A pipeline run only returned logs in the `StageFailed` and `AssemblerFailed` exceptions. Remove those and always return structured data instead. It only returns data for stages that actually ran (i.e., didn't come from the cache). This is similar to the output in interactive mode. Also change osbuildtest to be able to deal with output that is larger than the pipe buffer by using subprocess.communicate().
62 lines
2 KiB
Python
Executable file
62 lines
2 KiB
Python
Executable file
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
import osbuild
|
|
|
|
|
|
RESET = "\033[0m"
|
|
BOLD = "\033[1m"
|
|
RED = "\033[31m"
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Build operating system images")
|
|
parser.add_argument("pipeline_path", metavar="PIPELINE",
|
|
help="json file containing the pipeline that should be built, or a '-' to read from stdin")
|
|
parser.add_argument("--build-env", metavar="ENV", type=os.path.abspath,
|
|
help="json file containing a description of the build environment")
|
|
parser.add_argument("--store", metavar="DIRECTORY", type=os.path.abspath,
|
|
default=".osbuild",
|
|
help="the directory where intermediary os trees are stored")
|
|
parser.add_argument("-l", "--libdir", metavar="DIRECTORY", type=os.path.abspath,
|
|
help="the directory containing stages, assemblers, and the osbuild library")
|
|
parser.add_argument("--json", action="store_true",
|
|
help="output results in JSON format")
|
|
args = parser.parse_args()
|
|
|
|
if args.pipeline_path == "-":
|
|
f = sys.stdin
|
|
else:
|
|
f = open(args.pipeline_path)
|
|
pipeline = osbuild.load(json.load(f))
|
|
f.close()
|
|
|
|
if args.build_env:
|
|
with open(args.build_env) as f:
|
|
build_pipeline, runner = osbuild.load_build(json.load(f))
|
|
pipeline.prepend_build_env(build_pipeline, runner)
|
|
|
|
try:
|
|
r = pipeline.run(args.store, interactive=not args.json, libdir=args.libdir)
|
|
except KeyboardInterrupt:
|
|
print()
|
|
print(f"{RESET}{BOLD}{RED}Aborted{RESET}")
|
|
return 130
|
|
|
|
if args.json:
|
|
json.dump(r, sys.stdout)
|
|
sys.stdout.write("\n")
|
|
else:
|
|
if r["success"]:
|
|
print("tree id:", pipeline.tree_id)
|
|
print("output id:", pipeline.output_id)
|
|
else:
|
|
print()
|
|
print(f"{RESET}{BOLD}{RED}Failed{RESET}")
|
|
|
|
return 0 if r["success"] else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|