aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2015-06-11 16:09:04 +0100
committerMichael Wood <michael.g.wood@intel.com>2015-06-11 16:11:36 +0100
commit8333af184aae3ce3211bfd4ee43ce525302ff31a (patch)
tree9a870eb5bbe121f79bd78ae6e3b5e6dd210eb6e2
parent69ee069a6a49d4ed9a37d22fdb7600d7f1555be2 (diff)
downloaderror-report-web-8333af184aae3ce3211bfd4ee43ce525302ff31a.tar.gz
error-report-web-8333af184aae3ce3211bfd4ee43ce525302ff31a.tar.bz2
error-report-web-8333af184aae3ce3211bfd4ee43ce525302ff31a.zip
management: Add command to cull the database
Adds a cron-able command to reduce the size of the database to a specified size. [YOCTO #6874] Signed-off-by: Michael Wood <michael.g.wood@intel.com>
-rw-r--r--Post/management/__init__.py0
-rw-r--r--Post/management/commands/__init__.py0
-rw-r--r--Post/management/commands/culldb.py53
3 files changed, 53 insertions, 0 deletions
diff --git a/Post/management/__init__.py b/Post/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Post/management/__init__.py
diff --git a/Post/management/commands/__init__.py b/Post/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Post/management/commands/__init__.py
diff --git a/Post/management/commands/culldb.py b/Post/management/commands/culldb.py
new file mode 100644
index 0000000..698537c
--- /dev/null
+++ b/Post/management/commands/culldb.py
@@ -0,0 +1,53 @@
+# error-reporting-tool - culldb
+#
+# Copyright (C) 2015 Intel Corporation
+#
+# Licensed under the MIT license, see COPYING.MIT for details
+
+# Create your views here.
+# vi: tabstop=8 expandtab shiftwidth=4 softtabstop=4
+
+from django.core.management.base import BaseCommand, CommandError
+from Post.models import Build, BuildFailure
+from optparse import make_option
+import time
+import sys
+
+class Command(BaseCommand):
+ help = 'Culls the database to size in rows'
+ args = '<size>'
+ option_list = BaseCommand.option_list + (
+ make_option('-i',
+ '--info',
+ dest='info',
+ action="store_true",
+ help='Show the current database size'),
+ )
+
+ def handle(self, *args, **options):
+ count = Build.objects.count()
+
+ if options['info']:
+ print "Current builds table size: %d" % Build.objects.count()
+ return
+
+ if len(args) > 0 and args[0]:
+ try:
+ new_size = int(args[0])
+ except ValueError:
+ print "Not a valid size"
+ return
+
+
+ num_to_delete = count - new_size
+ print "\nReducing the database size to %d which will DELETE %d rows" % (new_size, num_to_delete)
+ i = 1
+ while i != 0:
+ i = i-1
+ print 'Ctrl+c TO CANCEL. Executing in... %d \r' % i,
+ sys.stdout.flush()
+ time.sleep(1)
+
+ q = Build.objects.all()[:num_to_delete].values_list('pk',
+ flat=True)
+ Build.objects.filter(pk__in=list(q)).delete()