forked from Mirror/pmbootstrap
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:
parent
15ffc2f370
commit
e087e7c665
2 changed files with 11 additions and 9 deletions
|
@ -100,7 +100,7 @@ def get_upstream_remote(aports: Path):
|
||||||
name_repo = aports.parts[-1]
|
name_repo = aports.parts[-1]
|
||||||
urls = pmb.config.git_repos[name_repo]
|
urls = pmb.config.git_repos[name_repo]
|
||||||
command = ["git", "remote", "-v"]
|
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"):
|
for line in output.split("\n"):
|
||||||
if any(u in line for u in urls):
|
if any(u in line for u in urls):
|
||||||
return line.split("\t", 1)[0]
|
return line.split("\t", 1)[0]
|
||||||
|
@ -125,8 +125,7 @@ def parse_channels_cfg(aports: Path):
|
||||||
cfg = configparser.ConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
remote = get_upstream_remote(aports)
|
remote = get_upstream_remote(aports)
|
||||||
command = ["git", "show", f"{remote}/master:channels.cfg"]
|
command = ["git", "show", f"{remote}/master:channels.cfg"]
|
||||||
stdout = pmb.helpers.run.user_output(command, aports,
|
stdout = pmb.helpers.run.user_output(command, aports, output="null", check=False)
|
||||||
check=False)
|
|
||||||
try:
|
try:
|
||||||
cfg.read_string(stdout)
|
cfg.read_string(stdout)
|
||||||
except configparser.MissingSectionHeaderError:
|
except configparser.MissingSectionHeaderError:
|
||||||
|
|
|
@ -57,7 +57,7 @@ def sanity_checks(output="log", output_return=False, check=None):
|
||||||
|
|
||||||
(all parameters are described in core() below).
|
(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:
|
if output not in vals:
|
||||||
raise RuntimeError("Invalid output value: " + str(output))
|
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
|
# 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):
|
output_return_buffer=False):
|
||||||
"""Read all output from a subprocess, copy it to the log and optionally stdout and a buffer variable.
|
"""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
|
# Copy available output
|
||||||
out = process.stdout.readline()
|
out = process.stdout.readline()
|
||||||
if len(out):
|
if len(out):
|
||||||
pmb.helpers.logging.logfd.buffer.write(out)
|
if output_log:
|
||||||
|
pmb.helpers.logging.logfd.buffer.write(out)
|
||||||
if output_to_stdout:
|
if output_to_stdout:
|
||||||
sys.stdout.buffer.write(out)
|
sys.stdout.buffer.write(out)
|
||||||
if output_return:
|
if output_return:
|
||||||
|
@ -160,7 +161,7 @@ def kill_command(pid, sudo):
|
||||||
|
|
||||||
|
|
||||||
def foreground_pipe(cmd, working_dir=None, output_to_stdout=False,
|
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):
|
sudo=False, stdin=None):
|
||||||
"""Run a subprocess in foreground with redirected output.
|
"""Run a subprocess in foreground with redirected output.
|
||||||
|
|
||||||
|
@ -217,11 +218,11 @@ def foreground_pipe(cmd, working_dir=None, output_to_stdout=False,
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Read all currently available output
|
# 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)
|
output_buffer)
|
||||||
|
|
||||||
# There may still be output after the process quit
|
# 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
|
# 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
|
# 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
|
"tui" x x x
|
||||||
"background" x
|
"background" x
|
||||||
"pipe"
|
"pipe"
|
||||||
|
"null"
|
||||||
============= ======= ========== ============= ==== ==========
|
============= ======= ========== ============= ==== ==========
|
||||||
|
|
||||||
:param output_return: in addition to writing the program's output to the
|
: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,
|
(code, output_after_run) = foreground_pipe(cmd, working_dir,
|
||||||
output_to_stdout,
|
output_to_stdout,
|
||||||
output_return,
|
output_return,
|
||||||
|
output!="null",
|
||||||
output_timeout,
|
output_timeout,
|
||||||
sudo, stdin)
|
sudo, stdin)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue