[bitbake-devel] [PATCH 14/23] toaster: delete multiple builds

Alex DAMIAN alexandru.damian at intel.com
Thu Jun 25 10:33:51 UTC 2015


From: Alexandru DAMIAN <alexandru.damian at intel.com>

This patch fixes the build deletion on unmigrated databases,
and enhances it to delete multiple builds in a single run.

[YOCTO #7726]

Signed-off-by: Alexandru DAMIAN <alexandru.damian at intel.com>
---
 lib/toaster/toastergui/views.py                    |  4 +-
 .../toastermain/management/commands/builddelete.py | 56 ++++++++++++++--------
 2 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 1a504b8..ec65903 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -64,9 +64,9 @@ def _get_latest_builds(prj=None):
     if prj is not None:
         queryset = queryset.filter(project = prj)
 
-    return itertools.chain(
+    return list(itertools.chain(
         queryset.filter(outcome=Build.IN_PROGRESS).order_by("-pk"),
-        queryset.filter(outcome__lt=Build.IN_PROGRESS).order_by("-pk")[:3] )
+        queryset.filter(outcome__lt=Build.IN_PROGRESS).order_by("-pk")[:3] ))
 
 
 # a JSON-able dict of recent builds; for use in the Project page, xhr_ updates,  and other places, as needed
diff --git a/lib/toaster/toastermain/management/commands/builddelete.py b/lib/toaster/toastermain/management/commands/builddelete.py
index 5cec436..343d311 100644
--- a/lib/toaster/toastermain/management/commands/builddelete.py
+++ b/lib/toaster/toastermain/management/commands/builddelete.py
@@ -1,33 +1,49 @@
 from django.core.management.base import BaseCommand, CommandError
 from orm.models import Build
+from django.db import OperationalError
 import os
 
 
 
 class Command(BaseCommand):
     args    = "buildId"
-    help    = "Deletes selected build"
+    help    = "Deletes selected build(s)"
 
     def handle(self, buildId, *args, **options):
-        b = Build.objects.get(pk = buildId)
-        # theoretically, just b.delete() would suffice
-        # however SQLite runs into problems when you try to
-        # delete too many rows at once, so we delete some direct
-        # relationships from Build manually.
+        for bid in buildId.split(","):
+            b = Build.objects.get(pk = bid)
+            # theoretically, just b.delete() would suffice
+            # however SQLite runs into problems when you try to
+            # delete too many rows at once, so we delete some direct
+            # relationships from Build manually.
+            for t in b.target_set.all():
+                t.delete()
+            for t in b.task_build.all():
+                t.delete()
+            for p in b.package_set.all():
+                p.delete()
+            for lv in b.layer_version_build.all():
+                lv.delete()
+            for v in b.variable_build.all():
+                v.delete()
+            for l in b.logmessage_set.all():
+                l.delete()
 
-        for t in b.target_set.all():
-            t.delete()
-        for t in b.task_build.all():
-            t.delete()
-        for p in b.package_set.all():
-            p.delete()
-        for lv in b.layer_version_build.all():
-            lv.delete()
-        for v in b.variable_build.all():
-            v.delete()
-        for l in b.logmessage_set.all():
-            l.delete()
+            # delete the build; some databases might have had problem with migration of the bldcontrol app
+            retry_count = 0
+            need_bldcontrol_migration = False
+            while True:
+                if retry_count >= 5:
+                    break
+                retry_count += 1
+                if need_bldcontrol_migration:
+                    from django.core import management
+                    management.call_command('migrate', 'bldcontrol', interactive=False)
 
-        # this should take care of the rest
-        b.delete()
+                try:
+                    b.delete()
+                    break
+                except OperationalError as e:
+                    # execute migrations
+                    need_bldcontrol_migration = True
 
-- 
1.9.1




More information about the bitbake-devel mailing list