From a30b407474d4eb6620f1ec549b54187ebbaff008 Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Wed, 14 Oct 2015 21:15:33 +0100 Subject: devtool: ensure we change back to the original dir on error 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 Signed-off-by: Ross Burton --- scripts/lib/devtool/__init__.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'scripts/lib') diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py index 50604e6e0d..e617d60405 100644 --- a/scripts/lib/devtool/__init__.py +++ b/scripts/lib/devtool/__init__.py @@ -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): -- cgit v1.2.3