X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=patchwork%2Fbin%2Fparsemail.py;h=f2b10bd38ee9f0536745d0e624db5c2a8f7c726f;hb=41d5ceb82b5d4297570b73639517b642fab0c45f;hp=5cb0b505250eb5ea92fce5b1791c635c05d8d0e6;hpb=85916e6c56076a29c6113e169d3e4926a7c886b1;p=patchwork diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py index 5cb0b50..f2b10bd 100755 --- a/patchwork/bin/parsemail.py +++ b/patchwork/bin/parsemail.py @@ -37,6 +37,7 @@ except ImportError: from patchwork.parser import parse_patch from patchwork.models import Patch, Project, Person, Comment, State, \ get_default_initial_patch_state +import django from django.contrib.auth.models import User list_id_headers = ['List-ID', 'X-Mailing-List', 'X-list'] @@ -79,7 +80,7 @@ def find_project(mail): try: project = Project.objects.get(listid = listid) break - except: + except Project.DoesNotExist: pass return project @@ -219,15 +220,20 @@ def find_content(project, mail): date = mail_date(mail), headers = mail_headers(mail)) if commentbuf: + # If this is a new patch, we defer setting comment.patch until + # patch has been saved by the caller if patch: - cpatch = patch + comment = Comment(date = mail_date(mail), + content = clean_content(commentbuf), + headers = mail_headers(mail)) + else: cpatch = find_patch_for_comment(project, mail) if not cpatch: return (None, None) - comment = Comment(patch = cpatch, date = mail_date(mail), - content = clean_content(commentbuf), - headers = mail_headers(mail)) + comment = Comment(patch = cpatch, date = mail_date(mail), + content = clean_content(commentbuf), + headers = mail_headers(mail)) return (patch, comment) @@ -388,8 +394,7 @@ def parse_mail(mail): if comment: if save_required: author.save() - # looks like the original constructor for Comment takes the pk - # when the Comment is created. reset it here. + # we defer this assignment until we know that we have a saved patch if patch: comment.patch = patch comment.submitter = author @@ -402,6 +407,7 @@ def parse_mail(mail): return 0 def main(args): + django.setup() mail = message_from_file(sys.stdin) return parse_mail(mail)