]> git.ozlabs.org Git - patchwork/commitdiff
Get parsemail scripts going
authorJeremy Kerr <jk@ozlabs.org>
Thu, 21 Aug 2008 09:08:23 +0000 (17:08 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 21 Aug 2008 09:08:23 +0000 (17:08 +0800)
A couple of fixes, plus required permissions in the grant-all script.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/bin/parsemail-batch.sh [changed mode: 0644->0755]
apps/patchwork/bin/parsemail.py
lib/sql/grant-all.sql

old mode 100644 (file)
new mode 100755 (executable)
index dbf81cc..d786022
@@ -21,7 +21,7 @@
 
 PATCHWORK_BASE="/srv/patchwork"
 
-if $# -ne 2
+if [ $# -ne 1 ]
 then
        echo "usage: $0 <dir>" >&2
        exit 1
@@ -29,9 +29,11 @@ fi
 
 mail_dir="$1"
 
-if ! -d "$mail_dir"
+echo "dir: $mail_dir"
+
+if [ ! -d "$mail_dir" ]
 then
-       echo "$mail_dir should be a directory"?&2
+       echo "$mail_dir should be a directory"? >&2
        exit 1
 fi
 
@@ -41,7 +43,7 @@ do
        echo $line
        PYTHONPATH="$PATCHWORK_BASE/apps":"$PATCHWORK_BASE/lib/python" \
                DJANGO_SETTINGS_MODULE=settings \
-               "$PATCHWORK_BASE/apps/patchworkbin/parsemail.py" <
+               "$PATCHWORK_BASE/apps/patchwork/bin/parsemail.py" < \
                "$mail_dir/$line"
 done
 
index d41bd92b04048bd0d2db2da2adb2629f5a50712a..d0993acfc2f641a790c08f35917cbb669111351b 100755 (executable)
@@ -85,12 +85,15 @@ def find_author(mail):
     if name is not None:
         name = name.strip()
 
+    new_person = False
+
     try:
         person = Person.objects.get(email = email)
     except Person.DoesNotExist:
         person = Person(name = name, email = email)
+        new_person = True
 
-    return person
+    return (person, new_person)
 
 def mail_date(mail):
     t = parsedate_tz(mail.get('Date', ''))
@@ -230,12 +233,15 @@ def main(args):
 
     msgid = mail.get('Message-Id').strip()
 
-    author = find_author(mail)
+    (author, save_required) = find_author(mail)
 
     (patch, comment) = find_content(project, mail)
 
     if patch:
-        author.save()
+        # we delay the saving until we know we have a patch.
+        if save_required:
+            author.save()
+            save_required = False
         patch.submitter = author
         patch.msgid = msgid
         patch.project = project
@@ -245,7 +251,8 @@ def main(args):
             print ex.message
 
     if comment:
-        author.save()
+        if save_required:
+            author.save()
         # looks like the original constructor for Comment takes the pk
         # when the Comment is created. reset it here.
         if patch:
index 4b8a43bc33d60bc1403a205bdf7574bbaab9b21b..d0dd45f8ecd2a5b1dfe5b4f3868147945454b746 100644 (file)
@@ -56,7 +56,8 @@ GRANT INSERT, SELECT ON
        patchwork_person
 TO "nobody";
 GRANT SELECT ON
-       patchwork_project
+       patchwork_project,
+       patchwork_state
 TO "nobody";
 GRANT UPDATE, SELECT ON
        patchwork_patch_id_seq,