[virt-tools-list] [virt-manager PATCH v2 15/25] osdict: refactor get_install_script()

Fabiano Fidêncio fidencio at redhat.com
Tue Feb 26 09:43:46 UTC 2019


Let's refactor get_install_script() a little bit in order to minimize
future changes coming in this code.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 virtinst/osdict.py | 47 ++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index eb64ba08..40386546 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -512,31 +512,34 @@ class _OsVariant(object):
         return filtered_treelist.get_nth(0).get_url()
 
     def get_install_script(self, profile):
+        def _get_install_script(script_list):
+            if script_list.get_length == 0:
+                raise RuntimeError(
+                    _("%s does not support unattended installation."),
+                    self.name)
+
+            profile_filter = libosinfo.Filter()
+            profile_filter.add_constraint(
+                libosinfo.INSTALL_SCRIPT_PROP_PROFILE, profile)
+
+            filtered_script_list = script_list.new_filtered(profile_filter)
+            if filtered_script_list.get_length() == 0:
+                raise RuntimeError(
+                    _("%s does not support unattended installation for the "
+                        "'%s' profile"), self.name, profile)
+
+            logging.debug("Install script found for profile '%s'", profile)
+
+            # Some OSes (as Windows) have more than one installer script,
+            # depending on the OS version and profile choosen, to be used to
+            # perform the unattended installation. Let's just deal with
+            # multiple installer scripts when its actually needed, though.
+            return filtered_script_list.get_nth(0)
+
         if not self._os:
             return None
 
-        script_list = self._os.get_install_script_list()
-        if script_list.get_length == 0:
-            raise RuntimeError(
-                _("%s does not support unattended installation."), self.name)
-
-        profile_filter = libosinfo.Filter()
-        profile_filter.add_constraint(
-            libosinfo.INSTALL_SCRIPT_PROP_PROFILE, profile)
-
-        filtered_script_list = script_list.new_filtered(profile_filter)
-        if filtered_script_list.get_length() == 0:
-            raise RuntimeError(
-                _("%s does not support unattended installation for the '%s' "
-                  "profile."), self.name, profile)
-
-        logging.debug("Install script found for profile '%s'", profile)
-
-        # Some OSes (as Windows) have more than one installer script, depending
-        # on the OS version and profile choosen, to be used to perform the
-        # unattended installation. Let's just deal with multiple installer
-        # scripts when its actually needed, though.
-        return filtered_script_list.get_nth(0)
+        return _get_install_script(self._os.get_install_script_list())
 
     def set_install_script_preferred_injection_method(self, script, method):
         def nick_to_value(method):
-- 
2.20.1




More information about the virt-tools-list mailing list