rrs/tools: handle dry-run properly

In the case of dry-run a couple of the scripts were breaking out after
one layerbranch had been processed due to the code structure. Handle the
exception within the block for the layerbranch to avoid this.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-09-04 15:28:39 +12:00
parent 0201a86f0d
commit 9d0e048ded
2 changed files with 61 additions and 60 deletions

View File

@ -112,19 +112,19 @@ if __name__=="__main__":
logger.debug("Starting recipe distros update ...") logger.debug("Starting recipe distros update ...")
try: origsyspath = sys.path
origsyspath = sys.path for maintplan in maintplans:
with transaction.atomic(): for item in maintplan.maintenanceplanlayerbranch_set.all():
for maintplan in maintplans: layerbranch = item.layerbranch
for item in maintplan.maintenanceplanlayerbranch_set.all(): sys.path = origsyspath
layerbranch = item.layerbranch (tinfoil, d, recipes, tempdir) = load_recipes(layerbranch, bitbakepath,
sys.path = origsyspath fetchdir, settings, logger)
(tinfoil, d, recipes, tempdir) = load_recipes(layerbranch, bitbakepath, try:
fetchdir, settings, logger) if not recipes:
try: continue
if not recipes:
continue
try:
with transaction.atomic():
utils.setup_core_layer_sys_path(settings, layerbranch.branch.name) utils.setup_core_layer_sys_path(settings, layerbranch.branch.name)
from oe import distro_check from oe import distro_check
@ -153,10 +153,10 @@ if __name__=="__main__":
recipedistro.save() recipedistro.save()
logger.debug('%s: layer branch %s, add distro %s alias %s' % (pn, logger.debug('%s: layer branch %s, add distro %s alias %s' % (pn,
str(layerbranch), distro, alias)) str(layerbranch), distro, alias))
finally: if options.dry_run:
tinfoil.shutdown() raise DryRunRollbackException
shutil.rmtree(tempdir) except DryRunRollbackException:
if options.dry_run: pass
raise DryRunRollbackException finally:
except DryRunRollbackException: tinfoil.shutdown()
pass shutil.rmtree(tempdir)

View File

@ -178,59 +178,60 @@ if __name__=="__main__":
for maintplan in maintplans: for maintplan in maintplans:
for item in maintplan.maintenanceplanlayerbranch_set.all(): for item in maintplan.maintenanceplanlayerbranch_set.all():
layerbranch = item.layerbranch layerbranch = item.layerbranch
with transaction.atomic(): try:
sys.path = origsyspath with transaction.atomic():
sys.path = origsyspath
layer = layerbranch.layer layer = layerbranch.layer
urldir = layer.get_fetch_dir() urldir = layer.get_fetch_dir()
repodir = os.path.join(fetchdir, urldir) repodir = os.path.join(fetchdir, urldir)
layerdir = os.path.join(repodir, layerbranch.vcs_subdir) layerdir = os.path.join(repodir, layerbranch.vcs_subdir)
recipe_files = [] recipe_files = []
for recipe in layerbranch.recipe_set.all(): for recipe in layerbranch.recipe_set.all():
file = str(os.path.join(layerdir, recipe.full_path())) file = str(os.path.join(layerdir, recipe.full_path()))
recipe_files.append(file) recipe_files.append(file)
(tinfoil, d, recipes, tempdir) = load_recipes(layerbranch, bitbakepath, (tinfoil, d, recipes, tempdir) = load_recipes(layerbranch, bitbakepath,
fetchdir, settings, logger, recipe_files=recipe_files) fetchdir, settings, logger, recipe_files=recipe_files)
try: try:
if not recipes: if not recipes:
continue continue
utils.setup_core_layer_sys_path(settings, layerbranch.branch.name) utils.setup_core_layer_sys_path(settings, layerbranch.branch.name)
for recipe_data in recipes: for recipe_data in recipes:
set_regexes(recipe_data) set_regexes(recipe_data)
history = RecipeUpstreamHistory(layerbranch=layerbranch, start_date=datetime.now()) history = RecipeUpstreamHistory(layerbranch=layerbranch, start_date=datetime.now())
result = [] result = []
for recipe_data in recipes: for recipe_data in recipes:
try: try:
get_upstream_info(layerbranch, recipe_data, result) get_upstream_info(layerbranch, recipe_data, result)
except: except:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
history.end_date = datetime.now() history.end_date = datetime.now()
history.save() history.save()
for res in result: for res in result:
(recipe, ru) = res (recipe, ru) = res
ru.history = history ru.history = history
ru.save() ru.save()
logger.debug('%s: layer branch %s, pv %s, upstream (%s)' % (recipe.pn, logger.debug('%s: layer branch %s, pv %s, upstream (%s)' % (recipe.pn,
str(layerbranch), recipe.pv, str(ru))) str(layerbranch), recipe.pv, str(ru)))
finally: finally:
tinfoil.shutdown() tinfoil.shutdown()
shutil.rmtree(tempdir) shutil.rmtree(tempdir)
if options.dry_run: if options.dry_run:
raise DryRunRollbackException raise DryRunRollbackException
except DryRunRollbackException: except DryRunRollbackException:
pass pass
finally: finally:
utils.unlock_file(lockfile) utils.unlock_file(lockfile)