[migration] Refactor migration script (use more RQL)
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Wed, 26 Feb 2014 15:42:03 +0100
changeset 1463 ff9dde49d178
parent 1462 fe052ee9a5a7
child 1464 15bd430d1de0
[migration] Refactor migration script (use more RQL)
migration/3.0.0_Any.py
--- a/migration/3.0.0_Any.py	Fri Apr 25 14:21:23 2014 +0200
+++ b/migration/3.0.0_Any.py	Wed Feb 26 15:42:03 2014 +0100
@@ -29,9 +29,9 @@
 
 from cubes.apycot import recipes
 r_script_names = {
-        u'apycot.recipe.quick': 'quick_script',
-        u'apycot.recipe.full': 'full_script',
-        u'apycot.recipe.scenario_runner': 'scenario_runner_script'
+        u'apycot.recipe.quick': recipes.quick_script,
+        u'apycot.recipe.full': recipes.full_script,
+        u'apycot.recipe.scenario_runner': recipes.scenario_runner_script,
         }
 
 warning_msg = """
@@ -42,17 +42,11 @@
 
 for r_name in r_script_names:
     ## update script in recipe
-    r_entity = rql('Any X WHERE X is Recipe, X name %(r_name)s,'
-                   'X script "#to be updated"',
-                   {'r_name': r_name})
-    if len(r_entity) > 0:
-        r_entity = r_entity.get_entity(0, 0)
-        r_entity.set_attributes(script=getattr(recipes, r_script_names[r_name]))
+    rql('SET X script %(script)s WHERE X is Recipe, X script "#to be updated", '
+        'X name %(name)s',
+        {'script': r_script_names[r_name],
+         'name': r_name})
     ## update script for existing TestExecution and Chekresults
-    r_set = rql('Any X WHERE X execution_of Y, Y name %(r_name)s',
-            {'r_name': r_name})
-    for e in r_set.entities():
-        if e.script is None:
-            e.set_attributes(script=warning_msg + getattr(recipes,
-                                         r_script_names[r_name]))
-
+    rql('SET X script %(script)s WHERE X execution_of Y, Y name %(name)s',
+        {'script': warning_msg + r_script_names[r_name],
+         'name': r_name})