# Path: patchwork/models.py
# class Patch(models.Model):
#     project = models.ForeignKey(Project, on_delete=models.CASCADE)
#     msgid = models.CharField(max_length=255)
#     name = models.CharField(max_length=255)
#     date = models.DateTimeField(default=datetime.datetime.now)
#     last_updated = models.DateTimeField(auto_now=True)
#     submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
#     delegate = models.ForeignKey(User, blank=True, null=True,
#                                  on_delete=models.CASCADE)
#     state = models.ForeignKey(State, null=True, on_delete=models.CASCADE)
#     archived = models.BooleanField(default=False)
#     headers = models.TextField(blank=True)
#     content = models.TextField(null=True, blank=True)
#     pull_url = models.CharField(max_length=255, null=True, blank=True)
#     commit_ref = models.CharField(max_length=255, null=True, blank=True)
#     hash = HashField(null=True, blank=True)
#     tags = models.ManyToManyField(Tag, through=PatchTag)
# 
#     objects = PatchManager()
# 
#     def commit_message(self):
#         """Retrieves the commit message"""
#         return Comment.objects.filter(patch=self, msgid=self.msgid)
# 
#     def answers(self):
#         """Retrieves the answers (ie all comments but the commit message)"""
#         return Comment.objects.filter(Q(patch=self) & ~Q(msgid=self.msgid))
# 
#     def comments(self):
#         """Retrieves all comments of this patch ie. the commit message and the
#            answers"""
#         return Comment.objects.filter(patch=self)
# 
#     def series(self):
#         try:
#             rev = SeriesRevisionPatch.objects.filter(patch=self)[0].revision
#             return rev.series
#         except Exception:
#             return None
# 
#     def _set_tag(self, tag, count):
#         if count == 0:
#             self.patchtag_set.filter(tag=tag).delete()
#             return
#         (patchtag, _) = PatchTag.objects.get_or_create(patch=self, tag=tag)
#         if patchtag.count != count:
#             patchtag.count = count
#             patchtag.save()
# 
#     def refresh_tag_counts(self):
#         tags = self.project.tags
#         counter = Counter()
#         for comment in self.comment_set.all():
#             counter = counter + extract_tags(comment.content, tags)
# 
#         for tag in tags:
#             self._set_tag(tag, counter[tag])
# 
#     def save(self):
#         if not hasattr(self, 'state') or not self.state:
#             self.state = get_default_initial_patch_state()
# 
#         if self.hash is None and self.content is not None:
#             self.hash = hash_patch(self.content).hexdigest()
# 
#         super(Patch, self).save()
# 
#     def filename(self):
#         return filename(self.name, '.patch')
# 
#     def human_name(self):
#         return self.name
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('patch', (), {'patch_id': self.id})
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = 'Patches'
#         ordering = ['date']
#         unique_together = [('msgid', 'project')]


from django.core.management.base import BaseCommand
from patchwork.models import Patch
#!/usr/bin/env python
#
# 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.
#
# Patchwork is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Patchwork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA




class Command(BaseCommand):
    help = 'Update the hashes on existing patches'
    args = '[<patch_id>...]'

    def handle(self, *args, **options):

# Path: patchwork/models.py
# class Patch(models.Model):
#     project = models.ForeignKey(Project, on_delete=models.CASCADE)
#     msgid = models.CharField(max_length=255)
#     name = models.CharField(max_length=255)
#     date = models.DateTimeField(default=datetime.datetime.now)
#     last_updated = models.DateTimeField(auto_now=True)
#     submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
#     delegate = models.ForeignKey(User, blank=True, null=True,
#                                  on_delete=models.CASCADE)
#     state = models.ForeignKey(State, null=True, on_delete=models.CASCADE)
#     archived = models.BooleanField(default=False)
#     headers = models.TextField(blank=True)
#     content = models.TextField(null=True, blank=True)
#     pull_url = models.CharField(max_length=255, null=True, blank=True)
#     commit_ref = models.CharField(max_length=255, null=True, blank=True)
#     hash = HashField(null=True, blank=True)
#     tags = models.ManyToManyField(Tag, through=PatchTag)
# 
#     objects = PatchManager()
# 
#     def commit_message(self):
#         """Retrieves the commit message"""
#         return Comment.objects.filter(patch=self, msgid=self.msgid)
# 
#     def answers(self):
#         """Retrieves the answers (ie all comments but the commit message)"""
#         return Comment.objects.filter(Q(patch=self) & ~Q(msgid=self.msgid))
# 
#     def comments(self):
#         """Retrieves all comments of this patch ie. the commit message and the
#            answers"""
#         return Comment.objects.filter(patch=self)
# 
#     def series(self):
#         try:
#             rev = SeriesRevisionPatch.objects.filter(patch=self)[0].revision
#             return rev.series
#         except Exception:
#             return None
# 
#     def _set_tag(self, tag, count):
#         if count == 0:
#             self.patchtag_set.filter(tag=tag).delete()
#             return
#         (patchtag, _) = PatchTag.objects.get_or_create(patch=self, tag=tag)
#         if patchtag.count != count:
#             patchtag.count = count
#             patchtag.save()
# 
#     def refresh_tag_counts(self):
#         tags = self.project.tags
#         counter = Counter()
#         for comment in self.comment_set.all():
#             counter = counter + extract_tags(comment.content, tags)
# 
#         for tag in tags:
#             self._set_tag(tag, counter[tag])
# 
#     def save(self):
#         if not hasattr(self, 'state') or not self.state:
#             self.state = get_default_initial_patch_state()
# 
#         if self.hash is None and self.content is not None:
#             self.hash = hash_patch(self.content).hexdigest()
# 
#         super(Patch, self).save()
# 
#     def filename(self):
#         return filename(self.name, '.patch')
# 
#     def human_name(self):
#         return self.name
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('patch', (), {'patch_id': self.id})
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = 'Patches'
#         ordering = ['date']
#         unique_together = [('msgid', 'project')]


# Path: patchwork/management/commands/rehash.py
from django.core.management.base import BaseCommand
from patchwork.models import Patch

#!/usr/bin/env python
#
# 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.
#
# Patchwork is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Patchwork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA




class Command(BaseCommand):
    help = 'Update the hashes on existing patches'
    args = '[<patch_id>...]'

    def handle(self, *args, **options):

        query = Patch.objects