From: Stephen Finucane Date: Tue, 24 Nov 2015 04:04:43 +0000 (+0000) Subject: management: Create 'rehash' command X-Git-Tag: v1.1.0~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16815aea6d14e4354e915455fa104256866984ee;p=thirdparty%2Fpatchwork.git management: Create 'rehash' command 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 --- diff --git a/patchwork/management/commands/cron.py b/patchwork/management/commands/cron.py old mode 100755 new mode 100644 diff --git a/patchwork/bin/rehash.py b/patchwork/management/commands/rehash.py old mode 100755 new mode 100644 similarity index 56% rename from patchwork/bin/rehash.py rename to patchwork/management/commands/rehash.py index c44e49ba..8d6da957 --- a/patchwork/bin/rehash.py +++ b/patchwork/management/commands/rehash.py @@ -2,6 +2,7 @@ # # Patchwork - automated patch tracking system # Copyright (C) 2008 Jeremy Kerr +# Copyright (C) 2015 Intel Corporation # # This file is part of the Patchwork package. # @@ -19,16 +20,29 @@ # 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 = '[...]' + + 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')