Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/__main__.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds+github@gmail.com>2020-07-07 23:56:17 +0000
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-07-07 23:56:17 +0000
commit60f581319f99afbd678b4f5f56193d588228cbe2 (patch)
tree54bad414cc43893b4316f3c0d9af191ea7ecdea2 /archinstall/__main__.py
parente17fac498a778d5f6c83a40d2334a2af7a0e5397 (diff)
Added pythons -m module support. __main__.py is the main module entry path, and setup.py now includes the examples (which as been renamed for more convenient module importing) which - enables __main__.py to locate the examples and import them via importlib and execute them.
Diffstat (limited to 'archinstall/__main__.py')
-rw-r--r--archinstall/__main__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/archinstall/__main__.py b/archinstall/__main__.py
new file mode 100644
index 00000000..bd657291
--- /dev/null
+++ b/archinstall/__main__.py
@@ -0,0 +1,29 @@
+import archinstall, sys, os, glob
+import importlib.util
+
+class ProfileNotFound(BaseException):
+ pass
+
+# TODO: Learn the dark arts of argparse...
+# (I summon thee dark spawn of cPython)
+
+def find_examples():
+ cwd = os.path.abspath(f'{os.path.dirname(__file__)}/../')
+ examples = f"{cwd}/examples"
+
+ return {os.path.basename(path): path for path in glob.glob(f'{examples}/*.py')}
+
+
+if __name__ == '__main__':
+ if len(sys.argv) == 1: sys.arv.append('guided')
+
+ profile = sys.argv[1]
+ library = find_examples()
+
+ if not f'{profile}.py' in library:
+ raise ProfileNotFound(f'Could not locate {profile}.py among the example files.')
+
+ spec = importlib.util.spec_from_file_location(library[f'{profile}.py'], library[f'{profile}.py'])
+ imported_path = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(imported_path)
+ sys.modules[library[f'{profile}.py']] = imported_path \ No newline at end of file