]> git.ozlabs.org Git - patchwork/blob - patchwork/management/commands/retag.py
management: Resolve a bug with 'retag' command
[patchwork] / patchwork / management / commands / retag.py
1
2 from django.core.management.base import BaseCommand, CommandError
3 from patchwork.models import Patch
4 import sys
5
6 class Command(BaseCommand):
7     help = 'Update the tag (Ack/Review/Test) counts on existing patches'
8     args = '[<patch_id>...]'
9
10     def handle(self, *args, **options):
11
12         qs = Patch.objects
13
14         if args:
15             qs = qs.filter(id__in=args)
16         else:
17             qs = qs.all()
18
19         count = qs.count()
20         i = 0
21
22         for patch in qs.iterator():
23             patch.refresh_tag_counts()
24             i += 1
25             if (i % 10) == 0 or i == count:
26                 sys.stdout.write('%06d/%06d\r' % (i, count))
27                 sys.stdout.flush()
28         sys.stderr.write('\ndone\n')