Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/__init__.py
diff options
context:
space:
mode:
authorDaniel Girtler <blackrabbit256@gmail.com>2023-05-12 02:30:09 +1000
committerGitHub <noreply@github.com>2023-05-11 18:30:09 +0200
commit89cefb9a1c7d4c4968e7d8645149078e601c9d1c (patch)
tree12c84bdcef1b0ef3f8a21977e25c7f0f89388138 /archinstall/__init__.py
parent6e6b850a8f687b193172aaa321d49bd2956c1d4f (diff)
Cleanup imports and unused code (#1801)
* Cleanup imports and unused code * Update build check * Keep deprecation exception * Simplify logging --------- Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
Diffstat (limited to 'archinstall/__init__.py')
-rw-r--r--archinstall/__init__.py85
1 files changed, 59 insertions, 26 deletions
diff --git a/archinstall/__init__.py b/archinstall/__init__.py
index 6f67d20f..992bd9fa 100644
--- a/archinstall/__init__.py
+++ b/archinstall/__init__.py
@@ -1,42 +1,75 @@
"""Arch Linux installer - guided, templates etc."""
import importlib
+import os
from argparse import ArgumentParser, Namespace
+from pathlib import Path
+from typing import TYPE_CHECKING, Any, Dict, Union
from .lib import disk
from .lib import menu
from .lib import models
from .lib import packages
-
-from .lib.exceptions import *
-from .lib.general import *
-from .lib.hardware import *
-from .lib.installer import __packages__, Installer, accessibility_tools_in_use
-from .lib.locale_helpers import *
-from .lib.luks import *
-from .lib.mirrors import *
-from .lib.networking import *
-from .lib.output import *
-from archinstall.lib.profile.profiles_handler import ProfileHandler, profile_handler
-from .lib.profile.profile_menu import ProfileConfiguration
-from .lib.services import *
-from .lib.storage import *
-from .lib.systemd import *
-from .lib.user_interaction import *
+from .lib import exceptions
+from .lib import luks
+from .lib import locale
+from .lib import mirrors
+from .lib import networking
+from .lib import profile
+from .lib import interactions
+from . import default_profiles
+
+from .lib.hardware import SysInfo, AVAILABLE_GFX_DRIVERS
+from .lib.installer import Installer, accessibility_tools_in_use
+from .lib.output import (
+ FormattedOutput, log, error,
+ check_log_permissions, debug, warn, info
+)
+from .lib.storage import storage
from .lib.global_menu import GlobalMenu
-from .lib.translationhandler import TranslationHandler, DeferredTranslation
-from .lib.plugins import plugins, load_plugin # This initiates the plugin loading ceremony
-from .lib.configuration import *
+from .lib.boot import Boot
+from .lib.translationhandler import TranslationHandler, Language, DeferredTranslation
+from .lib.plugins import plugins, load_plugin
+from .lib.configuration import ConfigurationOutput
+from .lib.general import (
+ generate_password, locate_binary, clear_vt100_escape_codes,
+ JsonEncoder, JSON, UNSAFE_JSON, SysCommandWorker, SysCommand,
+ run_custom_user_commands, json_stream_to_structure, secret
+)
+
+
+if TYPE_CHECKING:
+ _: Any
-parser = ArgumentParser()
__version__ = "2.5.6"
storage['__version__'] = __version__
+
# add the custome _ as a builtin, it can now be used anywhere in the
# project to mark strings as translatable with _('translate me')
DeferredTranslation.install()
+check_log_permissions()
+
+# Log various information about hardware before starting the installation. This might assist in troubleshooting
+debug(f"Hardware model detected: {SysInfo.sys_vendor()} {SysInfo.product_name()}; UEFI mode: {SysInfo.has_uefi()}")
+debug(f"Processor model detected: {SysInfo.cpu_model()}")
+debug(f"Memory statistics: {SysInfo.mem_available()} available out of {SysInfo.mem_total()} total installed")
+debug(f"Virtualization detected: {SysInfo.virtualization()}; is VM: {SysInfo.is_vm()}")
+debug(f"Graphics devices detected: {SysInfo._graphics_devices().keys()}")
+
+# For support reasons, we'll log the disk layout pre installation to match against post-installation layout
+debug(f"Disk states before installing: {disk.disk_layouts()}")
+
+
+if os.getuid() != 0:
+ print(_("Archinstall requires root privileges to run. See --help for more."))
+ exit(1)
+
+
+parser = ArgumentParser()
+
def define_arguments():
"""
@@ -61,7 +94,7 @@ def define_arguments():
parser.add_argument("--plugin", nargs="?", type=str)
-def parse_unspecified_argument_list(unknowns :list, multiple :bool = False, error :bool = False) -> dict:
+def parse_unspecified_argument_list(unknowns :list, multiple :bool = False, err :bool = False) -> dict:
"""We accept arguments not defined to the parser. (arguments "ad hoc").
Internally argparse return to us a list of words so we have to parse its contents, manually.
We accept following individual syntax for each argument
@@ -105,14 +138,14 @@ def parse_unspecified_argument_list(unknowns :list, multiple :bool = False, erro
config[last_key] = [config[last_key],element]
else:
config[last_key].append(element)
- elif error:
+ elif err:
raise ValueError(f"Entry {element} is not related to any argument")
else:
print(f" We ignore the entry {element} as it isn't related to any argument")
return config
-def cleanup_empty_args(args: Union[Namespace, dict]) -> dict:
+def cleanup_empty_args(args: Union[Namespace, Dict]) -> Dict:
"""
Takes arguments (dictionary or argparse Namespace) and removes any
None values. This ensures clean mergers during dict.update(args)
@@ -190,14 +223,14 @@ def load_config():
arguments['disk_config'] = disk.DiskLayoutConfiguration.parse_arg(disk_config)
if profile_config := arguments.get('profile_config', None):
- arguments['profile_config'] = ProfileConfiguration.parse_arg(profile_config)
+ arguments['profile_config'] = profile.ProfileConfiguration.parse_arg(profile_config)
if arguments.get('mirror-region', None) is not None:
if type(arguments.get('mirror-region', None)) is dict:
arguments['mirror-region'] = arguments.get('mirror-region', None)
else:
selected_region = arguments.get('mirror-region', None)
- arguments['mirror-region'] = {selected_region: list_mirrors()[selected_region]}
+ arguments['mirror-region'] = {selected_region: mirrors.list_mirrors()[selected_region]}
if arguments.get('servers', None) is not None:
storage['_selected_servers'] = arguments.get('servers', None)
@@ -230,7 +263,7 @@ def post_process_arguments(arguments):
storage['MOUNT_POINT'] = Path(mountpoint)
if arguments.get('debug', False):
- log(f"Warning: --debug mode will write certain credentials to {storage['LOG_PATH']}/{storage['LOG_FILE']}!", fg="red", level=logging.WARNING)
+ warn(f"Warning: --debug mode will write certain credentials to {storage['LOG_PATH']}/{storage['LOG_FILE']}!")
if arguments.get('plugin', None):
path = arguments['plugin']