Refactor arch_config_handler to use DI (#4280)
This commit is contained in:
parent
64567a748a
commit
813b9b34b3
|
|
@ -549,6 +549,3 @@ class ArchConfigHandler:
|
|||
clean_args[key] = val
|
||||
|
||||
return clean_args
|
||||
|
||||
|
||||
arch_config_handler: ArchConfigHandler = ArchConfigHandler()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import time
|
|||
import traceback
|
||||
from pathlib import Path
|
||||
|
||||
from archinstall.lib.args import arch_config_handler
|
||||
from archinstall.lib.args import ArchConfigHandler
|
||||
from archinstall.lib.disk.utils import disk_layouts
|
||||
from archinstall.lib.hardware import SysInfo
|
||||
from archinstall.lib.network.wifi_handler import WifiHandler
|
||||
|
|
@ -78,6 +78,8 @@ def run() -> int:
|
|||
OR straight as a module: python -m archinstall
|
||||
In any case we will be attempting to load the provided script to be run from the scripts/ folder
|
||||
"""
|
||||
arch_config_handler = ArchConfigHandler()
|
||||
|
||||
if '--help' in sys.argv or '-h' in sys.argv:
|
||||
arch_config_handler.print_help()
|
||||
return 0
|
||||
|
|
@ -122,7 +124,7 @@ def run() -> int:
|
|||
mod_name = f'archinstall.scripts.{script}'
|
||||
# by loading the module we'll automatically run the script
|
||||
module = importlib.import_module(mod_name)
|
||||
module.main()
|
||||
module.main(arch_config_handler)
|
||||
|
||||
return 0
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from archinstall.lib.applications.application_handler import ApplicationHandler
|
||||
from archinstall.lib.args import arch_config_handler
|
||||
from archinstall.lib.args import ArchConfigHandler
|
||||
from archinstall.lib.authentication.authentication_handler import AuthenticationHandler
|
||||
from archinstall.lib.configuration import ConfigurationOutput
|
||||
from archinstall.lib.disk.filesystem import FilesystemHandler
|
||||
|
|
@ -22,7 +21,10 @@ from archinstall.lib.profile.profiles_handler import profile_handler
|
|||
from archinstall.lib.translationhandler import tr
|
||||
|
||||
|
||||
def show_menu(mirror_list_handler: MirrorListHandler) -> None:
|
||||
def show_menu(
|
||||
arch_config_handler: ArchConfigHandler,
|
||||
mirror_list_handler: MirrorListHandler,
|
||||
) -> None:
|
||||
upgrade = check_version_upgrade()
|
||||
title_text = 'Archlinux'
|
||||
|
||||
|
|
@ -44,7 +46,7 @@ def show_menu(mirror_list_handler: MirrorListHandler) -> None:
|
|||
|
||||
|
||||
def perform_installation(
|
||||
mountpoint: Path,
|
||||
arch_config_handler: ArchConfigHandler,
|
||||
mirror_list_handler: MirrorListHandler,
|
||||
auth_handler: AuthenticationHandler,
|
||||
application_handler: ApplicationHandler,
|
||||
|
|
@ -57,6 +59,7 @@ def perform_installation(
|
|||
start_time = time.monotonic()
|
||||
info('Starting installation...')
|
||||
|
||||
mountpoint = arch_config_handler.args.mountpoint
|
||||
config = arch_config_handler.config
|
||||
|
||||
if not config.disk_config:
|
||||
|
|
@ -188,14 +191,17 @@ def perform_installation(
|
|||
pass
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def main(arch_config_handler: ArchConfigHandler | None = None) -> None:
|
||||
if arch_config_handler is None:
|
||||
arch_config_handler = ArchConfigHandler()
|
||||
|
||||
mirror_list_handler = MirrorListHandler(
|
||||
offline=arch_config_handler.args.offline,
|
||||
verbose=arch_config_handler.args.verbose,
|
||||
)
|
||||
|
||||
if not arch_config_handler.args.silent:
|
||||
show_menu(mirror_list_handler)
|
||||
show_menu(arch_config_handler, mirror_list_handler)
|
||||
|
||||
config = ConfigurationOutput(arch_config_handler.config)
|
||||
config.write_debug()
|
||||
|
|
@ -211,14 +217,14 @@ def main() -> None:
|
|||
aborted = True
|
||||
|
||||
if aborted:
|
||||
return main()
|
||||
return main(arch_config_handler)
|
||||
|
||||
if arch_config_handler.config.disk_config:
|
||||
fs_handler = FilesystemHandler(arch_config_handler.config.disk_config)
|
||||
fs_handler.perform_filesystem_operations()
|
||||
|
||||
perform_installation(
|
||||
arch_config_handler.args.mountpoint,
|
||||
arch_config_handler,
|
||||
mirror_list_handler,
|
||||
AuthenticationHandler(),
|
||||
ApplicationHandler(),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
from pathlib import Path
|
||||
|
||||
from archinstall.default_profiles.minimal import MinimalProfile
|
||||
from archinstall.lib.args import arch_config_handler
|
||||
from archinstall.lib.args import ArchConfigHandler
|
||||
from archinstall.lib.configuration import ConfigurationOutput
|
||||
from archinstall.lib.disk.disk_menu import DiskLayoutConfigurationMenu
|
||||
from archinstall.lib.disk.filesystem import FilesystemHandler
|
||||
|
|
@ -14,7 +12,8 @@ from archinstall.lib.output import debug, error, info
|
|||
from archinstall.lib.profile.profiles_handler import profile_handler
|
||||
|
||||
|
||||
def perform_installation(mountpoint: Path) -> None:
|
||||
def perform_installation(arch_config_handler: ArchConfigHandler) -> None:
|
||||
mountpoint = arch_config_handler.args.mountpoint
|
||||
config = arch_config_handler.config
|
||||
|
||||
if not config.disk_config:
|
||||
|
|
@ -59,7 +58,10 @@ def perform_installation(mountpoint: Path) -> None:
|
|||
info(' * devel (password: devel)')
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def main(arch_config_handler: ArchConfigHandler | None = None) -> None:
|
||||
if arch_config_handler is None:
|
||||
arch_config_handler = ArchConfigHandler()
|
||||
|
||||
disk_config = DiskLayoutConfigurationMenu(disk_layout_config=None).run()
|
||||
arch_config_handler.config.disk_config = disk_config
|
||||
|
||||
|
|
@ -77,13 +79,13 @@ def main() -> None:
|
|||
aborted = True
|
||||
|
||||
if aborted:
|
||||
return main()
|
||||
return main(arch_config_handler)
|
||||
|
||||
if arch_config_handler.config.disk_config:
|
||||
fs_handler = FilesystemHandler(arch_config_handler.config.disk_config)
|
||||
fs_handler.perform_filesystem_operations()
|
||||
|
||||
perform_installation(arch_config_handler.args.mountpoint)
|
||||
perform_installation(arch_config_handler)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from pathlib import Path
|
||||
|
||||
from archinstall.lib.args import arch_config_handler
|
||||
from archinstall.lib.args import ArchConfigHandler
|
||||
from archinstall.lib.configuration import ConfigurationOutput
|
||||
from archinstall.lib.disk.filesystem import FilesystemHandler
|
||||
from archinstall.lib.disk.utils import disk_layouts
|
||||
|
|
@ -9,7 +9,7 @@ from archinstall.lib.installer import Installer
|
|||
from archinstall.lib.output import debug, error
|
||||
|
||||
|
||||
def show_menu() -> None:
|
||||
def show_menu(arch_config_handler: ArchConfigHandler) -> None:
|
||||
global_menu = GlobalMenu(arch_config_handler.config)
|
||||
global_menu.disable_all()
|
||||
|
||||
|
|
@ -21,12 +21,13 @@ def show_menu() -> None:
|
|||
global_menu.run()
|
||||
|
||||
|
||||
def perform_installation(mountpoint: Path) -> None:
|
||||
def perform_installation(arch_config_handler: ArchConfigHandler) -> None:
|
||||
"""
|
||||
Performs the installation steps on a block device.
|
||||
Only requirement is that the block devices are
|
||||
formatted and setup prior to entering this function.
|
||||
"""
|
||||
mountpoint = arch_config_handler.args.mountpoint
|
||||
config = arch_config_handler.config
|
||||
|
||||
if not config.disk_config:
|
||||
|
|
@ -55,9 +56,12 @@ def perform_installation(mountpoint: Path) -> None:
|
|||
debug(f'Disk states after installing:\n{disk_layouts()}')
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def main(arch_config_handler: ArchConfigHandler | None = None) -> None:
|
||||
if arch_config_handler is None:
|
||||
arch_config_handler = ArchConfigHandler()
|
||||
|
||||
if not arch_config_handler.args.silent:
|
||||
show_menu()
|
||||
show_menu(arch_config_handler)
|
||||
|
||||
config = ConfigurationOutput(arch_config_handler.config)
|
||||
config.write_debug()
|
||||
|
|
@ -73,13 +77,13 @@ def main() -> None:
|
|||
aborted = True
|
||||
|
||||
if aborted:
|
||||
return main()
|
||||
return main(arch_config_handler)
|
||||
|
||||
if arch_config_handler.config.disk_config:
|
||||
fs_handler = FilesystemHandler(arch_config_handler.config.disk_config)
|
||||
fs_handler.perform_filesystem_operations()
|
||||
|
||||
perform_installation(arch_config_handler.args.mountpoint)
|
||||
perform_installation(arch_config_handler)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Reference in New Issue