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-21 11:01:48 +0000
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-07-21 11:01:48 +0000
commit06f8c46b3daaf0730a094c4cca26bd1fab6822af (patch)
treeeac7a2d721055a0204bafb68a9a3a2a723dbb0ca /archinstall/__main__.py
parente438e1bbde75bccb8cf8390ca1ca1e99f36d2806 (diff)
Added some more documentation. Also added a __init__.py in the git repo so that cloning enables importing as well. This should enable both git clone to work as well as pypi.
Diffstat (limited to 'archinstall/__main__.py')
-rw-r--r--archinstall/__main__.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/archinstall/__main__.py b/archinstall/__main__.py
index d5869020..fd536258 100644
--- a/archinstall/__main__.py
+++ b/archinstall/__main__.py
@@ -1,19 +1,30 @@
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)
+class ProfileNotFound(BaseException):
+ pass
+
def find_examples():
+ """
+ Used to locate the examples, bundled with the module or executable.
+
+ :return: {'guided.py' : './examples/guided.py', '<profile #2>' : '<path #2>'}
+ :rtype: dict
+ """
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__':
+def run_as_a_module():
+ """
+ Ssince we're running this as a 'python -m archinstall' module OR
+ a nuitka3 compiled version of the project.
+ This function and the file __main__ acts as a entry point.
+ """
if len(sys.argv) == 1: sys.argv.append('guided')
profile = sys.argv[1]
@@ -22,7 +33,11 @@ if __name__ == '__main__':
if not f'{profile}.py' in library:
raise ProfileNotFound(f'Could not locate {profile}.py among the example files.')
+ # Import and execute the chosen `<profile>.py`:
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
+
+if __name__ == '__main__':
+ run_as_a_module() \ No newline at end of file