#
# 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')