Skip to contentSkip to conversation

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

PATCH New Aníbal Limón 1 participant 2 messages Jan 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 1/2] 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.

---
 rrs/tools/rrs_distros.py            |  67 ++++++++++-----------
 rrs/tools/rrs_maintainer_history.py | 114 +++++++++++++++++-------------------
 rrs/tools/rrs_unique_recipes.py     |  60 +++++++++----------
 rrs/tools/rrs_upgrade_history.py    |  19 +++---
 rrs/tools/rrs_upstream_history.py   |  74 +++++++++++------------
 5 files changed, 156 insertions(+), 178 deletions(-)
rrs/tools/rrs_distros.py +31 -36
index e0c2def..b28f38d 100755
@@ -94,42 +94,37 @@ if __name__=="__main__":
 
     logger.debug("Starting recipe distros update ...")
 
-    transaction.enter_transaction_management()
-    transaction.managed(True)
+    with transaction.atomic():
+        for layerbranch in LayerBranch.objects.all():
+            (tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
+                    fetchdir, settings, logger)
 
-    for layerbranch in LayerBranch.objects.all():
-        (tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
-                fetchdir, settings, logger)
-
-        if not recipes:
-            continue
-
-        from oe import distro_check
-        logger.debug("Downloading distro's package information ...")
-        distro_check.create_distro_packages_list(fetchdir, d)
-        pkglst_dir = os.path.join(fetchdir, "package_lists")
-
-        RecipeDistro.objects.filter(recipe__layerbranch = layerbranch).delete()
-
-        for recipe_data in recipes:
-            pn = recipe_data.getVar('PN', True)
-
-            try:
-                recipe = Recipe.objects.get(pn = pn, layerbranch = layerbranch)
-            except:
-                logger.warn('%s: layer branch %s, NOT found' % (pn,
-                    str(layerbranch)))
+            if not recipes:
                 continue
 
-            distro_info = search_package_in_distros(pkglst_dir, recipe, recipe_data)
-            for distro, alias in distro_info.items():
-                recipedistro = RecipeDistro()
-                recipedistro.recipe = recipe
-                recipedistro.distro = distro
-                recipedistro.alias = alias
-                recipedistro.save()
-                logger.debug('%s: layer branch %s, add distro %s alias %s' % (pn,
-                    str(layerbranch), distro, alias))
-
-    transaction.commit()
-    transaction.leave_transaction_management()
+            from oe import distro_check
+            logger.debug("Downloading distro's package information ...")
+            distro_check.create_distro_packages_list(fetchdir, d)
+            pkglst_dir = os.path.join(fetchdir, "package_lists")
+
+            RecipeDistro.objects.filter(recipe__layerbranch = layerbranch).delete()
+
+            for recipe_data in recipes:
+                pn = recipe_data.getVar('PN', True)
+
+                try:
+                    recipe = Recipe.objects.get(pn = pn, layerbranch = layerbranch)
+                except:
+                    logger.warn('%s: layer branch %s, NOT found' % (pn,
+                        str(layerbranch)))
+                    continue
+
+                distro_info = search_package_in_distros(pkglst_dir, recipe, recipe_data)
+                for distro, alias in distro_info.items():
+                    recipedistro = RecipeDistro()
+                    recipedistro.recipe = recipe
+                    recipedistro.distro = distro
+                    recipedistro.alias = alias
+                    recipedistro.save()
+                    logger.debug('%s: layer branch %s, add distro %s alias %s' % (pn,
+                        str(layerbranch), distro, alias))
rrs/tools/rrs_maintainer_history.py +55 -59

133 lines not on this page · raw message

rrs/tools/rrs_unique_recipes.py +27 -33

70 lines not on this page · raw message

rrs/tools/rrs_upgrade_history.py +8 -11
index 4d417c0..27655d8 100755
@@ -157,9 +157,10 @@ def do_initial(layerbranch, ct, logger):
     (tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
                             fetchdir, settings, logger, nocheckout=True)
 
-    for recipe_data in recipes:
-        _create_upgrade(recipe_data, layerbranch, '', title,
-                info, logger, initial=True)
+    with transaction.atomic():
+        for recipe_data in recipes:
+            _create_upgrade(recipe_data, layerbranch, '', title,
+                    info, logger, initial=True)
 
     utils.runcmd("git checkout master -f", repodir, logger=logger)
     utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
@@ -188,9 +189,10 @@ def do_loop(layerbranch, ct, logger):
                                     repodir, logger=logger)
     info = utils.runcmd("git log  --format='%an;%ae;%ad;%cd' --date=rfc -n 1 " \
                     + ct, destdir=repodir, logger=logger)
-    for recipe_data in recipes:
-        _create_upgrade(recipe_data, layerbranch, ct, title,
-                            info, logger)
+    with transaction.atomic():
+        for recipe_data in recipes:
+            _create_upgrade(recipe_data, layerbranch, ct, title,
+                                info, logger)
 
     utils.runcmd("git checkout master -f", repodir, logger=logger)
     utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
@@ -232,8 +234,6 @@ def upgrade_history(options, logger):
                                 logger=logger)
         commit_list = commits.split('\n')
 
-        transaction.enter_transaction_management()
-        transaction.managed(True)
         if options.initial:
             logger.debug("Adding initial upgrade history ....")
 
@@ -255,9 +255,6 @@ def upgrade_history(options, logger):
                 p.start()
                 p.join()
 
-        transaction.commit()
-        transaction.leave_transaction_management()
-
 if __name__=="__main__":
     parser = optparse.OptionParser(usage = """%prog [options]""")
     
rrs/tools/rrs_upstream_history.py +35 -39

90 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 2/2] rrs/tools: Upgrade to use new API of tinfoil

The new client/server API of tinfoil requires explicit call of shutdown method to send the event for finalize cooker process.

[YOCTO #10863]

---
 rrs/tools/common.py               | 6 +++++-
 rrs/tools/rrs_distros.py          | 3 +++
 rrs/tools/rrs_upgrade_history.py  | 2 ++
 rrs/tools/rrs_upstream_history.py | 3 +++
 4 files changed, 13 insertions(+), 1 deletion(-)
rrs/tools/common.py +5 -1
index d61b81f..9dca431 100644
@@ -119,7 +119,11 @@ def load_recipes(layerbranch, bitbakepath, fetchdir, settings, logger,
     recipes = []
     for rp in recipe_files:
         try:
-            data = tinfoil.cache.loadDataFull(rp, [])
+            if hasattr(tinfoil, 'parse_recipe_file'):
+                data = tinfoil.parse_recipe_file(fn, appends=False, config_data=d)
+            else:
+                data = bb.cache.Cache.loadDataFull(fn, [], d)
+
             try:
                 pv = data.getVar('PV', True)
             except FetchError:
rrs/tools/rrs_distros.py +3 -0
index b28f38d..60820f4 100755
@@ -100,6 +100,7 @@ if __name__=="__main__":
                     fetchdir, settings, logger)
 
             if not recipes:
+                tinfoil.shutdown()
                 continue
 
             from oe import distro_check
@@ -128,3 +129,5 @@ if __name__=="__main__":
                     recipedistro.save()
                     logger.debug('%s: layer branch %s, add distro %s alias %s' % (pn,
                         str(layerbranch), distro, alias))
+
+            tinfoil.shutdown()
rrs/tools/rrs_upgrade_history.py +2 -0
index 27655d8..436916f 100755
@@ -164,6 +164,7 @@ def do_initial(layerbranch, ct, logger):
 
     utils.runcmd("git checkout master -f", repodir, logger=logger)
     utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
+    tinfoil.shutdown()
 
 def do_loop(layerbranch, ct, logger):
     layer = layerbranch.layer
@@ -196,6 +197,7 @@ def do_loop(layerbranch, ct, logger):
 
     utils.runcmd("git checkout master -f", repodir, logger=logger)
     utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
+    tinfoil.shutdown()
 
 
 """
rrs/tools/rrs_upstream_history.py +3 -0
index dfb1604..09a246a 100755
@@ -162,6 +162,7 @@ if __name__=="__main__":
                     fetchdir, settings, logger,  recipe_files=recipe_files)
 
             if not recipes:
+                tinfoil.shutdown()
                 continue
 
             for recipe_data in recipes:
@@ -194,3 +195,5 @@ if __name__=="__main__":
 
                 logger.debug('%s: layer branch %s, pv %s, upstream (%s)' % (recipe.pn,
                     str(layerbranch), recipe.pv, str(ru)))
+
+            tinfoil.shutdown()
Signature · 1 line
2.1.4