osbuild: make jsonseq montior creation more uniform

This changes the way monitors are initialized to always include
a `manifest` and now they will always log a `start` message.

This makes creation of a monitor symetric accross all monitors
again and no special cases for JSONSeqMonitor are required.

It means one needs to run the json-seq monitor with:
```
$ python3 -m osbuild --monitor=JSONSeqMonitor
```

Fwiw, I'm not 100% confident this is a win but it feels slightly
more right then the special cases in `main_cli.py` that is
replaces.
This commit is contained in:
Michael Vogt 2023-11-20 17:06:03 +01:00 committed by Ondřej Budai
parent 9bb42459aa
commit 16c1768780
2 changed files with 26 additions and 36 deletions

View file

@ -87,10 +87,6 @@ def parse_arguments(sys_argv: List[str]) -> argparse.Namespace:
help="object to export, can be passed multiple times")
parser.add_argument("--json", action="store_true",
help="output results in JSON format")
parser.add_argument("--json-mode", metavar="MODE", type=str, default="batch",
help=("output mode for JSON format; "
"'batch' (default if unspecified) mode prints all the results when the build ends "
"'jsonseq' prints status updates while building with each line being a JSON object"))
parser.add_argument("--output-directory", metavar="DIRECTORY", type=os.path.abspath,
help="directory where result objects are stored")
parser.add_argument("--inspect", action="store_true",
@ -167,19 +163,8 @@ def osbuild_cli() -> int:
monitor_name = args.monitor
if not monitor_name:
monitor_name = "NullMonitor" if args.json else "LogMonitor"
outfd = sys.stdout.fileno()
if args.json:
if args.json_mode == "jsonseq":
monitor = osbuild.monitor.JSONSeqMonitor(outfd, manifest)
monitor.log("start", origin="org.osbuild.main")
elif args.json_mode == "batch":
monitor = osbuild.monitor.NullMonitor(outfd)
else:
print(f"unknown json mode {args.json_mode}")
return 1
else:
monitor = osbuild.monitor.make(monitor_name, args.monitor_fd)
monitor = osbuild.monitor.make(monitor_name, args.monitor_fd, manifest)
monitor.log(f"starting {args.manifest_path}", origin="org.osbuild.main")
try:
with ObjectStore(args.store) as object_store:
@ -207,10 +192,9 @@ def osbuild_cli() -> int:
export(pid, output_directory, object_store, manifest)
if args.json:
if args.json_mode == "batch":
r = fmt.output(manifest, r, object_store)
json.dump(r, sys.stdout)
sys.stdout.write("\n")
r = fmt.output(manifest, r, object_store)
json.dump(r, sys.stdout)
sys.stdout.write("\n")
else:
if r["success"]:
for name, pl in manifest.pipelines.items():