Commits

Augie Fackler committed 01537b0

Add support for auto-closing patchwork entries.

Comments (0)

Files changed (1)

patchbot-patchworker/patchworker.py

+import argparse
+import sys
+import urllib2
 import xmlrpclib
-import urllib2
 
 import pyquery
 
-def get_new_patchwork():
-    s = xmlrpclib.ServerProxy('http://patchwork.serpentine.com/xmlrpc/')
-    return [p for p in s.patch_list() if p['state'] == 'New']
+def get_new_patchwork(s):
+    return [p for p in s.patch_list({'state_id': statemap['New']})]
 
 def patchurl(id):
     return 'http://patchwork.serpentine.com/patch/%d' % id
     return set([a.attrib['href'][_URL_PREFIX_LEN:] for a in
                 q('div.series-%s' % state)('a.list-group-item')])
 
-def main():
+def main(argv=sys.argv):
+    p = argparse.ArgumentParser()
+    p.add_argument('--user', '-u', required=True, nargs=1)
+    p.add_argument('--password', '-p', required=True, nargs=1)
+    p.add_argument('--dry-run', '-n', action='store_true')
+    p.add_argument('--close-seen', action='store_true')
+    p.add_argument('--quiet', '-q', action='store_true')
+    opts = p.parse_args(argv[1:])
+    s = xmlrpclib.ServerProxy(
+        'http://%s:%s@patchwork.serpentine.com/xmlrpc/' % (
+            opts.user, opts.password))
+    global statemap
+    statemap = {x['name']: x['id'] for x in s.state_list()}
+
     superseded = patchbot_in_state('superseded')
     queued = patchbot_in_state('queued')
     seen = patchbot_in_state('seen')
-    new_patches = get_new_patchwork()
+    new_patches = get_new_patchwork(s)
     superseded_ids = []
     queued_ids = []
     seen_ids = []
     for patch in new_patches:
         if patch['msgid'] in superseded:
+            if not opts.dry_run:
+                s.patch_set(patch['id'], {'state': statemap['Superseded']})
             superseded_ids.append(patch['id'])
         if patch['msgid'] in queued:
+            if not opts.dry_run:
+                s.patch_set(patch['id'], {'state': statemap['Accepted']})
             queued_ids.append(patch['id'])
         if patch['msgid'] in seen:
+            if not opts.dry_run and opts.close_seen:
+                s.patch_set(
+                    patch['id'], {'state': statemap['Changes Requested']})
             seen_ids.append(patch['id'])
-    if superseded_ids:
-        print 'Superseded:'
-        for pid in superseded_ids:
-            print patchurl(pid)
-    if queued_ids:
-        print 'Queued:'
-        for pid in queued_ids:
-            print patchurl(pid)
-    if seen_ids:
-        print 'Seen:'
-        for pid in seen_ids:
-            print patchurl(pid)
+    if not opts.quiet:
+        if superseded_ids:
+            print 'Superseded:'
+            for pid in superseded_ids:
+                print patchurl(pid)
+        if queued_ids:
+            print 'Queued:'
+            for pid in queued_ids:
+                print patchurl(pid)
+        if seen_ids:
+            print 'Seen:'
+            for pid in seen_ids:
+                print patchurl(pid)