= python-launchpad-bugs Examples = This page contains two examples on how using python-launchpad-bugs. == parse changelog and close upstream bugreports == This script parses 'debian/changelog' for statements like '(LP: #123456)' and closes upstream bugreports. {{{#!python import launchpadbugs.connector as Connector import re Bug = Connector.ConnectBug() Bug.authentication = "/home/markus/.gnome2/epiphany/mozilla/epiphany/cookies.txt" LP_BUGS = re.compile("\(LP: ?#?(?P[0-9]+)\)") class Entry(object): def __init__(self, text): self.text = text def closed_bugs(self): return map(int, LP_BUGS.findall(self.text)) class ChangeLog(list): def __init__(self, filename): changelog = file(filename, "r") L = [] for i in changelog.readlines(): if i.startswith(" -- ") or i.startswith("-- "): tmp += i L.append(Entry(tmp.strip("\n"))) elif i.strip("\n") and not i.startswith(" "): tmp = i else: tmp += i list.__init__(self, L) #c = ChangeLog("/home/devel/bughelper/main/debian/changelog") c = ChangeLog("debian/changelog") for i in c[:1]: #this only checks the last entry, but it's easy to define a range (cmd-line option?) comment = Bug.NewComment(text=i.text,subject="auto closed by script") for b in i.closed_bugs(): bug = Bug(b) print "checking", b if not bug.status == "Fix Released": print "changing", b.url b.comments.add(comment) b.status = "Fix Released" b.commit() }}} == Search buglists by content of an attachment == This is an example on how to filtering buglists by the content of an attachment {{{#!python import launchpadbugs.connector as Connector from launchpadbugs.basebuglistfilter import URLBugListFilter, StopFiltering from launchpadbugs.bugbase import Bug as BugBase import datetime Bug = Connector.ConnectBug("text") BugList = Connector.ConnectBugList() def reported_since(b): if not isinstance(b, BugBase): b = Bug(b) if not False in map(lambda x: x.date_created < datetime.datetime(2008,02,18), b.infotable): raise StopFiltering if "pycentral" in b.text or "python-central" in b.text: return b for a in b.attachments: if a.description == "DpkgTerminalLog.gz": if "pycentral" in a.text or "python-central" in a.text: return b return False url = """https://bugs.edge.launchpad.net/ubuntu/+bugs?field.searchtext=&orderby=-datecreated&search=Search&field.status%3Alist=NEW&field.status%3Alist=INCOMPLETE_WITH_RESPONSE&field.status%3Alist=INCOMPLETE_WITHOUT_RESPONSE&field.status%3Alist=INVALID&field.status%3Alist=WONTFIX&field.status%3Alist=CONFIRMED&field.status%3Alist=TRIAGED&field.status%3Alist=INPROGRESS&field.status%3Alist=FIXCOMMITTED&field.status%3Alist=FIXRELEASED&field.assignee=&field.bug_reporter=&field.omit_dupes=&field.has_patch=&field.has_no_package=""" bug_filter = URLBugListFilter() bug_filter.functions.append(reported_since) bl = BugList(bug_filter(url)) for b in bl: print b.url print "\t", b.duplicates, b.duplicate_of }}} == mass closing of bugs == {{{#!python from launchpadbugs.connector import ConnectBug, ConnectBugList cookie = "/home/markus/.mozilla/firefox/iy3ore6m.default/cookies.sqlite" Bug = ConnectBug() Bug.authentication = cookie Buglist = ConnectBugList() Buglist.authentication = cookie bl = Buglist("https://bugs.edge.launchpad.net/~thekorn") print len(bl) count = 0 for i in bl: com = Bug.NewComment("mass closing of old buglog-data bugs", "closing this old buglog-data bug") if i.sourcepackage == "buglog-data": count += 1 b = Bug(i) b.status = "Invalid" b.comments.add(com) print count, b.url b.commit() }}}