Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/general.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/general.py')
-rw-r--r--archinstall/lib/general.py50
1 files changed, 37 insertions, 13 deletions
diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py
index 8c7aed91..79ab024b 100644
--- a/archinstall/lib/general.py
+++ b/archinstall/lib/general.py
@@ -130,7 +130,10 @@ class JsonEncoder:
copy[JsonEncoder._encode(key)] = val
return copy
elif hasattr(obj, 'json'):
- return obj.json()
+ # json() is a friendly name for json-helper, it should return
+ # a dictionary representation of the object so that it can be
+ # processed by the json library.
+ return json.loads(json.dumps(obj.json(), cls=JSON))
elif hasattr(obj, '__dump__'):
return obj.__dump__()
elif isinstance(obj, (datetime, date)):
@@ -185,12 +188,16 @@ class SysCommandWorker:
def __init__(self,
cmd :Union[str, List[str]],
callbacks :Optional[Dict[str, Any]] = None,
+ peek_output :Optional[bool] = False,
peak_output :Optional[bool] = False,
environment_vars :Optional[Dict[str, Any]] = None,
logfile :Optional[None] = None,
working_directory :Optional[str] = './',
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:
callbacks = {}
if not environment_vars:
@@ -208,7 +215,9 @@ class SysCommandWorker:
self.cmd = cmd
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
self.environment_vars = {**storage.get('CMD_LOCALE',{}),**environment_vars}
self.logfile = logfile
@@ -262,7 +271,7 @@ class SysCommandWorker:
except:
pass
- if self.peak_output:
+ if self.peek_output:
# To make sure any peaked output didn't leave us hanging
# on the same line we were on.
sys.stdout.write("\n")
@@ -307,7 +316,7 @@ class SysCommandWorker:
self._trace_log_pos = min(max(0, pos), len(self._trace_log))
def peak(self, output: Union[str, bytes]) -> bool:
- if self.peak_output:
+ if self.peek_output:
if type(output) == bytes:
try:
output = output.decode('UTF-8')
@@ -320,8 +329,8 @@ class SysCommandWorker:
if peak_logfile.exists() is False:
change_perm = True
- with peak_logfile.open("a") as peak_output_log:
- peak_output_log.write(output)
+ with peak_logfile.open("a") as peek_output_log:
+ peek_output_log.write(output)
if change_perm:
os.chmod(str(peak_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
@@ -349,10 +358,12 @@ class SysCommandWorker:
if self.ended or (got_output is False and pid_exists(self.pid) is False):
self.ended = time.time()
try:
- self.exit_code = os.waitpid(self.pid, 0)[1]
+ wait_status = os.waitpid(self.pid, 0)[1]
+ self.exit_code = os.waitstatus_to_exitcode(wait_status)
except ChildProcessError:
try:
- self.exit_code = os.waitpid(self.child_fd, 0)[1]
+ wait_status = os.waitpid(self.child_fd, 0)[1]
+ self.exit_code = os.waitstatus_to_exitcode(wait_status)
except ChildProcessError:
self.exit_code = 1
@@ -385,6 +396,13 @@ class SysCommandWorker:
os.chmod(str(history_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
except PermissionError:
pass
+ # If history_logfile does not exist, ignore the error
+ except FileNotFoundError:
+ pass
+ except Exception as e:
+ exception_type = type(e).__name__
+ log(f"Unexpected {exception_type} occurred in {self.cmd}: {e}", level=logging.ERROR)
+ raise e
os.execve(self.cmd[0], list(self.cmd), {**os.environ, **self.environment_vars})
if storage['arguments'].get('debug'):
@@ -412,11 +430,15 @@ class SysCommand:
cmd :Union[str, List[str]],
callbacks :Optional[Dict[str, Callable[[Any], Any]]] = None,
start_callback :Optional[Callable[[Any], Any]] = None,
+ peek_output :Optional[bool] = False,
peak_output :Optional[bool] = False,
environment_vars :Optional[Dict[str, Any]] = None,
working_directory :Optional[str] = './',
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 = {}
if callbacks:
for hook, func in callbacks.items():
@@ -426,7 +448,9 @@ class SysCommand:
self.cmd = cmd
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.working_directory = working_directory
self.remove_vt100_escape_codes_from_lines = remove_vt100_escape_codes_from_lines
@@ -469,7 +493,7 @@ class SysCommand:
return {
'cmd': self.cmd,
'callbacks': self._callbacks,
- 'peak': self.peak_output,
+ 'peak': self.peek_output,
'environment_vars': self.environment_vars,
'session': True if self.session else False
}
@@ -478,7 +502,7 @@ class SysCommand:
"""
Initiates a :ref:`SysCommandWorker` session in this class ``.session``.
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:
return self.session
@@ -486,7 +510,7 @@ class SysCommand:
with SysCommandWorker(
self.cmd,
callbacks=self._callbacks,
- peak_output=self.peak_output,
+ peek_output=self.peek_output,
environment_vars=self.environment_vars,
remove_vt100_escape_codes_from_lines=self.remove_vt100_escape_codes_from_lines,
working_directory=self.working_directory) as session:
@@ -497,7 +521,7 @@ class SysCommand:
while self.session.ended is None:
self.session.poll()
- if self.peak_output:
+ if self.peek_output:
sys.stdout.write('\n')
sys.stdout.flush()