New feature: Profile() now supports .packages which returns any defined packages for that specific profile, as well as archinstall.__packages__ contain any packages that Installer() is responsible for. This can be used to quickly gather any required packages and dependencies by archinstall. Not all profiles have it yet, so .packages might return None.

This commit is contained in:
Anton Hvornum 2021-03-25 15:07:49 +01:00
parent b521f8028c
commit 99dd9b1fb7
5 changed files with 33 additions and 13 deletions

View File

@ -2,7 +2,7 @@ from .lib.general import *
from .lib.disk import *
from .lib.user_interaction import *
from .lib.exceptions import *
from .lib.installer import *
from .lib.installer import __packages__, __base_packages__, Installer
from .lib.profiles import *
from .lib.luks import *
from .lib.mirrors import *

View File

@ -10,6 +10,10 @@ from .systemd import Networkd
from .output import log, LOG_LEVELS
from .storage import storage
# Any package that the Installer() is responsible for (optional and the default ones)
__packages__ = ["base", "base-devel", "linux", "linux-firmware", "efibootmgr", "nano", "ntp", "iwd"]
__base_packages__ = __packages__[:6]
class Installer():
"""
`Installer()` is the wrapper for most basic installation steps.
@ -34,7 +38,7 @@ class Installer():
:type hostname: str, optional
"""
def __init__(self, partition, boot_partition, *, base_packages='base base-devel linux linux-firmware efibootmgr nano', profile=None, mountpoint='/mnt', hostname='ArchInstalled', logdir=None, logfile=None):
def __init__(self, partition, boot_partition, *, base_packages=__base_packages__, profile=None, mountpoint='/mnt', hostname='ArchInstalled', logdir=None, logfile=None):
self.profile = profile
self.hostname = hostname
self.mountpoint = mountpoint

View File

@ -178,6 +178,28 @@ class Profile(Script):
return True
return False
@property
def packages(self) -> list:
"""
Returns a list of packages baked into the profile definition.
If no package definition has been done, .packages() will return None.
"""
with open(self.path, 'r') as source:
source_data = source.read()
# Some crude safety checks, make sure the imported profile has
# a __name__ check before importing.
#
# If the requirements are met, import with .py in the namespace to not
# trigger a traditional:
# if __name__ == 'moduleName'
if '__name__' in source_data and '__packages__' in source_data:
with self.load_instructions(namespace=f"{self.namespace}.py") as imported:
if hasattr(imported, '__packages__'):
return imported.__packages__
return None
class Application(Profile):
def __repr__(self, *args, **kwargs):
return f'Application({os.path.basename(self.profile)})'

View File

@ -1,10 +1,10 @@
import archinstall
__packages__ = ["awesome", "xorg-xrandr", "xterm", "feh", "slock", "terminus-font", "gnu-free-fonts", "ttf-liberation", "xsel"]
installation.install_profile('xorg')
installation.add_additional_packages(
"awesome xorg-xrandr xterm feh slock terminus-font gnu-free-fonts ttf-liberation xsel"
)
installation.add_additional_packages(__packages__)
with open(f'{installation.mountpoint}/etc/X11/xinit/xinitrc', 'r') as xinitrc:
xinitrc_data = xinitrc.read()

View File

@ -2,6 +2,7 @@
import archinstall
__packages__ = ['nano', 'nemo', 'gpicview-gtk3', 'chromium', 'openssh', 'sshfs', 'htop', 'scrot', 'wget']
def _prep_function(*args, **kwargs):
"""
@ -28,14 +29,7 @@ if __name__ == 'awesome':
awesome = archinstall.Application(installation, 'awesome')
awesome.install()
# Then setup and configure the desktop environment: awesome
editor = "nano"
filebrowser = "nemo gpicview-gtk3"
webbrowser = "chromium" # TODO: Ask the user to select one instead
utils = "openssh sshfs htop scrot wget"
installation.add_additional_packages(f"{webbrowser} {utils} {filebrowser} {editor}")
installation.add_additional_packages(__packages__)
alacritty = archinstall.Application(installation, 'alacritty')
alacritty.install()