Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-05-19 14:45:13 +0000
committerGitHub <noreply@github.com>2021-05-19 16:45:13 +0200
commit49e6cbdc545402e066bdc2daf6054abf6c1bf977 (patch)
treea1d4afcc6473d93bc958eab8241dbad616033dba /archinstall/lib/disk.py
parent52960bd686c92af4813ce302a21eb63a5aa67343 (diff)
Reworking SysCommand & Moving to localectl for locale related activities
* Moving to `localectl` rather than local file manipulation *(both for listing locales and setting them)*. * Swapped `loadkeys` for localectl. * Renamed `main` to `maim` in awesome profile. * Created `archinstall.Boot(<installation>)` which spawns a `systemd-nspawn` container against the installation target. * Exposing systemd.py's internals to archinstall global scope. * Re-worked `SysCommand` completely, it's now a wrapper for `SysCommandWorker` which supports interacting with the process in a different way. `SysCommand` should behave just like the old one, for backwards compatibility reasons. This fixes #68 and #69. * `SysCommand()` now has a `.decode()` function that defaults to `UTF-8`. * Adding back peak_output=True to pacstrap. Co-authored-by: Anton Hvornum <anton.feeds@gmail.com> Co-authored-by: Dylan Taylor <dylan@dylanmtaylor.com>
Diffstat (limited to 'archinstall/lib/disk.py')
-rw-r--r--archinstall/lib/disk.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index f8703ae3..44f2742b 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -1,6 +1,7 @@
import glob
import pathlib
import re
+import time
from collections import OrderedDict
from typing import Optional
@@ -77,7 +78,7 @@ class BlockDevice:
raise DiskError(f'Could not locate backplane info for "{self.path}"')
if self.info['type'] == 'loop':
- for drive in json.loads(b''.join(SysCommand(['losetup', '--json'], hide_from_log=True)).decode('UTF_8'))['loopdevices']:
+ for drive in json.loads(b''.join(SysCommand(['losetup', '--json'])).decode('UTF_8'))['loopdevices']:
if not drive['name'] == self.path:
continue
@@ -264,7 +265,9 @@ class Partition:
raise DiskError(f'Could not mount and check for content on {self.path} because: {b"".join(handle)}')
files = len(glob.glob(f"{temporary_mountpoint}/*"))
- SysCommand(f'/usr/bin/umount {temporary_mountpoint}')
+ iterations = 0
+ while SysCommand(f"/usr/bin/umount -R {temporary_mountpoint}").exit_code != 0 and (iterations := iterations+1) < 10:
+ time.sleep(1)
temporary_path.rmdir()
@@ -425,7 +428,7 @@ class Partition:
"""
try:
self.format(self.filesystem, '/dev/null', log_formatting=False, allow_formatting=True)
- except SysCallError:
+ except (SysCallError, DiskError):
pass # We supported it, but /dev/null is not formatable as expected so the mkfs call exited with an error code
except UnknownFilesystemFormat as err:
raise err
@@ -572,7 +575,7 @@ def all_disks(*args, **kwargs):
kwargs.setdefault("partitions", False)
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(b''.join(SysCommand('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(SysCommand('lsblk --json -l -n -o path,size,type,mountpoint,label,pkname,model')).decode('UTF_8'))['blockdevices']:
if not kwargs['partitions'] and drive['type'] == 'part':
continue
@@ -603,13 +606,17 @@ def harddrive(size=None, model=None, fuzzy=False):
return collection[drive]
-def get_mount_info(path):
+def get_mount_info(path) -> dict:
try:
- output = b''.join(SysCommand(f'/usr/bin/findmnt --json {path}'))
+ output = SysCommand(f'/usr/bin/findmnt --json {path}')
except SysCallError:
return {}
output = output.decode('UTF-8')
+
+ if not output:
+ return {}
+
output = json.loads(output)
if 'filesystems' in output:
if len(output['filesystems']) > 1:
@@ -618,15 +625,19 @@ def get_mount_info(path):
return output['filesystems'][0]
-def get_partitions_in_use(mountpoint):
+def get_partitions_in_use(mountpoint) -> list:
try:
- output = b''.join(SysCommand(f'/usr/bin/findmnt --json -R {mountpoint}'))
+ output = SysCommand(f'/usr/bin/findmnt --json -R {mountpoint}')
except SysCallError:
- return {}
+ return []
mounts = []
output = output.decode('UTF-8')
+
+ if not output:
+ return []
+
output = json.loads(output)
for target in output.get('filesystems', []):
mounts.append(Partition(target['source'], None, filesystem=target.get('fstype', None), mountpoint=target['target']))