diff --git a/archinstall/__init__.py b/archinstall/__init__.py index f3620648..07c834c1 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -150,7 +150,7 @@ def get_arguments() -> Dict[str, Any]: parsed_url = urllib.parse.urlparse(args.config) if not parsed_url.scheme: # The Profile was not a direct match on a remote URL, it must be a local file. - if not json_stream_to_structure('--config',args.config,config): + if not json_stream_to_structure('--config', args.config, config): exit(1) else: # Attempt to load the configuration from the URL. with urllib.request.urlopen(urllib.request.Request(args.config, headers={'User-Agent': 'ArchInstall'})) as response: diff --git a/archinstall/examples b/archinstall/examples deleted file mode 120000 index 785887f7..00000000 --- a/archinstall/examples +++ /dev/null @@ -1 +0,0 @@ -../examples/ \ No newline at end of file diff --git a/examples/__init__.py b/archinstall/examples/__init__.py similarity index 100% rename from examples/__init__.py rename to archinstall/examples/__init__.py diff --git a/examples/config-sample.json b/archinstall/examples/config-sample.json similarity index 100% rename from examples/config-sample.json rename to archinstall/examples/config-sample.json diff --git a/examples/creds-sample.json b/archinstall/examples/creds-sample.json similarity index 100% rename from examples/creds-sample.json rename to archinstall/examples/creds-sample.json diff --git a/examples/custom-command-sample.json b/archinstall/examples/custom-command-sample.json similarity index 100% rename from examples/custom-command-sample.json rename to archinstall/examples/custom-command-sample.json diff --git a/examples/disk_layouts-sample.json b/archinstall/examples/disk_layouts-sample.json similarity index 100% rename from examples/disk_layouts-sample.json rename to archinstall/examples/disk_layouts-sample.json diff --git a/examples/guided.py b/archinstall/examples/guided.py similarity index 99% rename from examples/guided.py rename to archinstall/examples/guided.py index 15226668..4be4d661 100644 --- a/examples/guided.py +++ b/archinstall/examples/guided.py @@ -178,8 +178,8 @@ def perform_installation(mountpoint): archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium # Retrieve list of additional repositories and set boolean values appropriately - enable_testing = 'testing' in archinstall.arguments.get('additional-repositories', None) - enable_multilib = 'multilib' in archinstall.arguments.get('additional-repositories', None) + enable_testing = 'testing' in archinstall.arguments.get('additional-repositories', []) + enable_multilib = 'multilib' in archinstall.arguments.get('additional-repositories', []) if installation.minimal_installation(testing=enable_testing, multilib=enable_multilib): installation.set_locale(archinstall.arguments['sys-language'], archinstall.arguments['sys-encoding'].upper()) diff --git a/examples/minimal.py b/archinstall/examples/minimal.py similarity index 100% rename from examples/minimal.py rename to archinstall/examples/minimal.py diff --git a/examples/only_hd.py b/archinstall/examples/only_hd.py similarity index 100% rename from examples/only_hd.py rename to archinstall/examples/only_hd.py diff --git a/examples/swiss.py b/archinstall/examples/swiss.py similarity index 100% rename from examples/swiss.py rename to archinstall/examples/swiss.py diff --git a/examples/unattended.py b/archinstall/examples/unattended.py similarity index 100% rename from examples/unattended.py rename to archinstall/examples/unattended.py diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index da41d16d..2aaf6528 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -126,6 +126,6 @@ def log(*args :str, **kwargs :Union[str, int, Dict[str, Union[str, int]]]) -> No # Finally, print the log unless we skipped it based on level. # We use sys.stdout.write()+flush() instead of print() to try and # fix issue #94 - if kwargs.get('level', logging.INFO) != logging.DEBUG or storage['arguments'].get('verbose', False): + if kwargs.get('level', logging.INFO) != logging.DEBUG or hasattr(storage.get('arguments'), 'verbose') and storage['arguments'].verbose: sys.stdout.write(f"{string}\n") sys.stdout.flush() diff --git a/archinstall/profiles b/archinstall/profiles deleted file mode 120000 index c2968eea..00000000 --- a/archinstall/profiles +++ /dev/null @@ -1 +0,0 @@ -../profiles/ \ No newline at end of file diff --git a/profiles/52-54-00-12-34-56.py b/archinstall/profiles/52-54-00-12-34-56.py similarity index 100% rename from profiles/52-54-00-12-34-56.py rename to archinstall/profiles/52-54-00-12-34-56.py diff --git a/profiles/__init__.py b/archinstall/profiles/__init__.py similarity index 100% rename from profiles/__init__.py rename to archinstall/profiles/__init__.py diff --git a/profiles/applications/__init__.py b/archinstall/profiles/applications/__init__.py similarity index 100% rename from profiles/applications/__init__.py rename to archinstall/profiles/applications/__init__.py diff --git a/profiles/applications/awesome.py b/archinstall/profiles/applications/awesome.py similarity index 100% rename from profiles/applications/awesome.py rename to archinstall/profiles/applications/awesome.py diff --git a/profiles/applications/cockpit.py b/archinstall/profiles/applications/cockpit.py similarity index 100% rename from profiles/applications/cockpit.py rename to archinstall/profiles/applications/cockpit.py diff --git a/profiles/applications/docker.py b/archinstall/profiles/applications/docker.py similarity index 100% rename from profiles/applications/docker.py rename to archinstall/profiles/applications/docker.py diff --git a/profiles/applications/httpd.py b/archinstall/profiles/applications/httpd.py similarity index 100% rename from profiles/applications/httpd.py rename to archinstall/profiles/applications/httpd.py diff --git a/profiles/applications/lighttpd.py b/archinstall/profiles/applications/lighttpd.py similarity index 100% rename from profiles/applications/lighttpd.py rename to archinstall/profiles/applications/lighttpd.py diff --git a/profiles/applications/mariadb.py b/archinstall/profiles/applications/mariadb.py similarity index 100% rename from profiles/applications/mariadb.py rename to archinstall/profiles/applications/mariadb.py diff --git a/profiles/applications/nginx.py b/archinstall/profiles/applications/nginx.py similarity index 100% rename from profiles/applications/nginx.py rename to archinstall/profiles/applications/nginx.py diff --git a/profiles/applications/pipewire.py b/archinstall/profiles/applications/pipewire.py similarity index 100% rename from profiles/applications/pipewire.py rename to archinstall/profiles/applications/pipewire.py diff --git a/profiles/applications/postgresql.py b/archinstall/profiles/applications/postgresql.py similarity index 100% rename from profiles/applications/postgresql.py rename to archinstall/profiles/applications/postgresql.py diff --git a/profiles/applications/sshd.py b/archinstall/profiles/applications/sshd.py similarity index 100% rename from profiles/applications/sshd.py rename to archinstall/profiles/applications/sshd.py diff --git a/profiles/applications/tomcat.py b/archinstall/profiles/applications/tomcat.py similarity index 100% rename from profiles/applications/tomcat.py rename to archinstall/profiles/applications/tomcat.py diff --git a/profiles/awesome.py b/archinstall/profiles/awesome.py similarity index 100% rename from profiles/awesome.py rename to archinstall/profiles/awesome.py diff --git a/profiles/bspwm.py b/archinstall/profiles/bspwm.py similarity index 100% rename from profiles/bspwm.py rename to archinstall/profiles/bspwm.py diff --git a/profiles/budgie.py b/archinstall/profiles/budgie.py similarity index 100% rename from profiles/budgie.py rename to archinstall/profiles/budgie.py diff --git a/profiles/cinnamon.py b/archinstall/profiles/cinnamon.py similarity index 100% rename from profiles/cinnamon.py rename to archinstall/profiles/cinnamon.py diff --git a/profiles/cutefish.py b/archinstall/profiles/cutefish.py similarity index 100% rename from profiles/cutefish.py rename to archinstall/profiles/cutefish.py diff --git a/profiles/deepin.py b/archinstall/profiles/deepin.py similarity index 100% rename from profiles/deepin.py rename to archinstall/profiles/deepin.py diff --git a/profiles/desktop.py b/archinstall/profiles/desktop.py similarity index 100% rename from profiles/desktop.py rename to archinstall/profiles/desktop.py diff --git a/profiles/enlightenment.py b/archinstall/profiles/enlightenment.py similarity index 100% rename from profiles/enlightenment.py rename to archinstall/profiles/enlightenment.py diff --git a/profiles/gnome.py b/archinstall/profiles/gnome.py similarity index 100% rename from profiles/gnome.py rename to archinstall/profiles/gnome.py diff --git a/profiles/i3.py b/archinstall/profiles/i3.py similarity index 100% rename from profiles/i3.py rename to archinstall/profiles/i3.py diff --git a/profiles/kde.py b/archinstall/profiles/kde.py similarity index 100% rename from profiles/kde.py rename to archinstall/profiles/kde.py diff --git a/profiles/lxqt.py b/archinstall/profiles/lxqt.py similarity index 100% rename from profiles/lxqt.py rename to archinstall/profiles/lxqt.py diff --git a/profiles/mate.py b/archinstall/profiles/mate.py similarity index 100% rename from profiles/mate.py rename to archinstall/profiles/mate.py diff --git a/profiles/minimal.py b/archinstall/profiles/minimal.py similarity index 100% rename from profiles/minimal.py rename to archinstall/profiles/minimal.py diff --git a/profiles/qtile.py b/archinstall/profiles/qtile.py similarity index 100% rename from profiles/qtile.py rename to archinstall/profiles/qtile.py diff --git a/profiles/server.py b/archinstall/profiles/server.py similarity index 100% rename from profiles/server.py rename to archinstall/profiles/server.py diff --git a/profiles/sway.py b/archinstall/profiles/sway.py similarity index 100% rename from profiles/sway.py rename to archinstall/profiles/sway.py diff --git a/profiles/xfce4.py b/archinstall/profiles/xfce4.py similarity index 100% rename from profiles/xfce4.py rename to archinstall/profiles/xfce4.py diff --git a/profiles/xorg.py b/archinstall/profiles/xorg.py similarity index 100% rename from profiles/xorg.py rename to archinstall/profiles/xorg.py diff --git a/examples b/examples new file mode 120000 index 00000000..910e2384 --- /dev/null +++ b/examples @@ -0,0 +1 @@ +archinstall/examples/ \ No newline at end of file diff --git a/profiles b/profiles new file mode 120000 index 00000000..4cccef67 --- /dev/null +++ b/profiles @@ -0,0 +1 @@ +archinstall/profiles/ \ No newline at end of file diff --git a/tests/disk-related/test_stat_blockdev.py b/tests/disk-related/test_stat_blockdev.py index 0128d8ed..fb0a24b1 100644 --- a/tests/disk-related/test_stat_blockdev.py +++ b/tests/disk-related/test_stat_blockdev.py @@ -112,6 +112,4 @@ def test_stat_blockdev(): else: raise AssertionError(f"Could not retrieve a loopdev for testing on {filename}") - pathlib.Path(filename).resolve().unlink() - -test_stat_blockdev() \ No newline at end of file + pathlib.Path(filename).resolve().unlink() \ No newline at end of file diff --git a/tests/guided-related/test_minimal_install.py b/tests/guided-related/test_minimal_install.py new file mode 100644 index 00000000..ba67f0ea --- /dev/null +++ b/tests/guided-related/test_minimal_install.py @@ -0,0 +1,173 @@ +import pytest +import subprocess +import string +import random +import pathlib +import json +import time +import sys + +def simple_exec(cmd): + proc = subprocess.Popen( + cmd, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + + output = b'' + while proc.poll() is None: + line = proc.stdout.read(1024) + print(line.decode(), end='') + sys.stdout.flush() + output += line + time.sleep(0.01) + + output += proc.stdout.read() + proc.stdout.close() + + return {'exit_code' : proc.poll(), 'data' : output.decode().strip()} + +def random_filename(): + return ''.join([random.choice(string.ascii_letters) for x in range(20)]) + '.img' + +def truncate_file(filename): + result = simple_exec(f"truncate -s 20G {filename}") + + if not result['exit_code'] == 0: + raise AssertionError(f"Could not generate a testimage with truncate: {result['data']}") + + return filename + +def get_loopdev(filename): + result = simple_exec(f"""losetup -a | grep "{filename}" | awk -F ":" '{{print $1}}'""") + return result['data'] + +def detach_loopdev(path): + result = simple_exec(f"losetup -d {path}") + return result['exit_code'] == 0 + +def create_loopdev(path): + result = simple_exec(f"losetup -fP {path}") + return result['exit_code'] == 0 + +def test_stat_blockdev(): + import archinstall + + filename = pathlib.Path(random_filename()).resolve() + if loopdev := get_loopdev(filename): + if not detach_loopdev(loopdev): + raise AssertionError(f"Could not detach {loopdev} before performing test with {filename}.") + + truncate_file(filename) + if not create_loopdev(filename): + raise AssertionError(f"Could not create a loopdev for {filename}") + + if loopdev := get_loopdev(filename): + user_configuration = { + "audio": "pipewire", + "config_version": "2.4.2", + "debug": True, + "harddrives": [ + loopdev + ], + "mirror-region": { + "Sweden": { + "http://ftp.acc.umu.se/mirror/archlinux/$repo/os/$arch": True, + "http://ftp.lysator.liu.se/pub/archlinux/$repo/os/$arch": True, + "http://ftp.myrveln.se/pub/linux/archlinux/$repo/os/$arch": True, + "http://ftpmirror.infania.net/mirror/archlinux/$repo/os/$arch": True, + "https://ftp.acc.umu.se/mirror/archlinux/$repo/os/$arch": True, + "https://ftp.ludd.ltu.se/mirrors/archlinux/$repo/os/$arch": True, + "https://ftp.lysator.liu.se/pub/archlinux/$repo/os/$arch": True, + "https://ftp.myrveln.se/pub/linux/archlinux/$repo/os/$arch": True, + "https://mirror.osbeck.com/archlinux/$repo/os/$arch": True + } + }, + "mount_point": None, + "nic": { + "dhcp": True, + "dns": None, + "gateway": None, + "iface": None, + "ip": None, + "type": "iso" + }, + "packages": [ + "nano" + ], + "plugin": None, + "profile": { + "path": "/usr/lib/python3.10/site-packages/archinstall/profiles/minimal.py" + }, + "script": "guided", + "silent": True, + "timezone": "Europe/Stockholm", + "version": "2.4.2" + } + + user_credentials = { + "!encryption-password": "test", + "!superusers": { + "anton": { + "!password": "test" + } + }, + "!users": {} + } + + user_disk_layout = { + loopdev: { + "partitions": [ + { + "boot": True, + "encrypted": False, + "filesystem": { + "format": "fat32" + }, + "mountpoint": "/boot", + "size": "512MiB", + "start": "1MiB", + "type": "primary", + "wipe": True + }, + { + "btrfs": { + "subvolumes": { + "@": "/", + "@.snapshots": "/.snapshots", + "@home": "/home", + "@log": "/var/log", + "@pkg": "/var/cache/pacman/pkg" + } + }, + "encrypted": False, + "filesystem": { + "format": "btrfs", + "mount_options": [ + "compress=zstd" + ] + }, + "mountpoint": None, + "size": "100%", + "start": "513MiB", + "type": "primary", + "wipe": True + } + ], + "wipe": True + } + } + + result = archinstall.SysCommand(f'archinstall --silent --config \'{json.dumps(user_configuration)}\' --creds \'{json.dumps(user_credentials)}\' --disk-layout \'{json.dumps(user_disk_layout)}\'', peak_output=True) + #print(result) + + # Test ended, cleanup commences + if not detach_loopdev(loopdev): + raise AssertionError(f"Could not detach {loopdev} after performing tests on {filename}.") + else: + raise AssertionError(f"Could not retrieve a loopdev for testing on {filename}") + + pathlib.Path(filename).resolve().unlink() + +test_stat_blockdev() \ No newline at end of file