]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
management: Create 'rehash' command
authorStephen Finucane <stephen.finucane@intel.com>
Tue, 24 Nov 2015 04:04:43 +0000 (04:04 +0000)
committerStephen Finucane <stephen.finucane@intel.com>
Thu, 26 Nov 2015 19:28:37 +0000 (19:28 +0000)
The rehash script, though undocumented and possibly unused at the
moment, likely has some value to some users. Howver, it makes more
sense to provide this command as a management command like 'retag'.
Do this.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
patchwork/management/commands/cron.py [changed mode: 0755->0644]
patchwork/management/commands/rehash.py [moved from patchwork/bin/rehash.py with 56% similarity, mode: 0644]

old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
similarity index 56%
rename from patchwork/bin/rehash.py
rename to patchwork/management/commands/rehash.py
index c44e49b..8d6da95
@@ -2,6 +2,7 @@
 #
 # Patchwork - automated patch tracking system
 # Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
+# Copyright (C) 2015 Intel Corporation
 #
 # This file is part of the Patchwork package.
 #
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from django.core.management.base import BaseCommand
+
 from patchwork.models import Patch
-import sys
-
-if __name__ == '__main__':
-    if len(sys.argv) > 1:
-        patches = Patch.objects.filter(id__in = sys.argv[1:])
-    else:
-        patches = Patch.objects.all()
-
-    for patch in patches:
-        print patch.id, patch.name
-        patch.hash = None
-        patch.save()
+
+
+class Command(BaseCommand):
+    help = 'Update the hashes on existing patches'
+    args = '[<patch_id>...]'
+
+    def handle(self, *args, **options):
+        query = Patch.objects
+
+        if args:
+            query = query.filter(id_in=args)
+        else:
+            query = query.all()
+
+        count = query.count()
+
+        for i, patch in enumerate(query.iterator()):
+            patch.hash = None
+            patch.save()
+            if (i % 10) == 0:
+                self.stdout.write('%06d/%06d\r' % (i, count), ending='')
+                self.stdout.flush()
+        self.stdout.write('\ndone')