Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-03-21 15:04:23 +0100
committerAnton Hvornum <anton@hvornum.se>2021-03-21 15:04:23 +0100
commit9ee64797011b541b38e68610a746eb6f303ab63d (patch)
tree3426971f2a94e9e497edbd03add882b61b52799c /archinstall/lib
parent27bde44b8de447e8612a83bc6964fc1b5237e07d (diff)
Enabling load_instructions() to set a temporary namespace, and then reverting it after the instructions are loaded. This is to temporarly override the namespace during import - enabling avoidance of triggering __name__ checks, and at the same time reverting back the namespace automatically to enable .execute() on the script (reusability of classes)
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/profiles.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py
index 5d425a22..ef7bba00 100644
--- a/archinstall/lib/profiles.py
+++ b/archinstall/lib/profiles.py
@@ -125,7 +125,9 @@ class Script():
else:
raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
- def load_instructions(self, namespace=None):
+ def load_instructions(self, namespace=None, reset_namespace=False):
+ original_namespace = self.namespace
+
if namespace:
self.namespace = namespace
@@ -135,6 +137,9 @@ class Script():
print(f"Imported {self} into sys.modules with namespace {self.namespace}.")
+ if reset_namespace:
+ self.namespace = original_namespace
+
return self
def execute(self):
@@ -173,7 +178,7 @@ class Profile(Script):
# if __name__ == 'moduleName'
if '__name__' in source_data and '_prep_function' in source_data:
print(f"Checking if {self} has _prep_function by importing with namespace {self.namespace}.py")
- with self.load_instructions(namespace=f"{self.namespace}.py") as imported:
+ with self.load_instructions(namespace=f"{self.namespace}.py", reset_namespace=True) as imported:
if hasattr(imported, '_prep_function'):
return True
return False