Rename "peak_output" to "peek_output" (#1648)
* Rename "peak_output" to "peek_output" * Added backwards compatability * Added deprecated warning to peak_output --------- Co-authored-by: Anton Hvornum <anton@hvornum.se>
This commit is contained in:
parent
fa1bec9679
commit
f26b530859
|
|
@ -185,12 +185,16 @@ class SysCommandWorker:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
cmd :Union[str, List[str]],
|
cmd :Union[str, List[str]],
|
||||||
callbacks :Optional[Dict[str, Any]] = None,
|
callbacks :Optional[Dict[str, Any]] = None,
|
||||||
|
peek_output :Optional[bool] = False,
|
||||||
peak_output :Optional[bool] = False,
|
peak_output :Optional[bool] = False,
|
||||||
environment_vars :Optional[Dict[str, Any]] = None,
|
environment_vars :Optional[Dict[str, Any]] = None,
|
||||||
logfile :Optional[None] = None,
|
logfile :Optional[None] = None,
|
||||||
working_directory :Optional[str] = './',
|
working_directory :Optional[str] = './',
|
||||||
remove_vt100_escape_codes_from_lines :bool = True):
|
remove_vt100_escape_codes_from_lines :bool = True):
|
||||||
|
|
||||||
|
if peak_output:
|
||||||
|
log("SysCommandWorker()'s peak_output is deprecated, use peek_output instead.", level=logging.WARNING, fg='red')
|
||||||
|
|
||||||
if not callbacks:
|
if not callbacks:
|
||||||
callbacks = {}
|
callbacks = {}
|
||||||
if not environment_vars:
|
if not environment_vars:
|
||||||
|
|
@ -208,7 +212,9 @@ class SysCommandWorker:
|
||||||
|
|
||||||
self.cmd = cmd
|
self.cmd = cmd
|
||||||
self.callbacks = callbacks
|
self.callbacks = callbacks
|
||||||
self.peak_output = peak_output
|
self.peek_output = peek_output
|
||||||
|
if not self.peek_output and peak_output:
|
||||||
|
self.peek_output = peak_output
|
||||||
# define the standard locale for command outputs. For now the C ascii one. Can be overridden
|
# define the standard locale for command outputs. For now the C ascii one. Can be overridden
|
||||||
self.environment_vars = {**storage.get('CMD_LOCALE',{}),**environment_vars}
|
self.environment_vars = {**storage.get('CMD_LOCALE',{}),**environment_vars}
|
||||||
self.logfile = logfile
|
self.logfile = logfile
|
||||||
|
|
@ -262,7 +268,7 @@ class SysCommandWorker:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self.peak_output:
|
if self.peek_output:
|
||||||
# To make sure any peaked output didn't leave us hanging
|
# To make sure any peaked output didn't leave us hanging
|
||||||
# on the same line we were on.
|
# on the same line we were on.
|
||||||
sys.stdout.write("\n")
|
sys.stdout.write("\n")
|
||||||
|
|
@ -307,7 +313,7 @@ class SysCommandWorker:
|
||||||
self._trace_log_pos = min(max(0, pos), len(self._trace_log))
|
self._trace_log_pos = min(max(0, pos), len(self._trace_log))
|
||||||
|
|
||||||
def peak(self, output: Union[str, bytes]) -> bool:
|
def peak(self, output: Union[str, bytes]) -> bool:
|
||||||
if self.peak_output:
|
if self.peek_output:
|
||||||
if type(output) == bytes:
|
if type(output) == bytes:
|
||||||
try:
|
try:
|
||||||
output = output.decode('UTF-8')
|
output = output.decode('UTF-8')
|
||||||
|
|
@ -320,8 +326,8 @@ class SysCommandWorker:
|
||||||
if peak_logfile.exists() is False:
|
if peak_logfile.exists() is False:
|
||||||
change_perm = True
|
change_perm = True
|
||||||
|
|
||||||
with peak_logfile.open("a") as peak_output_log:
|
with peak_logfile.open("a") as peek_output_log:
|
||||||
peak_output_log.write(output)
|
peek_output_log.write(output)
|
||||||
|
|
||||||
if change_perm:
|
if change_perm:
|
||||||
os.chmod(str(peak_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
os.chmod(str(peak_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
||||||
|
|
@ -412,11 +418,15 @@ class SysCommand:
|
||||||
cmd :Union[str, List[str]],
|
cmd :Union[str, List[str]],
|
||||||
callbacks :Optional[Dict[str, Callable[[Any], Any]]] = None,
|
callbacks :Optional[Dict[str, Callable[[Any], Any]]] = None,
|
||||||
start_callback :Optional[Callable[[Any], Any]] = None,
|
start_callback :Optional[Callable[[Any], Any]] = None,
|
||||||
|
peek_output :Optional[bool] = False,
|
||||||
peak_output :Optional[bool] = False,
|
peak_output :Optional[bool] = False,
|
||||||
environment_vars :Optional[Dict[str, Any]] = None,
|
environment_vars :Optional[Dict[str, Any]] = None,
|
||||||
working_directory :Optional[str] = './',
|
working_directory :Optional[str] = './',
|
||||||
remove_vt100_escape_codes_from_lines :bool = True):
|
remove_vt100_escape_codes_from_lines :bool = True):
|
||||||
|
|
||||||
|
if peak_output:
|
||||||
|
log("SysCommandWorker()'s peak_output is deprecated, use peek_output instead.", level=logging.WARNING, fg='red')
|
||||||
|
|
||||||
_callbacks = {}
|
_callbacks = {}
|
||||||
if callbacks:
|
if callbacks:
|
||||||
for hook, func in callbacks.items():
|
for hook, func in callbacks.items():
|
||||||
|
|
@ -426,7 +436,9 @@ class SysCommand:
|
||||||
|
|
||||||
self.cmd = cmd
|
self.cmd = cmd
|
||||||
self._callbacks = _callbacks
|
self._callbacks = _callbacks
|
||||||
self.peak_output = peak_output
|
self.peek_output = peek_output
|
||||||
|
if not self.peek_output and peak_output:
|
||||||
|
self.peek_output = peak_output
|
||||||
self.environment_vars = environment_vars
|
self.environment_vars = environment_vars
|
||||||
self.working_directory = working_directory
|
self.working_directory = working_directory
|
||||||
self.remove_vt100_escape_codes_from_lines = remove_vt100_escape_codes_from_lines
|
self.remove_vt100_escape_codes_from_lines = remove_vt100_escape_codes_from_lines
|
||||||
|
|
@ -469,7 +481,7 @@ class SysCommand:
|
||||||
return {
|
return {
|
||||||
'cmd': self.cmd,
|
'cmd': self.cmd,
|
||||||
'callbacks': self._callbacks,
|
'callbacks': self._callbacks,
|
||||||
'peak': self.peak_output,
|
'peak': self.peek_output,
|
||||||
'environment_vars': self.environment_vars,
|
'environment_vars': self.environment_vars,
|
||||||
'session': True if self.session else False
|
'session': True if self.session else False
|
||||||
}
|
}
|
||||||
|
|
@ -478,7 +490,7 @@ class SysCommand:
|
||||||
"""
|
"""
|
||||||
Initiates a :ref:`SysCommandWorker` session in this class ``.session``.
|
Initiates a :ref:`SysCommandWorker` session in this class ``.session``.
|
||||||
It then proceeds to poll the process until it ends, after which it also
|
It then proceeds to poll the process until it ends, after which it also
|
||||||
clears any printed output if ``.peak_output=True``.
|
clears any printed output if ``.peek_output=True``.
|
||||||
"""
|
"""
|
||||||
if self.session:
|
if self.session:
|
||||||
return self.session
|
return self.session
|
||||||
|
|
@ -486,7 +498,7 @@ class SysCommand:
|
||||||
with SysCommandWorker(
|
with SysCommandWorker(
|
||||||
self.cmd,
|
self.cmd,
|
||||||
callbacks=self._callbacks,
|
callbacks=self._callbacks,
|
||||||
peak_output=self.peak_output,
|
peek_output=self.peek_output,
|
||||||
environment_vars=self.environment_vars,
|
environment_vars=self.environment_vars,
|
||||||
remove_vt100_escape_codes_from_lines=self.remove_vt100_escape_codes_from_lines,
|
remove_vt100_escape_codes_from_lines=self.remove_vt100_escape_codes_from_lines,
|
||||||
working_directory=self.working_directory) as session:
|
working_directory=self.working_directory) as session:
|
||||||
|
|
@ -497,7 +509,7 @@ class SysCommand:
|
||||||
while self.session.ended is None:
|
while self.session.ended is None:
|
||||||
self.session.poll()
|
self.session.poll()
|
||||||
|
|
||||||
if self.peak_output:
|
if self.peek_output:
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class Fido2:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fido2_enroll(cls, hsm_device: Fido2Device, partition :Partition, password :str):
|
def fido2_enroll(cls, hsm_device: Fido2Device, partition :Partition, password :str):
|
||||||
worker = SysCommandWorker(f"systemd-cryptenroll --fido2-device={hsm_device.path} {partition.real_device}", peak_output=True)
|
worker = SysCommandWorker(f"systemd-cryptenroll --fido2-device={hsm_device.path} {partition.real_device}", peek_output=True)
|
||||||
pw_inputted = False
|
pw_inputted = False
|
||||||
pin_inputted = False
|
pin_inputted = False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,7 @@ class Installer:
|
||||||
raise RequirementError(f'Could not sync mirrors: {error}', level=logging.ERROR, fg="red")
|
raise RequirementError(f'Could not sync mirrors: {error}', level=logging.ERROR, fg="red")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return SysCommand(f'/usr/bin/pacstrap -C /etc/pacman.conf {self.target} {" ".join(packages)} --noconfirm', peak_output=True).exit_code == 0
|
return SysCommand(f'/usr/bin/pacstrap -C /etc/pacman.conf {self.target} {" ".join(packages)} --noconfirm', peek_output=True).exit_code == 0
|
||||||
except SysCallError as error:
|
except SysCallError as error:
|
||||||
self.log(f'Could not strap in packages: {error}', level=logging.ERROR, fg="red")
|
self.log(f'Could not strap in packages: {error}', level=logging.ERROR, fg="red")
|
||||||
|
|
||||||
|
|
@ -921,15 +921,15 @@ class Installer:
|
||||||
if has_uefi():
|
if has_uefi():
|
||||||
self.pacstrap('efibootmgr') # TODO: Do we need? Yes, but remove from minimal_installation() instead?
|
self.pacstrap('efibootmgr') # TODO: Do we need? Yes, but remove from minimal_installation() instead?
|
||||||
try:
|
try:
|
||||||
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB --removable', peak_output=True)
|
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB --removable', peek_output=True)
|
||||||
except SysCallError:
|
except SysCallError:
|
||||||
try:
|
try:
|
||||||
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB --removable', peak_output=True)
|
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB --removable', peek_output=True)
|
||||||
except SysCallError as error:
|
except SysCallError as error:
|
||||||
raise DiskError(f"Could not install GRUB to {self.target}/boot: {error}")
|
raise DiskError(f"Could not install GRUB to {self.target}/boot: {error}")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=i386-pc --recheck {boot_partition.parent}', peak_output=True)
|
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=i386-pc --recheck {boot_partition.parent}', peek_output=True)
|
||||||
except SysCallError as error:
|
except SysCallError as error:
|
||||||
raise DiskError(f"Could not install GRUB to {boot_partition.path}: {error}")
|
raise DiskError(f"Could not install GRUB to {boot_partition.path}: {error}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue