Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds@gmail.com>2021-03-08 15:54:23 +0100
committerAnton Hvornum <anton.feeds@gmail.com>2021-03-08 15:54:23 +0100
commit1ef63147d0eeb002dcc9475f2fcec3abddc1298d (patch)
tree117e448be0fb249532c8756bb08b597f803b727d /archinstall
parentc5694393c6a9d53cbc7a2886e733b354d5055772 (diff)
Tweaked logging slightly.
Diffstat (limited to 'archinstall')
-rw-r--r--archinstall/lib/disk.py29
-rw-r--r--archinstall/lib/output.py11
2 files changed, 27 insertions, 13 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index f01300b3..a0fcfddf 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -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})"
diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py
index 956ad0c4..0e0a295b 100644
--- a/archinstall/lib/output.py
+++ b/archinstall/lib/output.py
@@ -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