diff options
author | Will Woods <wwoods@wills-mini.localdomain> | 2007-09-06 20:27:02 -0400 |
---|---|---|
committer | Will Woods <wwoods@wills-mini.localdomain> | 2007-09-06 20:27:02 -0400 |
commit | 4afdcd4f75effdd5f55e39916289707d7f67c235 (patch) | |
tree | 00e4f770bcc60155fc17350ddd11a7a51962cd8c | |
parent | 9ee1856c171867976b7a7b987baa62b24d14fd5c (diff) | |
download | python-bugzilla-4afdcd4f75effdd5f55e39916289707d7f67c235.tar.gz python-bugzilla-4afdcd4f75effdd5f55e39916289707d7f67c235.tar.xz python-bugzilla-4afdcd4f75effdd5f55e39916289707d7f67c235.zip |
make query() and getbug() return Bugs, adapt selftest.py
-rw-r--r-- | bugzilla.py | 41 | ||||
-rwxr-xr-x | selftest.py | 40 |
2 files changed, 55 insertions, 26 deletions
diff --git a/bugzilla.py b/bugzilla.py index 6326649..31bc21a 100644 --- a/bugzilla.py +++ b/bugzilla.py @@ -137,15 +137,19 @@ class Bugzilla(object): '''Return a short dict of simple bug info for the given bug id''' return self._proxy.bugzilla.getBugSimple(id, self.user, self.password) - # TODO return a Bug object instead + # these return a Bug objects + def getbugfull(self,id): + '''Return a Bug object with the full complement of bug data + already loaded.''' + r = self._proxy.bugzilla.getBug(id, self.user, self.password) + return Bug(bugzilla=self,dict=r) + def getbug(self,id): - '''Return a dict of full bug info for the given bug id''' - return self._proxy.bugzilla.getBug(id, self.user, self.password) - def getbugsimple(self,id): - '''Return a short dict of simple bug info for the given bug id''' - return self._proxy.bugzilla.getBugSimple(id, self.user, self.password) + '''Return a Bug object given bug id, populated with simple info''' + r = self._proxy.bugzilla.getBugSimple(id, self.user, self.password) + return Bug(bugzilla=self,dict=r) - def query(self,query): + def _query(self,query): '''Query bugzilla and return a list of matching bugs. query must be a dict with fields like those in in querydata['fields']. @@ -162,6 +166,18 @@ class Bugzilla(object): ''' return self._proxy.bugzilla.runQuery(query,self.user,self.password) + def query(self,query): + '''Query bugzilla and return a list of matching bugs. + query must be a dict with fields like those in in querydata['fields']. + + Returns a list of Bug objects. + ''' + r = self._query(query) + buglist = list() + for b in r['bugs']: + buglist.append(Bug(bugzilla=self,dict=b)) + return buglist + def query_comments(self,product,version,component,string,matchtype='allwordssubstr'): '''Convenience method - query for bugs filed against the given product, version, and component whose comments match the given string. @@ -381,6 +397,9 @@ class Bug(object): '_getAttributeNames') and not name.endswith(')'): # FIXME: that .endswith hack is an extremely stupid way to figure # out if we're checking on a method call. Find a smarter one! + if not 'bug_id' in self.__dict__: + raise AttributeError + #print "Bug %i missing %s - loading" % (self.bug_id,name) r = self.bugzilla._getbug(self.bug_id) self.__dict__.update(r) if name in self.__dict__: @@ -437,6 +456,14 @@ class Bug(object): tags = self.gettags(which) tags.remove(tag) self.setwhiteboard(' '.join(tags),which) + def __str__(self): + '''Return a simple string representation of this bug''' + if 'short_short_desc' in self.__dict__: + desc = self.short_short_desc + else: + desc = self.short_desc + return "#%-6s %-10s - %s - %s" % (self.bug_id,self.bug_status, + self.assigned_to,desc) # TODO: add a sync() method that writes the changed data in the Bug object # back to Bugzilla. Someday. diff --git a/selftest.py b/selftest.py index d4ed6df..3baadea 100755 --- a/selftest.py +++ b/selftest.py @@ -20,9 +20,8 @@ def find_firefox_cookiefile(): # TODO return whichever is newest return cookiefiles[0] -def selftest(): +def selftest(user='',password=''): url = 'https://bugzilla.redhat.com/xmlrpc.cgi' - cookies = find_firefox_cookiefile() public_bug = 1 private_bug = 250666 query = {'product':'Fedora', @@ -32,19 +31,24 @@ def selftest(): print "Woo, welcome to the bugzilla.py self-test." print "Using bugzilla at " + url - if not cookies: - print "Could not find any cookies for that URL!" - print "Log in with firefox or give me a username/password." - sys.exit(1) - print "Reading cookies from " + cookies - b = Bugzilla(url=url,cookies=cookies) + if user and password: + print 'Using username "%s", password "%s"' % (user,password) + b = Bugzilla(url=url,user=user,password=password) + else: + cookies = find_firefox_cookiefile() + if not cookies: + print "Could not find any cookies for that URL!" + print "Log in with firefox or give me a username/password." + sys.exit(1) + print "Reading cookies from " + cookies + b = Bugzilla(url=url,cookies=cookies) print "Reading product list" print b.getproducts() print "Reading public bug (#%i)" % public_bug - print b.getbugsimple(public_bug) + print b.getbug(public_bug) print "Reading private bug (#%i)" % private_bug try: - print b.getbugsimple(private_bug) + print b.getbug(private_bug) except xmlrpclib.Fault, e: if 'NotPermitted' in e.faultString: print "Failed: Not authorized." @@ -53,17 +57,15 @@ def selftest(): q_msg = "%s %s %s %s" % (query['product'],query['component'], query['version'],query['long_desc']) print "Querying %s bugs" % q_msg - q_result = b.query(query) - bugs = q_result['bugs'] + bugs = b.query(query) print "%s bugs found." % len(bugs) for bug in bugs: - if 'short_short_desc' not in bug: - print "wtf? bug %s has no desc." % bug['bug_id'] - else: - print "Bug #%s %-10s - %s - %s" % (bug['bug_id'], - '('+bug['bug_status']+')',bug['assigned_to'], - bug['short_short_desc']) + print "Bug %s" % bug print "Awesome. We're done." if __name__ == '__main__': - selftest() + user = '' + password = '' + if len(sys.argv) > 2: + (user,password) = sys.argv[1:3] + selftest(user,password) |