Merge branch 'exec-args' of https://github.com/kpcyrd/archinstall into torxed-v2.2.0

This commit is contained in:
Anton Hvornum 2021-04-02 20:36:06 +02:00
commit f61c61305e
2 changed files with 17 additions and 9 deletions

View File

@ -73,7 +73,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(sys_command(f'losetup --json', hide_from_log=True)).decode('UTF_8'))['loopdevices']:
for drive in json.loads(b''.join(sys_command(['losetup', '--json'], hide_from_log=True)).decode('UTF_8'))['loopdevices']:
if not drive['name'] == self.path: continue
return drive['back-file']
@ -89,10 +89,10 @@ class BlockDevice():
@property
def partitions(self):
o = b''.join(sys_command(f'partprobe {self.path}'))
o = b''.join(sys_command(['partprobe', self.path]))
#o = b''.join(sys_command('/usr/bin/lsblk -o name -J -b {dev}'.format(dev=dev)))
o = b''.join(sys_command(f'/usr/bin/lsblk -J {self.path}'))
o = b''.join(sys_command(['/usr/bin/lsblk', '-J', self.path]))
if b'not a block device' in o:
raise DiskError(f'Can not read partitions off something that isn\'t a block device: {self.path}')
@ -203,7 +203,7 @@ class Partition():
if not self._encrypted:
return self.path
else:
for blockdevice in json.loads(b''.join(sys_command('lsblk -J')).decode('UTF-8'))['blockdevices']:
for blockdevice in json.loads(b''.join(sys_command(['lsblk', '-J'])).decode('UTF-8'))['blockdevices']:
if (parent := self.find_parent_of(blockdevice, os.path.basename(self.path))):
return f"/dev/{parent}"
# raise DiskError(f'Could not find appropriate parent for encrypted partition {self}')

View File

@ -86,11 +86,19 @@ class sys_command():#Thread):
if kwargs['emulate']:
self.log(f"Starting command '{cmd}' in emulation mode.", level=LOG_LEVELS.Debug)
self.raw_cmd = cmd
try:
self.cmd = shlex.split(cmd)
except Exception as e:
raise ValueError(f'Incorrect string to split: {cmd}\n{e}')
if type(cmd) is list:
# if we get a list of arguments
self.raw_cmd = shlex.join(cmd)
self.cmd = cmd
else:
# else consider it a single shell string
# this should only be used if really necessary
self.raw_cmd = cmd
try:
self.cmd = shlex.split(cmd)
except Exception as e:
raise ValueError(f'Incorrect string to split: {cmd}\n{e}')
self.args = args
self.kwargs = kwargs