Adding compression as an option (#1084)

* Adding compression as an option

* Ignore 'misaligned' ending parenthathese

* Moved the 'mark compressed' logic into the sub block within manual disk operations.

* Fixed flake8 complaints

* Muting a complextion warning on manage_new_and_existing_partitions(). It is too complex, but not something that we'll bother with for v2.4.0. As this whole function could be replaced with a new and improved menu system split into tasks rather than one huge if/else.
This commit is contained in:
Anton Hvornum 2022-04-26 13:17:40 +02:00 committed by GitHub
parent 1bce561a0c
commit 12b5e2e4e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 11 deletions

View File

@ -1,7 +1,7 @@
[flake8]
count = True
# Several of the following could be autofixed or improved by running the code through psf/black
ignore = E126,E128,E203,E231,E261,E302,E402,E722,F541,W191,W292,W293
ignore = E123,E126,E128,E203,E231,E261,E302,E402,E722,F541,W191,W292,W293
max-complexity = 40
max-line-length = 236
show-source = True

View File

@ -23,12 +23,17 @@ def suggest_single_disk_layout(block_device :BlockDevice,
MIN_SIZE_TO_ALLOW_HOME_PART = 40 # GiB
using_subvolumes = False
using_home_partition = False
compression = False
if default_filesystem == 'btrfs':
prompt = 'Would you like to use BTRFS subvolumes with a default structure?'
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
using_subvolumes = choice == 'yes'
prompt = 'Would you like to use BTRFS compression?'
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
compression = choice == 'yes'
layout = {
block_device.path : {
"wipe" : True,
@ -73,7 +78,8 @@ def suggest_single_disk_layout(block_device :BlockDevice,
"wipe" : True,
"mountpoint" : "/" if not using_subvolumes else None,
"filesystem" : {
"format" : default_filesystem
"format" : default_filesystem,
"mount_options" : ["compress=zstd"] if compression else []
}
})
@ -124,7 +130,8 @@ def suggest_single_disk_layout(block_device :BlockDevice,
"wipe" : True,
"mountpoint" : "/home",
"filesystem" : {
"format" : default_filesystem
"format" : default_filesystem,
"mount_options" : ["compress=zstd"] if compression else []
}
})
@ -151,6 +158,17 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
home_device = select_largest_device(block_devices, gigabytes=MIN_SIZE_TO_ALLOW_HOME_PART)
root_device = select_disk_larger_than_or_close_to(block_devices, gigabytes=ARCH_LINUX_INSTALLED_SIZE, filter_out=[home_device])
compression = False
if default_filesystem == 'btrfs':
# prompt = 'Would you like to use BTRFS subvolumes with a default structure?'
# choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
# using_subvolumes = choice == 'yes'
prompt = 'Would you like to use BTRFS compression?'
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
compression = choice == 'yes'
log(f"Suggesting multi-disk-layout using {len(block_devices)} disks, where {root_device} will be /root and {home_device} will be /home", level=logging.DEBUG)
layout = {
@ -193,7 +211,8 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
"wipe" : True,
"mountpoint" : "/",
"filesystem" : {
"format" : default_filesystem
"format" : default_filesystem,
"mount_options" : ["compress=zstd"] if compression else []
}
})
if has_uefi():
@ -208,7 +227,8 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
"wipe" : True,
"mountpoint" : "/home",
"filesystem" : {
"format" : default_filesystem
"format" : default_filesystem,
"mount_options" : ["compress=zstd"] if compression else []
}
})

View File

@ -235,7 +235,7 @@ class Installer:
list_part.extend(layouts[blockdevice]['partitions'])
# we manage the encrypted partititons
for partition in [entry for entry in list_part if entry.get('encrypted',False)]:
for partition in [entry for entry in list_part if entry.get('encrypted', False)]:
# open the luks device and all associate stuff
if not (password := partition.get('!password', None)):
raise RequirementError(f"Missing partition {partition['device_instance'].path} encryption password in layout: {partition}")
@ -252,7 +252,11 @@ class Installer:
# we manage the btrfs partitions
for partition in [entry for entry in list_part if entry.get('btrfs', {}).get('subvolumes', {})]:
self.mount(partition['device_instance'],"/")
if partition.get('filesystem',{}).get('mount_options',[]):
mount_options = ','.join(partition['filesystem']['mount_options'])
self.mount(partition['device_instance'], "/", options=mount_options)
else:
self.mount(partition['device_instance'], "/")
try:
new_mountpoints = manage_btrfs_subvolumes(self,partition)
except Exception as e:
@ -270,7 +274,7 @@ class Installer:
if partition.get('filesystem',{}).get('mount_options',[]):
mount_options = ','.join(partition['filesystem']['mount_options'])
partition['device_instance'].mount(f"{self.target}{mountpoint}",options=mount_options)
partition['device_instance'].mount(f"{self.target}{mountpoint}", options=mount_options)
else:
partition['device_instance'].mount(f"{self.target}{mountpoint}")
@ -287,11 +291,11 @@ class Installer:
log(f"creating key-file for {ppath}",level=logging.INFO)
self._create_keyfile(handle[0],handle[1],handle[2])
def mount(self, partition :Partition, mountpoint :str, create_mountpoint :bool = True) -> None:
def mount(self, partition :Partition, mountpoint :str, create_mountpoint :bool = True, options='') -> None:
if create_mountpoint and not os.path.isdir(f'{self.target}{mountpoint}'):
os.makedirs(f'{self.target}{mountpoint}')
partition.mount(f'{self.target}{mountpoint}')
partition.mount(f'{self.target}{mountpoint}', options=options)
def post_install_check(self, *args :str, **kwargs :str) -> List[str]:
return [step for step, flag in self.helper_flags.items() if flag is False]

View File

@ -113,7 +113,7 @@ def select_individual_blockdevice_usage(block_devices: list) -> Dict[str, Any]:
return result
def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str, Any]:
def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str, Any]: # noqa: max-complexity: 50
block_device_struct = {"partitions": [partition.__dump__() for partition in block_device.partitions.values()]}
# Test code: [part.__dump__() for part in block_device.partitions.values()]
# TODO: Squeeze in BTRFS subvolumes here
@ -125,6 +125,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
assign_mount_point = str(_('Assign mount-point for a partition'))
mark_formatted = str(_('Mark/Unmark a partition to be formatted (wipes data)'))
mark_encrypted = str(_('Mark/Unmark a partition as encrypted'))
mark_compressed = str(_('Mark/Unmark a partition as compressed (btrfs only)'))
mark_bootable = str(_('Mark/Unmark a partition as bootable (automatic for /boot)'))
set_filesystem_partition = str(_('Set desired filesystem for a partition'))
set_btrfs_subvolumes = str(_('Set desired subvolumes on a btrfs partition'))
@ -140,6 +141,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
mark_formatted,
mark_encrypted,
mark_bootable,
mark_compressed,
set_filesystem_partition,
set_btrfs_subvolumes,
]
@ -213,6 +215,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
continue
block_device_struct.update(suggest_single_disk_layout(block_device)[block_device.path])
elif task is None:
return block_device_struct
else:
@ -226,6 +229,18 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
block_device_struct['partitions'] = [
p for idx, p in enumerate(block_device_struct['partitions']) if idx not in to_delete
]
elif task == mark_compressed:
title = _('{}\n\nSelect which partition to mark as bootable').format(current_layout)
partition = select_partition(title, block_device_struct["partitions"])
if partition is not None:
if "filesystem" not in block_device_struct["partitions"][partition]:
block_device_struct["partitions"][partition]["filesystem"] = {}
if "mount_options" not in block_device_struct["partitions"][partition]["filesystem"]:
block_device_struct["partitions"][partition]["filesystem"]["mount_options"] = []
if "compress=zstd" not in block_device_struct["partitions"][partition]["filesystem"]["mount_options"]:
block_device_struct["partitions"][partition]["filesystem"]["mount_options"].append("compress=zstd")
elif task == delete_all_partitions:
block_device_struct["partitions"] = []
elif task == assign_mount_point: