diff mbox

search by messageid?

Message ID 20120515213109.GC3963@sgi.com
State Accepted
Headers show

Commit Message

Ben Myers May 15, 2012, 9:31 p.m. UTC
Hey Jeremy,

On Fri, May 11, 2012 at 03:37:19PM -0700, Jeremy Kerr wrote:
> > Is it possible to find patches by messageid via the xmlrpc interface?  I'm a
> > mutt user and would like to be able to find the patch id given a message id in
> > one of my hooks.
> 
> 
> You could call patch_list() with a filter of {'msgid': some_message_id}
> - this should return a (possibly empty) list of patches. Would that work
> for you?

Thanks for the help!  I'm new to python so this maybe a little wonky but it
seems to work for me:

Regards,
Ben

-------------------

pwclient: add the Message-id to patches

Add the Message-id to patches so that it is easy to reply to the patch on-list
at a later date.

Signed-off-by: Ben Myers <bpm@sgi.com>
diff mbox

Patch

Index: root/pwclient
===================================================================
--- root.orig/pwclient
+++ root/pwclient
@@ -235,6 +235,7 @@  def action_get(rpc, patch_id):
         sys.exit(1)
 
     try:
+    	f.write("Message-ID: %s\n" % patch['msgid']);
         f.write(s)
         f.close()
         print "Saved patch to %s" % fname

------------------


pwclient: lookup patch_id given Message-id

Add a pwclient search option '-m' to look up a patch id given a Message-id.
This is useful for automation and mailer hooks.

Signed-off-by: Ben Myers <bpm@sgi.com>

Index: root/pwclient
===================================================================
--- root.orig/pwclient
+++ root/pwclient
@@ -119,7 +119,8 @@  def usage():
         -p <project>  : Filter by project name (see 'projects' for list)
         -w <who>      : Filter by submitter (name, e-mail substring search)
         -d <who>      : Filter by delegate (name, e-mail substring search)
-        -n <max #>    : Restrict number of results\n""")
+        -n <max #>    : Restrict number of results
+	-m <messageid>: Filter by Message-id\n""")
     sys.stderr.write("""\nActions that take an ID argument can also be \
 invoked with:
         -h <hash>     : Lookup by patch hash\n""")
@@ -294,11 +295,19 @@  def patch_id_from_hash(rpc, hash):
 
     return patch['id']
 
+def patch_id_from_msgid(rpc, msgid_str):
+    f = Filter();
+    f.add("msgid", msgid_str)
+    patches = rpc.patch_list(f.d)
+    for patch in patches:
+        sys.stdout.write("%s\n" % patch['id'])
+    return patches
+
 auth_actions = ['update']
 
 def main():
     try:
-        opts, args = getopt.getopt(sys.argv[2:], 's:p:w:d:n:c:h:')
+        opts, args = getopt.getopt(sys.argv[2:], 's:p:w:d:n:c:h:m:')
     except getopt.GetoptError, err:
         print str(err)
         usage()
@@ -316,6 +325,7 @@  def main():
     commit_str = ""
     state_str = ""
     hash_str = ""
+    msgid_str = ""
     url = DEFAULT_URL
 
     config = ConfigParser.ConfigParser()
@@ -341,6 +351,8 @@  def main():
             commit_str = value
         elif name == '-h':
             hash_str = value
+        elif name == '-m':
+            msgid_str = value
         elif name == '-n':
             try:
                 filt.add("max_count", int(value))
@@ -389,6 +401,11 @@  def main():
             sys.stderr.write("No patch has the hash provided")
             sys.exit(1)
 
+    if msgid_str:
+        patches = patch_id_from_msgid(rpc, msgid_str)
+        if not patches:
+	    sys.exit(1)
+        return
 
     if action == 'list' or action == 'search':
         if len(args) > 0: