]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
tinfoil: add context manager functions
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Wed, 5 Aug 2015 14:12:14 +0000 (15:12 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 2 Sep 2016 15:29:36 +0000 (16:29 +0100)
Since calling the shutdown() function is highly recommended, make
tinfoil objects a little easier to deal with by adding context manager
support - so you can do the following:

    with bb.tinfoil.Tinfoil() as tinfoil:
        tinfoil.prepare(True)
        ...

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
lib/bb/tinfoil.py

index 95608ae3bd4474fa5e6f38bb81de1a44f1613f5b..441be2c6158eb7f4a4c204b7fe47b25a1ed0fdd3 100644 (file)
@@ -59,6 +59,12 @@ class Tinfoil:
     def register_idle_function(self, function, data):
         pass
 
+    def __enter__(self):
+        return self
+
+    def __exit__(self, type, value, traceback):
+        self.shutdown()
+
     def parseRecipes(self):
         sys.stderr.write("Parsing recipes..")
         self.logger.setLevel(logging.WARNING)