Add console_scripts archinstall entry point
archinstall should be callable from the command-line. Previously this was achieved with a shell script, however Python packages contain a built in way to to this via the entry points mechanism.
This commit is contained in:
parent
7f691ce1c9
commit
ecf7a2a237
|
|
@ -30,3 +30,32 @@ for arg in sys.argv[1:]:
|
||||||
arguments[key] = val
|
arguments[key] = val
|
||||||
else:
|
else:
|
||||||
positionals.append(arg)
|
positionals.append(arg)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Learn the dark arts of argparse...
|
||||||
|
# (I summon thee dark spawn of cPython)
|
||||||
|
|
||||||
|
def run_as_a_module():
|
||||||
|
"""
|
||||||
|
Since 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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Add another path for finding profiles, so that list_profiles() in Script() can find guided.py, unattended.py etc.
|
||||||
|
storage['PROFILE_PATH'].append(os.path.abspath(f'{os.path.dirname(__file__)}/examples'))
|
||||||
|
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
sys.argv.append('guided')
|
||||||
|
|
||||||
|
try:
|
||||||
|
script = Script(sys.argv[1])
|
||||||
|
except ProfileNotFound as err:
|
||||||
|
print(f"Couldn't find file: {err}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
||||||
|
|
||||||
|
# Remove the example directory from the PROFILE_PATH, to avoid guided.py etc shows up in user input questions.
|
||||||
|
storage['PROFILE_PATH'].pop()
|
||||||
|
script.execute()
|
||||||
|
|
|
||||||
|
|
@ -2,33 +2,5 @@ import archinstall
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# TODO: Learn the dark arts of argparse...
|
|
||||||
# (I summon thee dark spawn of cPython)
|
|
||||||
|
|
||||||
def run_as_a_module():
|
|
||||||
"""
|
|
||||||
Since 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.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Add another path for finding profiles, so that list_profiles() in Script() can find guided.py, unattended.py etc.
|
|
||||||
archinstall.storage['PROFILE_PATH'].append(os.path.abspath(f'{os.path.dirname(__file__)}/examples'))
|
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
sys.argv.append('guided')
|
|
||||||
|
|
||||||
try:
|
|
||||||
script = archinstall.Script(sys.argv[1])
|
|
||||||
except archinstall.ProfileNotFound as err:
|
|
||||||
print(f"Couldn't find file: {err}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
|
||||||
|
|
||||||
# Remove the example directory from the PROFILE_PATH, to avoid guided.py etc shows up in user input questions.
|
|
||||||
archinstall.storage['PROFILE_PATH'].pop()
|
|
||||||
script.execute()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run_as_a_module()
|
archinstall.run_as_a_module()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue