Simplified profile prep-execution slightly in guided.py. The code can be improved further but it's now more easily read what's going on.
This commit is contained in:
parent
758b12e674
commit
ad4733bbd0
|
|
@ -157,6 +157,23 @@ class Profile(Script):
|
||||||
def install(self):
|
def install(self):
|
||||||
return self.execute()
|
return self.execute()
|
||||||
|
|
||||||
|
def has_prep_function(self):
|
||||||
|
with open(self.path, 'r') as source:
|
||||||
|
source_data = source.read()
|
||||||
|
|
||||||
|
# Some crude safety checks, make sure the imported profile has
|
||||||
|
# a __name__ check and if so, check if it's got a _prep_function()
|
||||||
|
# we can call to ask for more user input.
|
||||||
|
#
|
||||||
|
# If the requirements are met, import with .py in the namespace to not
|
||||||
|
# trigger a traditional:
|
||||||
|
# if __name__ == 'moduleName'
|
||||||
|
if '__name__' in source_data and '_prep_function' in source_data:
|
||||||
|
with profile.load_instructions(namespace=f"{selected_profile}.py") as imported:
|
||||||
|
if hasattr(imported, '_prep_function'):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class Application(Profile):
|
class Application(Profile):
|
||||||
def __repr__(self, *args, **kwargs):
|
def __repr__(self, *args, **kwargs):
|
||||||
return f'Application({os.path.basename(self.profile)})'
|
return f'Application({os.path.basename(self.profile)})'
|
||||||
|
|
|
||||||
|
|
@ -174,23 +174,7 @@ def select_profile(options):
|
||||||
else:
|
else:
|
||||||
RequirementError("Selected profile does not exist.")
|
RequirementError("Selected profile does not exist.")
|
||||||
|
|
||||||
profile = Profile(None, selected_profile)
|
return Profile(None, selected_profile)
|
||||||
with open(profile.path, 'r') as source:
|
|
||||||
source_data = source.read()
|
|
||||||
|
|
||||||
# Some crude safety checks, make sure the imported profile has
|
|
||||||
# a __name__ check and if so, check if it's got a _prep_function()
|
|
||||||
# we can call to ask for more user input.
|
|
||||||
#
|
|
||||||
# If the requirements are met, import with .py in the namespace to not
|
|
||||||
# trigger a traditional:
|
|
||||||
# if __name__ == 'moduleName'
|
|
||||||
if '__name__' in source_data and '_prep_function' in source_data:
|
|
||||||
with profile.load_instructions(namespace=f"{selected_profile}.py") as imported:
|
|
||||||
if hasattr(imported, '_prep_function'):
|
|
||||||
return imported
|
|
||||||
|
|
||||||
return profile
|
|
||||||
|
|
||||||
raise RequirementError("Selecting profiles require a least one profile to be given as an option.")
|
raise RequirementError("Selecting profiles require a least one profile to be given as an option.")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,9 +185,9 @@ else:
|
||||||
archinstall.arguments['profile'] = archinstall.list_profiles()[archinstall.arguments['profile']]
|
archinstall.arguments['profile'] = archinstall.list_profiles()[archinstall.arguments['profile']]
|
||||||
|
|
||||||
# Check the potentially selected profiles preperations to get early checks if some additional questions are needed.
|
# Check the potentially selected profiles preperations to get early checks if some additional questions are needed.
|
||||||
print(archinstall.arguments['profile'])
|
if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function():
|
||||||
if archinstall.arguments['profile']:
|
with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported:
|
||||||
if not archinstall.arguments['profile']._prep_function():
|
if not imported._prep_function():
|
||||||
archinstall.log(
|
archinstall.log(
|
||||||
' * Profile\'s preparation requirements was not fulfilled.',
|
' * Profile\'s preparation requirements was not fulfilled.',
|
||||||
bg='black',
|
bg='black',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue