debian-forge/osbuild/__main__.py
Lars Karlitski 83475cc9f4 osbuild: store outputs in objectstore
Treat outputs like we treat trees: store them in the object store. This
simplifies using osbuild and allows returning a cached version if one is
available.

This makes the `--output` parameter redundant. Remove it.
2019-09-25 23:50:50 +02:00

60 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")
parser.add_argument("--build-pipeline", metavar="PIPELINE", type=os.path.abspath,
help="json file containing the pipeline to create a 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()
with open(args.pipeline_path) as f:
pipeline = osbuild.load(json.load(f))
if args.build_pipeline:
with open(args.build_pipeline) as f:
build = osbuild.load(json.load(f))
pipeline.prepend_build_pipeline(build)
try:
pipeline.run(args.store, interactive=not args.json, libdir=args.libdir)
except KeyboardInterrupt:
print()
print(f"{RESET}{BOLD}{RED}Aborted{RESET}")
return 130
except (osbuild.StageFailed, osbuild.AssemblerFailed) as error:
print()
print(f"{RESET}{BOLD}{RED}{error.name} failed with code {error.returncode}{RESET}")
if args.json:
print(error.output)
return 1
if args.json:
json.dump({
"tree_id": pipeline.tree_id,
"output_id": pipeline.output_id,
}, sys.stdout)
sys.stdout.write("\n")
return 0
if __name__ == "__main__":
sys.exit(main())