Files
poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py
brian avery 013c030c42 bitbake: toaster: delete multiple builds cleanup
This patch cleans up the multiple delete. It:

1) skips build id's that don't exist rather than giving a traceback.
2) let you pass in the ids as a space separated list
3) fixes the usage to match the space separated list format

[YOCTO #7726]

(Bitbake rev: a065f7e5e9c07dbd71a98e7db1d7f711607716f3)

Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2015-09-18 09:05:32 +01:00

55 lines
1.9 KiB
Python

from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import ObjectDoesNotExist
from orm.models import Build
from django.db import OperationalError
import os
class Command(BaseCommand):
args = '<buildID1 buildID2 .....>'
help = "Deletes selected build(s)"
def handle(self, *args, **options):
for bid in args:
try:
b = Build.objects.get(pk = bid)
except ObjectDoesNotExist:
print 'build %s does not exist, skipping...' %(bid)
continue
# 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()
# 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)
try:
b.delete()
break
except OperationalError as e:
# execute migrations
need_bldcontrol_migration = True