scripts: ensure tinfoil is shut down correctly

We should always shut down tinfoil when we're finished with it, either
by explicitly calling the shutdown() method or by using it as a
context manager ("with ...").

(From OE-Core rev: 5ec6d9ef309b841cdcbf1d14ac678d106d5d888a)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Eggleton 2015-08-05 15:48:00 +01:00 committed by Richard Purdie
parent f2854c67ce
commit e616beba1c
10 changed files with 414 additions and 385 deletions

View File

@ -159,7 +159,7 @@ def main():
options, args = parser.parse_args(sys.argv)
bbhandler = bb.tinfoil.Tinfoil()
with bb.tinfoil.Tinfoil() as bbhandler:
bbhandler.prepare()
print("Gathering recipe data...")
data_dict = get_recipesdata(bbhandler, options.preferred)

View File

@ -54,7 +54,7 @@ def verifyHomepage(bbhandler):
return count
if __name__=='__main__':
bbhandler = bb.tinfoil.Tinfoil()
with bb.tinfoil.Tinfoil() as bbhandler:
bbhandler.prepare()
logger.info("Start verifying HOMEPAGE:")
failcount = verifyHomepage(bbhandler)

View File

@ -289,17 +289,15 @@ def main():
if global_args.bbpath is None:
tinfoil = setup_tinfoil(config_only=True, basepath=basepath)
try:
global_args.bbpath = tinfoil.config_data.getVar('BBPATH', True)
else:
tinfoil = None
finally:
tinfoil.shutdown()
for path in [scripts_path] + global_args.bbpath.split(':'):
pluginpath = os.path.join(path, 'lib', 'devtool')
scriptutils.load_plugins(logger, plugins, pluginpath)
if tinfoil:
tinfoil.shutdown()
subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>')
subparsers.required = True

View File

@ -86,6 +86,7 @@ def build_image_task(config, basepath, workspace, image, add_packages=None, task
raise
tinfoil = setup_tinfoil(basepath=basepath)
try:
rd = parse_recipe(config, tinfoil, image, True)
if not rd:
# Error already shown
@ -135,7 +136,9 @@ def build_image_task(config, basepath, workspace, image, add_packages=None, task
else:
outputdir = rd.getVar('DEPLOY_DIR_IMAGE', True)
tinfoil.shutdown()
tmp_tinfoil = tinfoil
tinfoil = None
tmp_tinfoil.shutdown()
options = ''
if task:
@ -150,6 +153,9 @@ def build_image_task(config, basepath, workspace, image, add_packages=None, task
finally:
if os.path.isfile(appendfile):
os.unlink(appendfile)
finally:
if tinfoil:
tinfoil.shutdown()
return (0, outputdir)

View File

@ -154,6 +154,7 @@ def deploy(args, config, basepath, workspace):
destdir += '/'
tinfoil = setup_tinfoil(basepath=basepath)
try:
try:
rd = oe.recipeutils.parse_recipe_simple(tinfoil.cooker, args.recipename, tinfoil.config_data)
except Exception as e:
@ -232,6 +233,8 @@ def deploy(args, config, basepath, workspace):
for filename in files:
filename = os.path.relpath(os.path.join(root, filename), recipe_outdir)
files_list.append(os.path.join(destdir, filename))
finally:
tinfoil.shutdown()
return 0

View File

@ -30,8 +30,10 @@ def runqemu(args, config, basepath, workspace):
"""Entry point for the devtool 'runqemu' subcommand"""
tinfoil = setup_tinfoil(config_only=True, basepath=basepath)
try:
machine = tinfoil.config_data.getVar('MACHINE', True)
bindir_native = tinfoil.config_data.getVar('STAGING_BINDIR_NATIVE', True)
finally:
tinfoil.shutdown()
if not glob.glob(os.path.join(bindir_native, 'qemu-system-*')):

View File

@ -213,6 +213,7 @@ def add(args, config, basepath, workspace):
_add_md5(config, recipename, os.path.join(recipedir, fn))
tinfoil = setup_tinfoil(config_only=True, basepath=basepath)
try:
rd = oe.recipeutils.parse_recipe(tinfoil.cooker, recipefile, None)
if not rd:
return 1
@ -260,6 +261,7 @@ def add(args, config, basepath, workspace):
logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile)
finally:
tinfoil.shutdown()
return 0
@ -352,7 +354,7 @@ def extract(args, config, basepath, workspace):
if not tinfoil:
# Error already shown
return 1
try:
rd = parse_recipe(config, tinfoil, args.recipename, True)
if not rd:
return 1
@ -365,6 +367,8 @@ def extract(args, config, basepath, workspace):
return 0
else:
return 1
finally:
tinfoil.shutdown()
def sync(args, config, basepath, workspace):
"""Entry point for the devtool 'sync' subcommand"""
@ -374,7 +378,7 @@ def sync(args, config, basepath, workspace):
if not tinfoil:
# Error already shown
return 1
try:
rd = parse_recipe(config, tinfoil, args.recipename, True)
if not rd:
return 1
@ -387,6 +391,8 @@ def sync(args, config, basepath, workspace):
return 0
else:
return 1
finally:
tinfoil.shutdown()
class BbTaskExecutor(object):
"""Class for executing bitbake tasks for a recipe
@ -715,6 +721,7 @@ def modify(args, config, basepath, workspace):
args.recipename)
tinfoil = setup_tinfoil(basepath=basepath)
try:
rd = parse_recipe(config, tinfoil, args.recipename, True)
if not rd:
return 1
@ -817,6 +824,7 @@ def modify(args, config, basepath, workspace):
logger.info('Recipe %s now set up to build from %s' % (pn, srctree))
finally:
tinfoil.shutdown()
return 0
@ -1290,6 +1298,7 @@ def update_recipe(args, config, basepath, workspace):
'destination layer "%s"' % args.append)
tinfoil = setup_tinfoil(basepath=basepath, tracking=True)
try:
rd = parse_recipe(config, tinfoil, args.recipename, True)
if not rd:
@ -1301,6 +1310,8 @@ def update_recipe(args, config, basepath, workspace):
rf = rd.getVar('FILE', True)
if rf.startswith(config.workspace_path):
logger.warn('Recipe file %s has been updated but is inside the workspace - you will need to move it (and any associated files next to it) out to the desired layer before using "devtool reset" in order to keep any changes' % rf)
finally:
tinfoil.shutdown()
return 0

View File

@ -336,6 +336,7 @@ def upgrade(args, config, basepath, workspace):
raise DevtoolError("If you specify --srcbranch/-B then you must use --srcrev/-S to specify the revision" % args.recipename)
tinfoil = setup_tinfoil(basepath=basepath, tracking=True)
try:
rd = parse_recipe(config, tinfoil, args.recipename, True)
if not rd:
return 1
@ -378,6 +379,8 @@ def upgrade(args, config, basepath, workspace):
standard._add_md5(config, pn, af)
logger.info('Upgraded source extracted to %s' % srctree)
logger.info('New recipe is %s' % rf)
finally:
tinfoil.shutdown()
return 0
def register_commands(subparsers, context):

View File

@ -569,7 +569,10 @@ def main():
sys.exit(1)
logger.debug('Found bitbake path: %s' % bitbakepath)
tinfoil = tinfoil_init()
try:
args.pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR', True)
finally:
tinfoil.shutdown()
logger.debug('Value of PKGDATA_DIR is "%s"' % args.pkgdata_dir)
if not args.pkgdata_dir:
logger.error('Unable to determine pkgdata directory from PKGDATA_DIR')

View File

@ -77,6 +77,7 @@ def main():
scriptutils.logger_setup_color(logger, global_args.color)
tinfoil = tinfoil_init(False)
try:
for path in ([scripts_path] +
tinfoil.config_data.getVar('BBPATH', True).split(':')):
pluginpath = os.path.join(path, 'lib', 'recipetool')
@ -108,6 +109,8 @@ def main():
ret = args.func(args)
except bb.BBHandledException:
ret = 1
finally:
tinfoil.shutdown()
return ret