rrs/tools: Upgrade to use transaction.atomic() in Django 1.6

Django 1.6 provides a context manager for atomic transactions so
update the way for make db transactions.

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
This commit is contained in:
Aníbal Limón 2017-01-05 15:37:15 -06:00
parent cb6f6b50d0
commit 9001631a2e
5 changed files with 148 additions and 170 deletions

View File

@ -94,9 +94,7 @@ if __name__=="__main__":
logger.debug("Starting recipe distros update ...") logger.debug("Starting recipe distros update ...")
transaction.enter_transaction_management() with transaction.atomic():
transaction.managed(True)
for layerbranch in LayerBranch.objects.all(): for layerbranch in LayerBranch.objects.all():
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath, (tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
fetchdir, settings, logger) fetchdir, settings, logger)
@ -130,6 +128,3 @@ 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))
transaction.commit()
transaction.leave_transaction_management()

View File

@ -90,8 +90,7 @@ def maintainer_history(logger):
commits = utils.runcmd("git log --format='%H' --reverse --date=rfc " + commits = utils.runcmd("git log --format='%H' --reverse --date=rfc " +
MAINTAINERS_INCLUDE_PATH, pokypath, logger=logger) MAINTAINERS_INCLUDE_PATH, pokypath, logger=logger)
transaction.enter_transaction_management() with transaction.atomic():
transaction.managed(True)
for commit in commits.strip().split("\n"): for commit in commits.strip().split("\n"):
if RecipeMaintainerHistory.objects.filter(sha1=commit): if RecipeMaintainerHistory.objects.filter(sha1=commit):
continue continue
@ -161,9 +160,6 @@ def maintainer_history(logger):
logger.debug("%s: New recipe not found maintainer set to 'No maintainer'." % \ logger.debug("%s: New recipe not found maintainer set to 'No maintainer'." % \
(recipe.pn)) (recipe.pn))
transaction.commit()
transaction.leave_transaction_management()
if __name__=="__main__": if __name__=="__main__":
parser = optparse.OptionParser(usage = """%prog [options]""") parser = optparse.OptionParser(usage = """%prog [options]""")

View File

@ -46,11 +46,9 @@ if __name__=="__main__":
logger.info('Starting unique recipes ...') logger.info('Starting unique recipes ...')
transaction.enter_transaction_management()
transaction.managed(True)
# only keep the major version of recipe # only keep the major version of recipe
logger.info('Starting remove of duplicate recipes only keep major version ...') logger.info('Starting remove of duplicate recipes only keep major version ...')
with transaction.atomic():
for layerbranch in LayerBranch.objects.all(): for layerbranch in LayerBranch.objects.all():
recipes = {} recipes = {}
@ -82,7 +80,3 @@ if __name__=="__main__":
logger.debug("%s: Removed older recipe (%s), current recipe (%s)." \ logger.debug("%s: Removed older recipe (%s), current recipe (%s)." \
% (recipes[pn].pn, recipe.pv, recipes[pn].pv)) % (recipes[pn].pn, recipe.pv, recipes[pn].pv))
recipe.delete() recipe.delete()
transaction.commit()
transaction.leave_transaction_management()

View File

@ -157,6 +157,7 @@ def do_initial(layerbranch, ct, logger):
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath, (tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
fetchdir, settings, logger, nocheckout=True) fetchdir, settings, logger, nocheckout=True)
with transaction.atomic():
for recipe_data in recipes: for recipe_data in recipes:
_create_upgrade(recipe_data, layerbranch, '', title, _create_upgrade(recipe_data, layerbranch, '', title,
info, logger, initial=True) info, logger, initial=True)
@ -188,6 +189,7 @@ def do_loop(layerbranch, ct, logger):
repodir, logger=logger) repodir, logger=logger)
info = utils.runcmd("git log --format='%an;%ae;%ad;%cd' --date=rfc -n 1 " \ info = utils.runcmd("git log --format='%an;%ae;%ad;%cd' --date=rfc -n 1 " \
+ ct, destdir=repodir, logger=logger) + ct, destdir=repodir, logger=logger)
with transaction.atomic():
for recipe_data in recipes: for recipe_data in recipes:
_create_upgrade(recipe_data, layerbranch, ct, title, _create_upgrade(recipe_data, layerbranch, ct, title,
info, logger) info, logger)
@ -232,8 +234,6 @@ def upgrade_history(options, logger):
logger=logger) logger=logger)
commit_list = commits.split('\n') commit_list = commits.split('\n')
transaction.enter_transaction_management()
transaction.managed(True)
if options.initial: if options.initial:
logger.debug("Adding initial upgrade history ....") logger.debug("Adding initial upgrade history ....")
@ -255,9 +255,6 @@ def upgrade_history(options, logger):
p.start() p.start()
p.join() p.join()
transaction.commit()
transaction.leave_transaction_management()
if __name__=="__main__": if __name__=="__main__":
parser = optparse.OptionParser(usage = """%prog [options]""") parser = optparse.OptionParser(usage = """%prog [options]""")

View File

@ -146,8 +146,7 @@ if __name__=="__main__":
logger.debug("Starting upstream history...") logger.debug("Starting upstream history...")
transaction.enter_transaction_management() with transaction.atomic():
transaction.managed(True)
for layerbranch in LayerBranch.objects.all(): for layerbranch in LayerBranch.objects.all():
layer = layerbranch.layer layer = layerbranch.layer
urldir = layer.get_fetch_dir() urldir = layer.get_fetch_dir()
@ -195,6 +194,3 @@ if __name__=="__main__":
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)))
transaction.commit()
transaction.leave_transaction_management()