Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/guided.py53
-rw-r--r--examples/minimal.py24
-rw-r--r--examples/unattended.py7
3 files changed, 44 insertions, 40 deletions
diff --git a/examples/guided.py b/examples/guided.py
index 0ae253a0..ae5c5f54 100644
--- a/examples/guided.py
+++ b/examples/guided.py
@@ -1,20 +1,23 @@
-import getpass, time, json, os, logging
+import json
+import logging
+import time
+
import archinstall
from archinstall.lib.hardware import hasUEFI
-from archinstall.lib.profiles import Profile
if archinstall.arguments.get('help'):
print("See `man archinstall` for help.")
exit(0)
# For support reasons, we'll log the disk layout pre installation to match against post-installation layout
-archinstall.log(f"Disk states before installing: {archinstall.disk_layouts()}", level=archinstall.LOG_LEVELS.Debug)
+archinstall.log(f"Disk states before installing: {archinstall.disk_layouts()}", level=logging.DEBUG)
+
def ask_user_questions():
"""
- First, we'll ask the user for a bunch of user input.
- Not until we're satisfied with what we want to install
- will we continue with the actual installation steps.
+ First, we'll ask the user for a bunch of user input.
+ Not until we're satisfied with what we want to install
+ will we continue with the actual installation steps.
"""
if not archinstall.arguments.get('keyboard-language', None):
while True:
@@ -36,11 +39,10 @@ def ask_user_questions():
archinstall.arguments['mirror-region'] = archinstall.select_mirror_regions(archinstall.list_mirrors())
break
except archinstall.RequirementError as e:
- archinstall.log(e, fg="red")
+ archinstall.log(e, fg="red")
else:
selected_region = archinstall.arguments['mirror-region']
- archinstall.arguments['mirror-region'] = {selected_region : archinstall.list_mirrors()[selected_region]}
-
+ archinstall.arguments['mirror-region'] = {selected_region: archinstall.list_mirrors()[selected_region]}
# Ask which harddrive/block-device we will install to
if archinstall.arguments.get('harddrive', None):
@@ -67,7 +69,6 @@ def ask_user_questions():
partition_mountpoints[partition] = None
except archinstall.UnknownFilesystemFormat as err:
archinstall.log(f" {partition} (Filesystem not supported)", fg='red')
-
# We then ask what to do with the partitions.
if (option := archinstall.ask_for_disk_layout()) == 'abort':
@@ -122,8 +123,7 @@ def ask_user_questions():
archinstall.log(f"Until then, please enter another supported filesystem.")
continue
except archinstall.SysCallError:
- pass # Expected exception since mkfs.<format> can not format /dev/null.
- # But that means our .format() function supported it.
+ pass # Expected exception since mkfs.<format> can not format /dev/null. But that means our .format() function supported it.
break
# When we've selected all three criteria,
@@ -151,7 +151,7 @@ def ask_user_questions():
# Get disk encryption password (or skip if blank)
if archinstall.arguments['harddrive'] and archinstall.arguments.get('!encryption-password', None) is None:
- if (passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): ')):
+ if passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): '):
archinstall.arguments['!encryption-password'] = passwd
archinstall.arguments['harddrive'].encryption_password = archinstall.arguments['!encryption-password']
archinstall.arguments["bootloader"] = archinstall.ask_for_bootloader()
@@ -191,7 +191,7 @@ def ask_user_questions():
# Ask about audio server selection if one is not already set
if not archinstall.arguments.get('audio', None):
- # only ask for audio server selection on a desktop profile
+ # only ask for audio server selection on a desktop profile
if str(archinstall.arguments['profile']) == 'Profile(desktop)':
archinstall.arguments['audio'] = archinstall.ask_for_audio_selection()
else:
@@ -219,7 +219,7 @@ def ask_user_questions():
break
except archinstall.RequirementError as e:
archinstall.log(e, fg='red')
- archinstall.arguments['packages'] = None # Clear the packages to trigger a new input question
+ archinstall.arguments['packages'] = None # Clear the packages to trigger a new input question
else:
# no additional packages were selected, which we'll allow
break
@@ -264,12 +264,12 @@ def perform_installation_steps():
# Wipe the entire drive if the disk flag `keep_partitions`is False.
if archinstall.arguments['harddrive'].keep_partitions is False:
fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs'))
-
+
# Check if encryption is desired and mark the root partition as encrypted.
if archinstall.arguments.get('!encryption-password', None):
root_partition = fs.find_partition('/')
root_partition.encrypted = True
-
+
# After the disk is ready, iterate the partitions and check
# which ones are safe to format, and format those.
for partition in archinstall.arguments['harddrive']:
@@ -293,10 +293,10 @@ def perform_installation_steps():
unlocked_device.mount('/mnt')
else:
fs.find_partition('/').mount('/mnt')
-
+
if hasUEFI():
fs.find_partition('/boot').mount('/mnt/boot')
-
+
perform_installation('/mnt')
@@ -307,7 +307,7 @@ def perform_installation(mountpoint):
formatted and setup prior to entering this function.
"""
with archinstall.Installer(mountpoint, kernels=archinstall.arguments.get('kernels', 'linux')) as installation:
- ## if len(mirrors):
+ # if len(mirrors):
# Certain services might be running that affects the system during installation.
# Currently, only one such service is "reflector.service" which updates /etc/pacman.d/mirrorlist
# We need to wait for it before we continue since we opted in to use a custom mirror/region.
@@ -319,7 +319,7 @@ def perform_installation(mountpoint):
archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium
if installation.minimal_installation():
installation.set_hostname(archinstall.arguments['hostname'])
- if archinstall.arguments['mirror-region'].get("mirrors",{})!= None:
+ if archinstall.arguments['mirror-region'].get("mirrors", None) is not None:
installation.set_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors in the installation medium
if archinstall.arguments["bootloader"]=="grub-install" and hasUEFI()==True:
installation.add_additional_packages("grub")
@@ -339,7 +339,7 @@ def perform_installation(mountpoint):
installation.enable_service('systemd-networkd')
installation.enable_service('systemd-resolved')
- if archinstall.arguments.get('audio', None) != None:
+ if archinstall.arguments.get('audio', None) is not None:
installation.log(f"This audio server will be used: {archinstall.arguments.get('audio', None)}", level=logging.INFO)
if archinstall.arguments.get('audio', None) == 'pipewire':
print('Installing pipewire ...')
@@ -350,7 +350,7 @@ def perform_installation(mountpoint):
installation.add_additional_packages("pulseaudio")
else:
installation.log("No audio server will be installed.", level=logging.INFO)
-
+
if archinstall.arguments.get('packages', None) and archinstall.arguments.get('packages', None)[0] != '':
installation.add_additional_packages(archinstall.arguments.get('packages', None))
@@ -363,7 +363,7 @@ def perform_installation(mountpoint):
for superuser, user_info in archinstall.arguments.get('superusers', {}).items():
installation.user_create(superuser, user_info["!password"], sudo=True)
- if (timezone := archinstall.arguments.get('timezone', None)):
+ if timezone := archinstall.arguments.get('timezone', None):
installation.set_timezone(timezone)
if (root_pw := archinstall.arguments.get('!root-password', None)) and len(root_pw):
@@ -387,7 +387,8 @@ def perform_installation(mountpoint):
pass
# For support reasons, we'll log the disk layout post installation (crash or no crash)
- archinstall.log(f"Disk states after installing: {archinstall.disk_layouts()}", level=archinstall.LOG_LEVELS.Debug)
+ archinstall.log(f"Disk states after installing: {archinstall.disk_layouts()}", level=logging.DEBUG)
+
ask_user_questions()
-perform_installation_steps() \ No newline at end of file
+perform_installation_steps()
diff --git a/examples/minimal.py b/examples/minimal.py
index 98d9a6f0..308a5e30 100644
--- a/examples/minimal.py
+++ b/examples/minimal.py
@@ -1,18 +1,19 @@
import archinstall
# Select a harddrive and a disk password
-archinstall.log(f"Minimal only supports:")
-archinstall.log(f" * Being installed to a single disk")
+archinstall.log("Minimal only supports:")
+archinstall.log(" * Being installed to a single disk")
if archinstall.arguments.get('help', None):
- archinstall.log(f" - Optional disk encryption via --!encryption-password=<password>")
- archinstall.log(f" - Optional filesystem type via --filesystem=<fs type>")
- archinstall.log(f" - Optional systemd network via --network")
+ archinstall.log(" - Optional disk encryption via --!encryption-password=<password>")
+ archinstall.log(" - Optional filesystem type via --filesystem=<fs type>")
+ archinstall.log(" - Optional systemd network via --network")
archinstall.arguments['harddrive'] = archinstall.select_disk(archinstall.all_disks())
+
def install_on(mountpoint):
- # We kick off the installer by telling it where the
+ # We kick off the installer by telling it where the
with archinstall.Installer(mountpoint) as installation:
# Strap in the base system, add a boot loader and configure
# some other minor details as specified by this profile and user.
@@ -32,13 +33,14 @@ def install_on(mountpoint):
# Once this is done, we output some useful information to the user
# And the installation is complete.
- archinstall.log(f"There are two new accounts in your installation after reboot:")
- archinstall.log(f" * root (password: airoot)")
- archinstall.log(f" * devel (password: devel)")
+ archinstall.log("There are two new accounts in your installation after reboot:")
+ archinstall.log(" * root (password: airoot)")
+ archinstall.log(" * devel (password: devel)")
+
if archinstall.arguments['harddrive']:
archinstall.arguments['harddrive'].keep_partitions = False
-
+
print(f" ! Formatting {archinstall.arguments['harddrive']} in ", end='')
archinstall.do_countdown()
@@ -68,4 +70,4 @@ if archinstall.arguments['harddrive']:
boot.mount('/mnt/boot')
-install_on('/mnt') \ No newline at end of file
+install_on('/mnt')
diff --git a/examples/unattended.py b/examples/unattended.py
index 679fbdf6..f1ed4c94 100644
--- a/examples/unattended.py
+++ b/examples/unattended.py
@@ -1,6 +1,7 @@
-import archinstall
import time
+import archinstall
+
archinstall.storage['UPSTREAM_URL'] = 'https://archlinux.life/profiles'
archinstall.storage['PROFILE_DB'] = 'index.json'
@@ -10,11 +11,11 @@ for name, info in archinstall.list_profiles().items():
# that fits the requirements for this machine specifically).
if info['tailored']:
print(f'Found a tailored profile for this machine called: "{name}".')
- print(f'Starting install in:')
+ print('Starting install in:')
for i in range(10, 0, -1):
print(f'{i}...')
time.sleep(1)
profile = archinstall.Profile(None, info['path'])
profile.install()
- break \ No newline at end of file
+ break