Skip to content

Commit

Permalink
Added some more documentation. Also added a __init__.py in the git re…
Browse files Browse the repository at this point in the history
…po so that cloning enables importing as well. This should enable both git clone to work as well as pypi.
  • Loading branch information
Torxed committed Jul 21, 2020
1 parent e438e1b commit 06f8c46
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .archinstall import *
23 changes: 19 additions & 4 deletions archinstall/__main__.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -22,7 +33,11 @@ def find_examples():
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()
23 changes: 23 additions & 0 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@
from .profiles import Profile

class Installer():
"""
`Installer()` is the wrapper for most basic installation steps.
It also wraps :py:func:`~archinstall.Installer.pacstrap` among other things.
:param partition: Requires a partition as the first argument, this is
so that the installer can mount to `mountpoint` and strap packages there.
:type partition: class:`archinstall.Partition`
:param boot_partition: There's two reasons for needing a boot partition argument,
The first being so that `mkinitcpio` can place the `vmlinuz` kernel at the right place
during the `pacstrap` or `linux` and the base packages for a minimal installation.
The second being when :py:func:`~archinstall.Installer.add_bootloader` is called,
A `boot_partition` must be known to the installer before this is called.
:type boot_partition: class:`archinstall.Partition`
:param profile: A profile to install, this is optional and can be called later manually.
This just simplifies the process by not having to call :py:func:`~archinstall.Installer.install_profile` later on.
:type profile: str, optional
:param hostname: The given /etc/hostname for the machine.
:type hostname: str, optional
"""
def __init__(self, partition, boot_partition, *, profile=None, mountpoint='/mnt', hostname='ArchInstalled'):
self.profile = profile
self.hostname = hostname
Expand Down

0 comments on commit 06f8c46

Please sign in to comment.