#!/usr/bin/python # Read any new bugs out of RH Bugzilla and update the "Bugzilla # Incoming" page. Exclude bugs which are mentioned in [#123456] # comments already. import sys import re import getopt import dbus, gobject, dbus.glib import bugzilla import xml.sax.saxutils username = None password = None try: opts, args = getopt.getopt (sys.argv[1:], "hp:u:", ["help", "password=", "username="]) except getopt.GetoptError: usage () sys.exit (2) for opt, arg in opts: if opt in ("-h", "--help"): usage () sys.exit () elif opt in ("-p", "--password"): password = arg elif opt in ("-u", "--username"): username = arg bus = dbus.SessionBus () obj = bus.get_object ("org.gnome.Tomboy", "/org/gnome/Tomboy/RemoteControl") tomboy = dbus.Interface (obj, "org.gnome.Tomboy.RemoteControl") # Look at all notes for [#123456] comments, and add those (seen) # bugzilla numbers to the list of seen bugs. bugs_seen = dict () for note in tomboy.ListAllNotes (): contents = tomboy.GetNoteContents (note) matches = re.finditer ("\[#(\d+)\]", contents) for match in matches: num = int (match.group(1)) bugs_seen[num] = note #print bugs_seen # Connect to BZ. bz = bugzilla.Bugzilla (url="https://bugzilla.redhat.com/xmlrpc.cgi") if username <> None and password <> None: bz.login (username, password) # Get all bugs of interest to me. # A good way to find out the syntax of these queries is to use the # command line /usr/bin/bugzilla program with the --debug option, # looking for the "bz.query" line. bugs = bz.query ({'emailtype1': 'substring', 'emailcc1': True, 'email1': username, # Everything except 'CLOSED' 'bug_status': ['NEW','ASSIGNED','NEEDINFO','ON_DEV', 'MODIFIED','POST','ON_QA','FAILS_QA', 'PASSES_QA','REOPENED', 'VERIFIED','RELEASE_PENDING']}) # This returns a list of bugs. Note that accessing fields in the bug # (apart from 'id' and a few others) involves a hidden callout to the # Bugzilla server, so avoid this if possible. #for bug in bugs: # if not (bug.id in bugs_seen): # print "%d %s" % (bug.id, bug.summary) # Get the Tomboy Bugzilla Incoming page (you must create this page first). incoming_note = tomboy.FindNote ("Bugzilla Incoming") # Now add the new bugs to the "Bugzilla Incoming" page. for bug in bugs: if not (bug.id in bugs_seen): print "New bug seen: %d %s" % (bug.id, bug.summary) contents = tomboy.GetNoteContentsXml (incoming_note) summary = xml.sax.saxutils.escape (bug.summary) contents = re.sub ("", "[#%d] %s\n" % (bug.id, summary), contents) tomboy.SetNoteContentsXml (incoming_note, contents)