From: Paul Eggleton Date: Wed, 5 Aug 2015 14:12:14 +0000 (+0100) Subject: tinfoil: add context manager functions X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f59bc6be2b4af1acdcf6a1b184956b5ffd297743;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git tinfoil: add context manager functions 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 --- diff --git a/lib/bb/tinfoil.py b/lib/bb/tinfoil.py index 95608ae3bd4..441be2c6158 100644 --- a/lib/bb/tinfoil.py +++ b/lib/bb/tinfoil.py @@ -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)