changes_0.3

API changes in python-launchpad-bugs 0.3

There are some API related differences between python-launchpad-bugs 0.2 and 0.3. This documents aims to describe these and show necessary changes to code using this library.

Exceptions

python-launchpad-bugs 0.3 now has a separate module called exceptions where basically two classes of exceptions are defined: LaunchpadError and PythonLaunchpadBugsError. Both have several subclasses, for a complete list please have a look at help(exceptions).

In former versions of python-launchpad-bugs there only existed one exception-class as an attribute of the connector class, so there were code like:

   1 >>> from launchpadbugs.connector import ConnectBug
   2 >>> Bug = ConnectBug()
   3 >>> try:
   4 ...     b = Bug(url="https://bugs.launchpad.net/someinvalidproduct/+bug/1")
   5 ... except Bug.Error.LPUrlError, e:
   6 ...     print e
   7 ... 
   8 'Page not found (url: https://bugs.launchpad.net/someinvalidproduct/+bug/1)'
   9 >>> 

This now changed to something like:

   1 >>> from launchpadbugs.connector import ConnectBug
   2 >>> from launchpadbugs.exceptions import LaunchpadError
   3 >>> Bug = ConnectBug()
   4 >>> try:
   5 ...     b = Bug(url="https://bugs.launchpad.net/someinvalidproduct/+bug/1")
   6 ... except LaunchpadError, e:
   7 ...     print e
   8 ... 
   9 
  10     * message: Page not found
  11     * url: https://bugs.launchpad.net/someinvalidproduct/+bug/1
  12 >>> 

However, it is still possible to use the old Bug.Error.LPUrlError method.

Filtering BugList-objects

In the past BugList-objects had a method called filter() for filter purposes. This method has now been removed, please use the buildin filter() function instead.

In the past filtering of buglists looked like:

   1 >>> from launchpadbugs.connector import ConnectBugList
   2 >>> BugList = ConnectBugList()
   3 >>> l = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs") 
   4 >>> BugList.set_filter(minbug=100000, filterbug="117701,109628", status="New")
   5 >>> l = l.filter()
   6 >>> print l
   7     #.... [output]

This has now been replaced by:

   1 >>> from launchpadbugs.connector import ConnectBugList
   2 >>> BugList = ConnectBugList()
   3 >>> l = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs")
   4 >>> print l
   5 BugList([<BugInfo 239007>,<BugInfo 129341>,<BugInfo 88102>,<BugInfo 150887>])
   6 >>> filter(lambda x: int(x) > 100000 and int(x) not in (117701, 109628) and x.status == "New", l)
   7 [<BugInfo 129341>]
   8 >>> 

In python-launchpad-bugs 0.3 it is also possible to filter bugs during the fetching process, for more information on this please visit BugHelper/Dev/python-launchpad-bugs/BugList

Downloading attachments

As in former versions of python-launchpad-bugs the default download location for attachments is ~/.bughelper/attachments-cache/<package>/<bugnumber>/<attachment_id>/<filename>. In the past changing the ~/.bughelper/attachments-cache/-part of the location could be done by changing a global setting:

   1 >>> from launchpadbugs.connector import ConnectBug
   2 >>> Bug = ConnectBug()
   3 >>> Bug.attachment_path = "/tmp/"
   4 >>> b = Bug(234904)
   5 >>> a = b.attachments[0]
   6 >>> a
   7 <Attachment (up: 14708361)>
   8 >>> a.text # by doing this the file is downloaded and the content is returned
   9 ....some content here ...
  10 >>> a.locale_filename
  11 '/tmp/terminator/234904/14708361/terminator-ctrl-tab.patch'
  12 >>>

This behaviour changed a bit, Bug.attachment_path has been removed, there is not global setting any more. Instead you can now give an explicit location where the file will be downloaded:

   1 >>> from launchpadbugs.connector import ConnectBug
   2 >>> Bug = ConnectBug()
   3 >>> b = Bug(229201)
   4 >>> a = b.attachments[0]
   5 >>> a
   6 <Attachment (up: 14525858)>
   7 >>> a.download("/tmp/boo.diff")
   8 >>> a
   9 <Attachment (up: 14525858), (down: /tmp/boo.diff)>
  10 >>> a.text
  11 ....some content here ...

Constants

The launchpadbugs.lpconstants module defines some global constants for python-launchpad-bugs, for example there is a class of BASEURL constants. This BASEURL constants define the valid url scheme for the different objects and are server independent. In former versions there where two url constants for bug objects (BASEURL.BUG_NG and BASEURL.BUG). BASEURL.BUG_NG has been remove in python-launchpad-bugs 0.3. BASEURL.BUG is now the only valid url definition for bug-objects, its value is https://bugs.launchpad.net.

BugHelper/Dev/python-launchpad-bugs/changes_0.3 (last edited 2008-08-28 00:31:47 by c-24-21-234-111)