Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds@gmail.com>2021-02-17 14:21:46 +0100
committerAnton Hvornum <anton.feeds@gmail.com>2021-02-17 14:21:46 +0100
commitad4733bbd0b0e889ad902a7d954ec985fc7a24fe (patch)
treea0f4feaa14fd9fc87d4b3572f9efbd796291ba37
parent758b12e6746ac76c57e7725d4e35abbb4805ad23 (diff)
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.
-rw-r--r--archinstall/lib/profiles.py17
-rw-r--r--archinstall/lib/user_interaction.py18
-rw-r--r--examples/guided.py18
3 files changed, 27 insertions, 26 deletions
diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py
index f9aa206c..7b0e78e4 100644
--- a/archinstall/lib/profiles.py
+++ b/archinstall/lib/profiles.py
@@ -157,6 +157,23 @@ class Profile(Script):
def install(self):
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):
def __repr__(self, *args, **kwargs):
return f'Application({os.path.basename(self.profile)})'
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py
index bdf8acaf..5941903d 100644
--- a/archinstall/lib/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -174,23 +174,7 @@ def select_profile(options):
else:
RequirementError("Selected profile does not exist.")
- profile = 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
+ return Profile(None, selected_profile)
raise RequirementError("Selecting profiles require a least one profile to be given as an option.")
diff --git a/examples/guided.py b/examples/guided.py
index 1758a397..4cd37972 100644
--- a/examples/guided.py
+++ b/examples/guided.py
@@ -185,15 +185,15 @@ else:
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.
-print(archinstall.arguments['profile'])
-if archinstall.arguments['profile']:
- if not archinstall.arguments['profile']._prep_function():
- archinstall.log(
- ' * Profile\'s preparation requirements was not fulfilled.',
- bg='black',
- fg='red'
- )
- exit(1)
+if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function():
+ with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported:
+ if not imported._prep_function():
+ archinstall.log(
+ ' * Profile\'s preparation requirements was not fulfilled.',
+ bg='black',
+ fg='red'
+ )
+ exit(1)
# Additional packages (with some light weight error handling for invalid package names)
if not archinstall.arguments.get('packages', None):