osbuild add new -q, --quiet option

Current osbuild will always print some non output even
when run with `--monitor=JSONSeqMonitor` because of the
unconditional `print/sys.stdout.write()` in `main_cli.py`.

This commit adds a new `-q` option to silence this so that something
like osbuild-composer can run `osbuild -q --monitor=JSONSeqMonitor`
to get pure json-seq output during the build.

The use-case is to run `osbuild --monitor-fd` from e.g. bib and
osbuild-composer so that we get pure json from the monitor-fd
and anything that goes on std{out,err} can be logged as it is
most likely error output.
This commit is contained in:
Michael Vogt 2024-07-08 12:12:38 +02:00 committed by Brian C. Lane
parent a221d4e68b
commit ea14713f3a
2 changed files with 24 additions and 2 deletions

View file

@ -103,6 +103,8 @@ def parse_arguments(sys_argv: List[str]) -> argparse.Namespace:
# nargs='?' const='*' means `--break` is equivalent to `--break=*`
parser.add_argument("--break", dest='debug_break', type=str, nargs='?', const='*',
help="open debug shell when executing stage. Accepts stage name or id or * (for all)")
parser.add_argument("--quiet", "-q", action="store_true",
help="suppress normal output")
return parser.parse_args(sys_argv[1:])
@ -162,7 +164,7 @@ def osbuild_cli() -> int:
monitor_name = args.monitor
if not monitor_name:
monitor_name = "NullMonitor" if args.json else "LogMonitor"
monitor_name = "NullMonitor" if (args.json or args.quiet) else "LogMonitor"
try:
with ObjectStore(args.store) as object_store:
@ -201,7 +203,7 @@ def osbuild_cli() -> int:
r = fmt.output(manifest, r, object_store)
json.dump(r, sys.stdout)
sys.stdout.write("\n")
else:
elif not args.quiet:
if r["success"]:
for name, pl in manifest.pipelines.items():
print(f"{name + ':': <10}\t{pl.id}")