Merge pull request #448 from dylanmtaylor/whitespace

More minor whitespace changes
This commit is contained in:
Anton Hvornum 2021-05-15 18:15:13 +00:00 committed by GitHub
commit 85fa833a8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 29 deletions

View File

@ -152,8 +152,9 @@ class BlockDevice():
def flush_cache(self): def flush_cache(self):
self.part_cache = OrderedDict() self.part_cache = OrderedDict()
class Partition(): class Partition():
def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): def __init__(self, path: str, block_device: BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True):
if not part_id: if not part_id:
part_id = os.path.basename(path) part_id = os.path.basename(path)
@ -506,9 +507,9 @@ class Filesystem():
self.blockdevice.partition[0].allow_formatting = True self.blockdevice.partition[0].allow_formatting = True
self.blockdevice.partition[1].allow_formatting = True self.blockdevice.partition[1].allow_formatting = True
else: else:
#we don't need a seprate boot partition it would be a waste of space # we don't need a seprate boot partition it would be a waste of space
self.add_partition('primary', start='1MB', end='100%') self.add_partition('primary', start='1MB', end='100%')
self.blockdevice.partition[0].filesystem=root_filesystem_type self.blockdevice.partition[0].filesystem = root_filesystem_type
log(f"Set the root partition {self.blockdevice.partition[0]} to use filesystem {root_filesystem_type}.", level=logging.DEBUG) log(f"Set the root partition {self.blockdevice.partition[0]} to use filesystem {root_filesystem_type}.", level=logging.DEBUG)
self.blockdevice.partition[0].target_mountpoint = '/' self.blockdevice.partition[0].target_mountpoint = '/'
self.blockdevice.partition[0].allow_formatting = True self.blockdevice.partition[0].allow_formatting = True
@ -558,28 +559,31 @@ def device_state(name, *args, **kwargs):
return return
return True return True
# lsblk --json -l -n -o path # lsblk --json -l -n -o path
def all_disks(*args, **kwargs): def all_disks(*args, **kwargs):
kwargs.setdefault("partitions", False) kwargs.setdefault("partitions", False)
drives = OrderedDict() drives = OrderedDict()
#for drive in json.loads(sys_command(f'losetup --json', *args, **lkwargs, hide_from_log=True)).decode('UTF_8')['loopdevices']: # for drive in json.loads(sys_command(f'losetup --json', *args, **lkwargs, hide_from_log=True)).decode('UTF_8')['loopdevices']:
for drive in json.loads(b''.join(sys_command(f'lsblk --json -l -n -o path,size,type,mountpoint,label,pkname,model', *args, **kwargs, hide_from_log=True)).decode('UTF_8'))['blockdevices']: for drive in json.loads(b''.join(sys_command(f'lsblk --json -l -n -o path,size,type,mountpoint,label,pkname,model', *args, **kwargs, hide_from_log=True)).decode('UTF_8'))['blockdevices']:
if not kwargs['partitions'] and drive['type'] == 'part': continue if not kwargs['partitions'] and drive['type'] == 'part': continue
drives[drive['path']] = BlockDevice(drive['path'], drive) drives[drive['path']] = BlockDevice(drive['path'], drive)
return drives return drives
def convert_to_gigabytes(string): def convert_to_gigabytes(string):
unit = string.strip()[-1] unit = string.strip()[-1]
size = float(string.strip()[:-1]) size = float(string.strip()[:-1])
if unit == 'M': if unit == 'M':
size = size/1024 size = size / 1024
elif unit == 'T': elif unit == 'T':
size = size*1024 size = size * 1024
return size return size
def harddrive(size=None, model=None, fuzzy=False): def harddrive(size=None, model=None, fuzzy=False):
collection = all_disks() collection = all_disks()
for drive in collection: for drive in collection:

View File

@ -83,10 +83,12 @@ class JSON(json.JSONEncoder, json.JSONDecoder):
def encode(self, obj): def encode(self, obj):
return super(JSON, self).encode(self._encode(obj)) return super(JSON, self).encode(self._encode(obj))
class sys_command: class sys_command:
""" """
Stolen from archinstall_gui Stolen from archinstall_gui
""" """
def __init__(self, cmd, callback=None, start_callback=None, peak_output=False, environment_vars={}, *args, **kwargs): def __init__(self, cmd, callback=None, start_callback=None, peak_output=False, environment_vars={}, *args, **kwargs):
kwargs.setdefault("worker_id", gen_uid()) kwargs.setdefault("worker_id", gen_uid())
kwargs.setdefault("emulate", False) kwargs.setdefault("emulate", False)

View File

@ -108,7 +108,7 @@ def cpuVendor() -> Optional[str]:
def isVM() -> bool: def isVM() -> bool:
try: try:
subprocess.check_call(["systemd-detect-virt"]) # systemd-detect-virt issues a non-zero exit code if it is not on a virtual machine subprocess.check_call(["systemd-detect-virt"]) # systemd-detect-virt issues a non-zero exit code if it is not on a virtual machine
return True return True
except: except:
return False return False

View File

@ -153,7 +153,7 @@ class Installer():
return True return True
def set_hostname(self, hostname :str, *args, **kwargs): def set_hostname(self, hostname: str, *args, **kwargs):
with open(f'{self.target}/etc/hostname', 'w') as fh: with open(f'{self.target}/etc/hostname', 'w') as fh:
fh.write(hostname + '\n') fh.write(hostname + '\n')
@ -423,7 +423,6 @@ class Installer():
## blkid doesn't trigger on loopback devices really well, ## blkid doesn't trigger on loopback devices really well,
## so we'll use the old manual method until we get that sorted out. ## so we'll use the old manual method until we get that sorted out.
if (real_device := self.detect_encryption(root_partition)): if (real_device := self.detect_encryption(root_partition)):
# TODO: We need to detect if the encrypted device is a whole disk encryption, # TODO: We need to detect if the encrypted device is a whole disk encryption,
# or simply a partition encryption. Right now we assume it's a partition (and we always have) # or simply a partition encryption. Right now we assume it's a partition (and we always have)
@ -446,7 +445,7 @@ class Installer():
sys_command('/usr/bin/arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg') sys_command('/usr/bin/arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg')
return True return True
else: else:
root_device = subprocess.check_output(f'basename "$(readlink -f /sys/class/block/{root_partition.path.replace("/dev/","")}/..)"', shell=True).decode().strip() root_device = subprocess.check_output(f'basename "$(readlink -f /sys/class/block/{root_partition.path.replace("/dev/", "")}/..)"', shell=True).decode().strip()
if root_device == "block": if root_device == "block":
root_device = f"{root_partition.path}" root_device = f"{root_partition.path}"
o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.target} grub-install --target=i386-pc /dev/{root_device}')) o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.target} grub-install --target=i386-pc /dev/{root_device}'))

View File

@ -22,7 +22,7 @@ def filter_mirrors_by_region(regions, destination='/etc/pacman.d/mirrorlist', tm
return True return True
def add_custom_mirrors(mirrors:list, *args, **kwargs): def add_custom_mirrors(mirrors: list, *args, **kwargs):
""" """
This will append custom mirror definitions in pacman.conf This will append custom mirror definitions in pacman.conf

View File

@ -14,7 +14,7 @@ from .storage import storage
def grab_url_data(path): def grab_url_data(path):
safe_path = path[:path.find(':')+1]+''.join([item if item in ('/', '?', '=', '&') else urllib.parse.quote(item) for item in multisplit(path[path.find(':')+1:], ('/', '?', '=', '&'))]) safe_path = path[:path.find(':') + 1] + ''.join([item if item in ('/', '?', '=', '&') else urllib.parse.quote(item) for item in multisplit(path[path.find(':') + 1:], ('/', '?', '=', '&'))])
ssl_context = ssl.create_default_context() ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE ssl_context.verify_mode = ssl.CERT_NONE
@ -47,7 +47,7 @@ def list_profiles(filter_irrelevant_macs=True, subpath='', filter_top_level_prof
if len(first_line) and first_line[0] == '#': if len(first_line) and first_line[0] == '#':
description = first_line[1:].strip() description = first_line[1:].strip()
cache[file[:-3]] = {'path' : os.path.join(root, file), 'description' : description, 'tailored' : tailored} cache[file[:-3]] = {'path': os.path.join(root, file), 'description': description, 'tailored': tailored}
break break
# Grab profiles from upstream URL # Grab profiles from upstream URL
@ -70,7 +70,7 @@ def list_profiles(filter_irrelevant_macs=True, subpath='', filter_top_level_prof
continue continue
tailored = True tailored = True
cache[profile[:-3]] = {'path' : os.path.join(storage["UPSTREAM_URL"]+subpath, profile), 'description' : profile_list[profile], 'tailored' : tailored} cache[profile[:-3]] = {'path': os.path.join(storage["UPSTREAM_URL"] + subpath, profile), 'description': profile_list[profile], 'tailored': tailored}
if filter_top_level_profiles: if filter_top_level_profiles:
for profile in list(cache.keys()): for profile in list(cache.keys()):

View File

@ -5,6 +5,6 @@ def service_state(service_name: str):
if os.path.splitext(service_name)[1] != '.service': if os.path.splitext(service_name)[1] != '.service':
service_name += '.service' # Just to be safe service_name += '.service' # Just to be safe
state = b''.join(sys_command(f'systemctl show --no-pager -p SubState --value {service_name}', environment_vars={'SYSTEMD_COLORS' : '0'})) state = b''.join(sys_command(f'systemctl show --no-pager -p SubState --value {service_name}', environment_vars={'SYSTEMD_COLORS': '0'}))
return state.strip().decode('UTF-8') return state.strip().decode('UTF-8')

View File

@ -12,5 +12,4 @@ If the PR is larger than ~20 lines, please describe it here unless described in
# Testing # Testing
Any new feature or stability improvement should be tested if possible. Please follow the test instructions at the bottom Any new feature or stability improvement should be tested if possible. Please follow the test instructions at the bottom of the README or use the ISO built on each PR.
of the README or use the ISO built on each PR.

View File

@ -85,7 +85,7 @@ def ask_user_questions():
# If we provide keys as options, it's better to convert them to list and sort before passing # If we provide keys as options, it's better to convert them to list and sort before passing
mountpoints_list = sorted(list(partition_mountpoints.keys())) mountpoints_list = sorted(list(partition_mountpoints.keys()))
partition = archinstall.generic_select(mountpoints_list, partition = archinstall.generic_select(mountpoints_list,
"Select a partition by number that you want to set a mount-point for (leave blank when done): ") "Select a partition by number that you want to set a mount-point for (leave blank when done): ")
if not partition: if not partition:
if set(mountpoints_set) & {'/', '/boot'} == {'/', '/boot'}: if set(mountpoints_set) & {'/', '/boot'} == {'/', '/boot'}:
break break
@ -119,8 +119,9 @@ def ask_user_questions():
try: try:
partition.format(new_filesystem, path='/dev/null', log_formatting=False, allow_formatting=True) partition.format(new_filesystem, path='/dev/null', log_formatting=False, allow_formatting=True)
except archinstall.UnknownFilesystemFormat: except archinstall.UnknownFilesystemFormat:
archinstall.log(f"Selected filesystem is not supported yet. If you want archinstall to support '{new_filesystem}', please create a issue-ticket suggesting it on github at https://github.com/archlinux/archinstall/issues.") archinstall.log(f"Selected filesystem is not supported yet. If you want archinstall to support '{new_filesystem}',")
archinstall.log(f"Until then, please enter another supported filesystem.") archinstall.log("please create a issue-ticket suggesting it on github at https://github.com/archlinux/archinstall/issues.")
archinstall.log("Until then, please enter another supported filesystem.")
continue continue
except archinstall.SysCallError: 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.
@ -316,12 +317,12 @@ def perform_installation(mountpoint):
time.sleep(1) time.sleep(1)
# Set mirrors used by pacstrap (outside of installation) # Set mirrors used by pacstrap (outside of installation)
if archinstall.arguments.get('mirror-region', None): if archinstall.arguments.get('mirror-region', None):
archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium
if installation.minimal_installation(): if installation.minimal_installation():
installation.set_hostname(archinstall.arguments['hostname']) installation.set_hostname(archinstall.arguments['hostname'])
if archinstall.arguments['mirror-region'].get("mirrors", None) is not 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 installation.set_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors in the installation medium
if archinstall.arguments["bootloader"]=="grub-install" and hasUEFI()==True: if archinstall.arguments["bootloader"] == "grub-install" and hasUEFI() == True:
installation.add_additional_packages("grub") installation.add_additional_packages("grub")
installation.set_keyboard_language(archinstall.arguments['keyboard-language']) installation.set_keyboard_language(archinstall.arguments['keyboard-language'])
installation.add_bootloader(archinstall.arguments["bootloader"]) installation.add_bootloader(archinstall.arguments["bootloader"])
@ -329,8 +330,8 @@ def perform_installation(mountpoint):
# If user selected to copy the current ISO network configuration # If user selected to copy the current ISO network configuration
# Perform a copy of the config # Perform a copy of the config
if archinstall.arguments.get('nic', {}) == 'Copy ISO network configuration to installation': if archinstall.arguments.get('nic', {}) == 'Copy ISO network configuration to installation':
installation.copy_ISO_network_config(enable_services=True) # Sources the ISO network configuration to the install medium. installation.copy_ISO_network_config(enable_services=True) # Sources the ISO network configuration to the install medium.
elif archinstall.arguments.get('nic', {}).get('NetworkManager',False): elif archinstall.arguments.get('nic', {}).get('NetworkManager', False):
installation.add_additional_packages("networkmanager") installation.add_additional_packages("networkmanager")
installation.enable_service('NetworkManager.service') installation.enable_service('NetworkManager.service')
# Otherwise, if a interface was selected, configure that interface # Otherwise, if a interface was selected, configure that interface

View File

@ -37,5 +37,5 @@ if __name__ == 'gnome':
archinstall.storage['installation_session'].add_additional_packages(__packages__) archinstall.storage['installation_session'].add_additional_packages(__packages__)
archinstall.storage['installation_session'].enable_service('gdm') # Gnome Display Manager archinstall.storage['installation_session'].enable_service('gdm') # Gnome Display Manager
# We could also start it via xinitrc since we do have Xorg, # We could also start it via xinitrc since we do have Xorg,
# but for gnome that's deprecated and wayland is preferred. # but for gnome that's deprecated and wayland is preferred.

View File

@ -30,11 +30,11 @@ if __name__ == 'xorg':
try: try:
if "nvidia" in _gfx_driver_packages: if "nvidia" in _gfx_driver_packages:
if "linux-zen" in archinstall.storage['installation_session'].base_packages or "linux-lts" in archinstall.storage['installation_session'].base_packages: if "linux-zen" in archinstall.storage['installation_session'].base_packages or "linux-lts" in archinstall.storage['installation_session'].base_packages:
archinstall.storage['installation_session'].add_additional_packages("dkms")#I've had kernel regen fail if it wasn't installed before nvidia-dkms archinstall.storage['installation_session'].add_additional_packages("dkms") # I've had kernel regen fail if it wasn't installed before nvidia-dkms
archinstall.storage['installation_session'].add_additional_packages("xorg-server xorg-xinit nvidia-dkms") archinstall.storage['installation_session'].add_additional_packages("xorg-server xorg-xinit nvidia-dkms")
else: else:
archinstall.storage['installation_session'].add_additional_packages(f"xorg-server xorg-xinit {' '.join(_gfx_driver_packages)}") archinstall.storage['installation_session'].add_additional_packages(f"xorg-server xorg-xinit {' '.join(_gfx_driver_packages)}")
else: else:
archinstall.storage['installation_session'].add_additional_packages(f"xorg-server xorg-xinit {' '.join(_gfx_driver_packages)}") archinstall.storage['installation_session'].add_additional_packages(f"xorg-server xorg-xinit {' '.join(_gfx_driver_packages)}")
except: except:
archinstall.storage['installation_session'].add_additional_packages("xorg-server xorg-xinit") # Prep didn't run, so there's no driver to install archinstall.storage['installation_session'].add_additional_packages("xorg-server xorg-xinit") # Prep didn't run, so there's no driver to install