Message ID | 1448712886-3221-4-git-send-email-mchehab@osg.samsung.com |
---|---|
State | Accepted |
Delegated to: | Stephen Finucane |
Headers | show |
On 28 Nov 10:14, Mauro Carvalho Chehab wrote: > From: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com> > --- > patchwork/bin/parsemail.py | 47 +++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 40 insertions(+), 7 deletions(-) > > diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py > index e66b55715d8f..4f22c7f2d6a0 100755 > --- a/patchwork/bin/parsemail.py > +++ b/patchwork/bin/parsemail.py > @@ -25,13 +25,14 @@ import datetime > import time > import operator > import codecs > +from fnmatch import fnmatch > from email import message_from_file > from email.header import Header, decode_header > from email.utils import parsedate_tz, mktime_tz > > -from patchwork.parser import parse_patch > +from patchwork.parser import parse_patch, patch_get_filenames > from patchwork.models import Patch, Project, Person, Comment, State, \ > - get_default_initial_patch_state > + DelegationRule, get_default_initial_patch_state > import django > from django.contrib.auth.models import User > > @@ -208,6 +209,10 @@ def find_content(project, mail): > > patch = None > comment = None > + filenames = None > + > + if patchbuf: > + filenames = patch_get_filenames(patchbuf) > > if pullurl or patchbuf: > name = clean_subject(mail.get('Subject'), [project.linkname]) > @@ -225,12 +230,12 @@ def find_content(project, mail): > else: > cpatch = find_patch_for_comment(project, mail) > if not cpatch: > - return (None, None) > + return (None, None, None) So this changes the signature for the function, resulting in a lot of failing unit tests. Could you fix these? You can run them like so: tox or to test a specific environment: tox -e py27-django18 Alternatively I can fix them, though I'm not sure if I should resend the entire series or not? Stephen
On 06 Jan 17:10, Finucane, Stephen wrote: > On 28 Nov 10:14, Mauro Carvalho Chehab wrote: > > From: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com> > > --- > > patchwork/bin/parsemail.py | 47 +++++++++++++++++++++++++++++++++++++++------- > > 1 file changed, 40 insertions(+), 7 deletions(-) > > > > diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py > > index e66b55715d8f..4f22c7f2d6a0 100755 > > --- a/patchwork/bin/parsemail.py > > +++ b/patchwork/bin/parsemail.py > > @@ -25,13 +25,14 @@ import datetime > > import time > > import operator > > import codecs > > +from fnmatch import fnmatch > > from email import message_from_file > > from email.header import Header, decode_header > > from email.utils import parsedate_tz, mktime_tz > > > > -from patchwork.parser import parse_patch > > +from patchwork.parser import parse_patch, patch_get_filenames > > from patchwork.models import Patch, Project, Person, Comment, State, \ > > - get_default_initial_patch_state > > + DelegationRule, get_default_initial_patch_state > > import django > > from django.contrib.auth.models import User > > > > @@ -208,6 +209,10 @@ def find_content(project, mail): > > > > patch = None > > comment = None > > + filenames = None > > + > > + if patchbuf: > > + filenames = patch_get_filenames(patchbuf) > > > > if pullurl or patchbuf: > > name = clean_subject(mail.get('Subject'), [project.linkname]) > > @@ -225,12 +230,12 @@ def find_content(project, mail): > > else: > > cpatch = find_patch_for_comment(project, mail) > > if not cpatch: > > - return (None, None) > > + return (None, None, None) > > So this changes the signature for the function, resulting in a lot of > failing unit tests. Could you fix these? You can run them like so: > > tox > > or to test a specific environment: > > tox -e py27-django18 > > Alternatively I can fix them, though I'm not sure if I should resend > the entire series or not? > > Stephen I fixed these. Merged.
diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py index e66b55715d8f..4f22c7f2d6a0 100755 --- a/patchwork/bin/parsemail.py +++ b/patchwork/bin/parsemail.py @@ -25,13 +25,14 @@ import datetime import time import operator import codecs +from fnmatch import fnmatch from email import message_from_file from email.header import Header, decode_header from email.utils import parsedate_tz, mktime_tz -from patchwork.parser import parse_patch +from patchwork.parser import parse_patch, patch_get_filenames from patchwork.models import Patch, Project, Person, Comment, State, \ - get_default_initial_patch_state + DelegationRule, get_default_initial_patch_state import django from django.contrib.auth.models import User @@ -208,6 +209,10 @@ def find_content(project, mail): patch = None comment = None + filenames = None + + if patchbuf: + filenames = patch_get_filenames(patchbuf) if pullurl or patchbuf: name = clean_subject(mail.get('Subject'), [project.linkname]) @@ -225,12 +230,12 @@ def find_content(project, mail): else: cpatch = find_patch_for_comment(project, mail) if not cpatch: - return (None, None) + return (None, None, None) comment = Comment(patch = cpatch, date = mail_date(mail), content = clean_content(commentbuf), headers = mail_headers(mail)) - return (patch, comment) + return (patch, comment, filenames) def find_patch_for_comment(project, mail): # construct a list of possible reply message ids @@ -334,6 +339,31 @@ def get_state(state_name): pass return get_default_initial_patch_state() +def auto_delegate(project, filenames): + if not filenames: + return None + + rules = list(DelegationRule.objects.filter(project = project)) + + patch_delegate = None + + for filename in filenames: + file_delegate = None + for rule in rules: + if fnmatch(filename, rule.path): + file_delegate = rule.user + break; + + if file_delegate is None: + return None + + if patch_delegate is not None and file_delegate != patch_delegate: + return None + + patch_delegate = file_delegate + + return patch_delegate + def get_delegate(delegate_email): """ Return the delegate with the given email or None """ if delegate_email: @@ -368,9 +398,13 @@ def parse_mail(mail): (author, save_required) = find_author(mail) - (patch, comment) = find_content(project, mail) + (patch, comment, filenames) = find_content(project, mail) if patch: + delegate = get_delegate(mail.get('X-Patchwork-Delegate', '').strip()) + if not delegate: + delegate = auto_delegate(project, filenames) + # we delay the saving until we know we have a patch. if save_required: author.save() @@ -379,8 +413,7 @@ def parse_mail(mail): patch.msgid = msgid patch.project = project patch.state = get_state(mail.get('X-Patchwork-State', '').strip()) - patch.delegate = get_delegate( - mail.get('X-Patchwork-Delegate', '').strip()) + patch.delegate = delegate try: patch.save() except Exception, ex: