Tweaked logging slightly.

This commit is contained in:
Anton Hvornum 2021-03-08 15:54:23 +01:00
parent c5694393c6
commit 1ef63147d0
3 changed files with 27 additions and 15 deletions

View File

@ -7,6 +7,7 @@ from .storage import storage
ROOT_DIR_PATTERN = re.compile('^.*?/devices')
GPT = 0b00000001
MBR = 0b00000010
#import ctypes
#import ctypes.util
@ -113,6 +114,10 @@ class BlockDevice():
all_partitions = self.partitions
return [all_partitions[k] for k in all_partitions]
@property
def partition_table_type(self):
return GPT
def has_partitions(self):
return len(self.partitions)
@ -272,15 +277,21 @@ class Filesystem():
self.mode = mode
def __enter__(self, *args, **kwargs):
#if self.mode == GPT:
# if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt',).exit_code == 0:
# return self
# else:
# raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt')
#else:
# raise DiskError(f'Unknown mode selected to format in: {self.mode}')
print(type(self.blockdevice))
print('Keep partitions:', self.blockdevice.keep_partitions)
if self.blockdevice.keep_partitions is False:
log(f'Wiping {self.blockdevice} by using partition format {self.mode}', level=LOG_LEVELS.Debug)
if self.mode == GPT:
if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt',).exit_code == 0:
return self
else:
raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt')
else:
raise DiskError(f'Unknown mode selected to format in: {self.mode}')
# TODO: partition_table_type is hardcoded to GPT at the moment. This has to be changed.
elif self.mode == self.blockdevice.partition_table_type:
log(f'Kept partition format {self.mode} for {self.blockdevice}', level=LOG_LEVELS.Debug)
else:
raise DiskError(f'The selected partition table format {self.mode} does not match that of {self.blockdevice}.')
def __repr__(self):
return f"Filesystem(blockdevice={self.blockdevice}, mode={self.mode})"

View File

@ -5,6 +5,9 @@ import logging
from pathlib import Path
from .storage import storage
# TODO: use logging's built in levels instead.
# Altough logging is threaded and I wish to avoid that.
# It's more Pythonistic or w/e you want to call it.
class LOG_LEVELS:
Critical = 0b001
Error = 0b010
@ -108,10 +111,10 @@ def log(*args, **kwargs):
# In that case, we'll drop it.
return None
try:
journald.log(string, level=kwargs['level'])
except ModuleNotFoundError:
pass # Ignore writing to journald
try:
journald.log(string, level=kwargs.get('level', LOG_LEVELS.Info))
except ModuleNotFoundError:
pass # Ignore writing to journald
# Finally, print the log unless we skipped it based on level.
# We use sys.stdout.write()+flush() instead of print() to try and

View File

@ -271,8 +271,6 @@ signal.signal(signal.SIGINT, original_sigint_handler)
Once that's done, we'll hand over to perform_installation()
"""
with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs:
print('Debug')
exit(0)
# Use partitioning helper to set up the disk partitions.
if disk_password:
fs.use_entire_disk('luks2')