Examples

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.

   1 import launchpadbugs.connector as Connector
   2 import re
   3 
   4 Bug = Connector.ConnectBug()
   5 Bug.authentication = "/home/markus/.gnome2/epiphany/mozilla/epiphany/cookies.txt"
   6 LP_BUGS = re.compile("\(LP: ?#?(?P<bug>[0-9]+)\)")
   7 
   8 class Entry(object):
   9     def __init__(self, text):
  10         self.text = text
  11         
  12     def closed_bugs(self):
  13         return map(int, LP_BUGS.findall(self.text))
  14         
  15         
  16 
  17 class ChangeLog(list):
  18     def __init__(self, filename):
  19         changelog = file(filename, "r")
  20         L = []
  21         for i in changelog.readlines():
  22             if i.startswith(" -- ") or i.startswith("-- "):
  23                 tmp += i
  24                 L.append(Entry(tmp.strip("\n")))
  25             elif i.strip("\n") and not i.startswith(" "):
  26                 tmp = i
  27             else:
  28                 tmp += i
  29         list.__init__(self, L)
  30         
  31 
  32 #c = ChangeLog("/home/devel/bughelper/main/debian/changelog")
  33 c = ChangeLog("debian/changelog")
  34 for i in c[:1]: #this only checks the last entry, but it's easy to define a range (cmd-line option?)
  35     comment = Bug.NewComment(text=i.text,subject="auto closed by script")
  36     for b in i.closed_bugs():
  37         bug = Bug(b)
  38         print "checking", b
  39         if not bug.status == "Fix Released":
  40             print "changing", b.url
  41             b.comments.add(comment)
  42             b.status = "Fix Released"
  43             b.commit()

Search buglists by content of an attachment

This is an example on how to filtering buglists by the content of an attachment

   1 import launchpadbugs.connector as Connector
   2 from launchpadbugs.basebuglistfilter import URLBugListFilter, StopFiltering
   3 from launchpadbugs.bugbase import Bug as BugBase
   4 import datetime
   5 
   6 Bug = Connector.ConnectBug("text")
   7 BugList = Connector.ConnectBugList()
   8 
   9 def reported_since(b):
  10     if not isinstance(b, BugBase):
  11         b = Bug(b)
  12     if not False in map(lambda x: x.date_created < datetime.datetime(2008,02,18), b.infotable):
  13         raise StopFiltering
  14     if "pycentral" in b.text or "python-central" in b.text:
  15         return b
  16     for a in b.attachments:
  17         if a.description == "DpkgTerminalLog.gz":
  18             if "pycentral" in a.text or "python-central" in a.text:
  19                 return b
  20     return False
  21 
  22 
  23 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="""
  24 bug_filter = URLBugListFilter()
  25 
  26 bug_filter.functions.append(reported_since)    
  27 
  28 bl = BugList(bug_filter(url))
  29 for b in bl:
  30     print b.url
  31     print "\t", b.duplicates, b.duplicate_of

mass closing of bugs

   1 from launchpadbugs.connector import ConnectBug, ConnectBugList
   2 
   3 cookie = "/home/markus/.mozilla/firefox/iy3ore6m.default/cookies.sqlite"
   4 Bug = ConnectBug()
   5 Bug.authentication = cookie
   6 Buglist = ConnectBugList()
   7 Buglist.authentication = cookie
   8 
   9 bl = Buglist("https://bugs.edge.launchpad.net/~thekorn")
  10 print len(bl)
  11 
  12 count = 0
  13 
  14 for i in bl:
  15     com = Bug.NewComment("mass closing of old buglog-data bugs", "closing this old buglog-data bug")
  16     if i.sourcepackage == "buglog-data":
  17         count += 1
  18         b = Bug(i)
  19         b.status = "Invalid"
  20         b.comments.add(com)
  21         print count, b.url
  22         b.commit()

BugHelper/Dev/python-launchpad-bugs/Examples (last edited 2008-08-29 12:00:30 by a89-182-207-167)