helpers: hide channels.cfg and git remote log (MR 2252)

Add a new output=null option to run_core and use it for some git
commands.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-10 04:34:06 +02:00 committed by Oliver Smith
parent 15ffc2f370
commit e087e7c665
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 11 additions and 9 deletions

View file

@ -100,7 +100,7 @@ def get_upstream_remote(aports: Path):
name_repo = aports.parts[-1]
urls = pmb.config.git_repos[name_repo]
command = ["git", "remote", "-v"]
output = pmb.helpers.run.user_output(command, aports)
output = pmb.helpers.run.user_output(command, aports, output="null")
for line in output.split("\n"):
if any(u in line for u in urls):
return line.split("\t", 1)[0]
@ -125,8 +125,7 @@ def parse_channels_cfg(aports: Path):
cfg = configparser.ConfigParser()
remote = get_upstream_remote(aports)
command = ["git", "show", f"{remote}/master:channels.cfg"]
stdout = pmb.helpers.run.user_output(command, aports,
check=False)
stdout = pmb.helpers.run.user_output(command, aports, output="null", check=False)
try:
cfg.read_string(stdout)
except configparser.MissingSectionHeaderError:

View file

@ -57,7 +57,7 @@ def sanity_checks(output="log", output_return=False, check=None):
(all parameters are described in core() below).
"""
vals = ["log", "stdout", "interactive", "tui", "background", "pipe"]
vals = ["log", "stdout", "interactive", "tui", "background", "pipe", "null"]
if output not in vals:
raise RuntimeError("Invalid output value: " + str(output))
@ -90,7 +90,7 @@ def pipe(cmd, working_dir=None):
# FIXME (#2324): These types make no sense at all
def pipe_read(process, output_to_stdout=False, output_return=False,
def pipe_read(process, output_to_stdout=False, output_log=True, output_return=False,
output_return_buffer=False):
"""Read all output from a subprocess, copy it to the log and optionally stdout and a buffer variable.
@ -107,7 +107,8 @@ def pipe_read(process, output_to_stdout=False, output_return=False,
# Copy available output
out = process.stdout.readline()
if len(out):
pmb.helpers.logging.logfd.buffer.write(out)
if output_log:
pmb.helpers.logging.logfd.buffer.write(out)
if output_to_stdout:
sys.stdout.buffer.write(out)
if output_return:
@ -160,7 +161,7 @@ def kill_command(pid, sudo):
def foreground_pipe(cmd, working_dir=None, output_to_stdout=False,
output_return=False, output_timeout=True,
output_return=False, output_log=True, output_timeout=True,
sudo=False, stdin=None):
"""Run a subprocess in foreground with redirected output.
@ -217,11 +218,11 @@ def foreground_pipe(cmd, working_dir=None, output_to_stdout=False,
continue
# Read all currently available output
pipe_read(process, output_to_stdout, output_return,
pipe_read(process, output_to_stdout, output_log, output_return,
output_buffer)
# There may still be output after the process quit
pipe_read(process, output_to_stdout, output_return, output_buffer)
pipe_read(process, output_to_stdout, output_log, output_return, output_buffer)
# Return the return code and output (the output gets built as list of
# output chunks and combined at the end, this is faster than extending the
@ -344,6 +345,7 @@ def core(log_message, cmd, working_dir=None, output="log",
"tui" x x x
"background" x
"pipe"
"null"
============= ======= ========== ============= ==== ==========
:param output_return: in addition to writing the program's output to the
@ -398,6 +400,7 @@ def core(log_message, cmd, working_dir=None, output="log",
(code, output_after_run) = foreground_pipe(cmd, working_dir,
output_to_stdout,
output_return,
output!="null",
output_timeout,
sudo, stdin)