Skip to content

Commit

Permalink
project: Add a retriageproject command
Browse files Browse the repository at this point in the history
When creating a new project using the subject prefix tags, people may
want to go back and triage already existing patches/series into that new
project from the already existing project.

This command let you do just that.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Nov 7, 2015
1 parent 33f4ed4 commit ddca0ad
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions patchwork/management/commands/retriageproject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Patchwork - automated patch tracking system
# 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

from email.parser import HeaderParser
import sys

from django.core.management.base import BaseCommand
from patchwork.models import Patch, Project, SeriesRevisionPatch
from patchwork.bin.parsemail import find_project


def find_series_for_patch(patch):
try:
revision = SeriesRevisionPatch.objects.filter(patch=patch)[0].revision
return revision.series
except:
return None


class Command(BaseCommand):
help = 'Reassign project of patches and series when ' \
'subject_prefix_tags changes'
args = 'project'

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

if len(args) != 1:
print('error: Need a project.')
sys.exit(1)

try:
project = Project.objects.get(linkname=args[0])
except Project.DoesNotExist:
print("error: can't find project '%s'" % args[0])
sys.exit(1)

parser = HeaderParser()
query = Patch.objects.filter(project=project)
count = query.count()
for i, patch in enumerate(query.iterator()):
if (i % 10) == 0:
sys.stdout.write("%06d/%06d\r" % (i, count))
sys.stdout.flush()

headers = parser.parsestr(patch.headers)
new_project = find_project(headers)
if new_project == patch.project:
continue

patch.project = new_project
patch.save()
series = find_series_for_patch(patch)
if not series:
continue
series.project = new_project
series.save()

sys.stdout.write("%06d/%06d\r" % (count, count))
sys.stdout.write('\ndone\n')

0 comments on commit ddca0ad

Please sign in to comment.