osdict: Add get_install_script()

get_install_script() method returns an installer script of a specific
profile type for a specific OS.

In case no OS is defined, None is returned.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
Fabiano Fidêncio 2019-02-22 09:40:09 +01:00 committed by Cole Robinson
parent e8893f2178
commit 8f991e3ea2

View File

@ -510,4 +510,31 @@ class _OsVariant(object):
# the right one. # the right one.
return filtered_treelist.get_nth(0).get_url() return filtered_treelist.get_nth(0).get_url()
def get_install_script(self, profile):
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)
OSDB = _OSDB() OSDB = _OSDB()