diff --git a/osbuild/main_cli.py b/osbuild/main_cli.py index 75cd968c..1800d69f 100644 --- a/osbuild/main_cli.py +++ b/osbuild/main_cli.py @@ -14,6 +14,7 @@ import sys import osbuild import osbuild.meta import osbuild.monitor +from osbuild.objectstore import ObjectStore from osbuild.formats import v1 as fmt @@ -114,12 +115,13 @@ def osbuild_cli(): monitor = osbuild.monitor.make(monitor_name, sys.stdout.fileno()) try: - r = manifest.build( - args.store, - monitor, - args.libdir, - output_directory=args.output_directory - ) + with ObjectStore(args.store) as object_store: + r = manifest.build( + object_store, + monitor, + args.libdir, + output_directory=args.output_directory + ) except KeyboardInterrupt: print() print(f"{RESET}{BOLD}{RED}Aborted{RESET}") diff --git a/osbuild/pipeline.py b/osbuild/pipeline.py index 39914084..e7026cc7 100644 --- a/osbuild/pipeline.py +++ b/osbuild/pipeline.py @@ -294,34 +294,33 @@ class Pipeline: monitor.begin(self) - with objectstore.ObjectStore(store) as object_store: - # If the final result is already in the store, no need to attempt - # building it. Just fetch the cached information. If the associated - # tree exists, we return it as well, but we do not care if it is - # missing, since it is not a mandatory part of the result and would - # usually be needless overhead. - obj = object_store.get(self.output_id) + # If the final result is already in the store, no need to attempt + # building it. Just fetch the cached information. If the associated + # tree exists, we return it as well, but we do not care if it is + # missing, since it is not a mandatory part of the result and would + # usually be needless overhead. + obj = store.get(self.output_id) - if not obj: - results, build_tree, tree = self.build_stages(object_store, - monitor, - libdir) + if not obj: + results, build_tree, tree = self.build_stages(store, + monitor, + libdir) - if not results["success"]: - return results + if not results["success"]: + return results - r, obj = self.assemble(object_store, - build_tree, - tree, - monitor, - libdir) + r, obj = self.assemble(store, + build_tree, + tree, + monitor, + libdir) - results.update(r) # This will also update 'success' + results.update(r) # This will also update 'success' - if obj: - if output_directory: - obj.export(output_directory) - obj.cleanup() + if obj: + if output_directory: + obj.export(output_directory) + obj.cleanup() monitor.finish(results) diff --git a/test/mod/test_monitor.py b/test/mod/test_monitor.py index d0eac1cb..82593ad1 100644 --- a/test/mod/test_monitor.py +++ b/test/mod/test_monitor.py @@ -12,6 +12,7 @@ from collections import defaultdict import osbuild import osbuild.meta from osbuild.monitor import LogMonitor +from osbuild.objectstore import ObjectStore from osbuild.pipeline import detect_host_runner from .. import test @@ -67,9 +68,9 @@ class TestMonitor(unittest.TestCase): logfile = os.path.join(tmpdir, "log.txt") - with open(logfile, "w") as log: + with open(logfile, "w") as log, ObjectStore(storedir) as store: monitor = LogMonitor(log.fileno()) - res = pipeline.run(storedir, + res = pipeline.run(store, monitor, libdir=os.path.abspath(os.curdir), output_directory=outputdir) @@ -100,10 +101,11 @@ class TestMonitor(unittest.TestCase): outputdir = os.path.join(tmpdir, "output") tape = TapeMonitor() - res = pipeline.run(storedir, - tape, - libdir=os.path.abspath(os.curdir), - output_directory=outputdir) + with ObjectStore(storedir) as store: + res = pipeline.run(store, + tape, + libdir=os.path.abspath(os.curdir), + output_directory=outputdir) assert res self.assertEqual(tape.counter["begin"], 1)