]> code.ossystems Code Review - openembedded-core.git/commitdiff
devtool: ensure we change back to the original dir on error
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Wed, 14 Oct 2015 20:15:33 +0000 (21:15 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 1 Dec 2015 21:30:54 +0000 (21:30 +0000)
This is just belt-and-braces but we ought to use try..finally in this
kind of situation, so just do it.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
scripts/lib/devtool/__init__.py

index 50604e6e0dabb1662ff36bbda7fe39a9e171f677..e617d604052ef5de474472512fb96543d55506c8 100644 (file)
@@ -100,18 +100,20 @@ def setup_tinfoil(config_only=False, basepath=None, tracking=False):
     """Initialize tinfoil api from bitbake"""
     import scriptpath
     orig_cwd = os.path.abspath(os.curdir)
-    if basepath:
-        os.chdir(basepath)
-    bitbakepath = scriptpath.add_bitbake_lib_path()
-    if not bitbakepath:
-        logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
-        sys.exit(1)
-
-    import bb.tinfoil
-    tinfoil = bb.tinfoil.Tinfoil(tracking=tracking)
-    tinfoil.prepare(config_only)
-    tinfoil.logger.setLevel(logger.getEffectiveLevel())
-    os.chdir(orig_cwd)
+    try:
+        if basepath:
+            os.chdir(basepath)
+        bitbakepath = scriptpath.add_bitbake_lib_path()
+        if not bitbakepath:
+            logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
+            sys.exit(1)
+
+        import bb.tinfoil
+        tinfoil = bb.tinfoil.Tinfoil(tracking=tracking)
+        tinfoil.prepare(config_only)
+        tinfoil.logger.setLevel(logger.getEffectiveLevel())
+    finally:
+        os.chdir(orig_cwd)
     return tinfoil
 
 def get_recipe_file(cooker, pn):