diff options
author | Patrick Williams <patrick@stwcx.xyz> | 2015-09-15 22:41:29 +0300 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2015-09-15 22:41:29 +0300 |
commit | 21f9b84b4b729fbd7acbd465e7a3f726e4d20f91 (patch) | |
tree | eb2d091d427ca0813b445509d59cc8e27e8ad25f /yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py | |
parent | 101cef31e2bf54c678501155cd2106251acbd076 (diff) | |
parent | c124f4f2e04dca16a428a76c89677328bc7bf908 (diff) | |
download | openbmc-21f9b84b4b729fbd7acbd465e7a3f726e4d20f91.tar.xz |
Merge commit 'c124f4f2e04dca16a428a76c89677328bc7bf908' as 'yocto-poky'
Diffstat (limited to 'yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py')
-rw-r--r-- | yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py new file mode 100644 index 000000000..343d3114c --- /dev/null +++ b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py @@ -0,0 +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(s)" + + def handle(self, buildId, *args, **options): + 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() + + # 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 + |