BugList

Differences between revisions 10 and 15 (spanning 5 versions)
Revision 10 as of 2007-09-03 10:27:24
Size: 2764
Editor: a89-182-150-140
Comment:
Revision 15 as of 2008-07-03 14:20:37
Size: 6174
Editor: a89-182-197-108
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from BugHelper/Dev/python-launchpad-bugs/API changes/BugListExample
Line 2: Line 3:
||<tablestyle="float:right; font-size: 0.9em; width:40%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;">'''Contents'''[[BR]][[TableOfContents]]||

= BugList - tutorial =
Line 3: Line 8:
= Example usage of BugList =
Line 5: Line 9:
=== Use `LaunchpadConnector` and setting authentification: === == General workflow ==

This is how to use python-launchpad-bugs to get a list of bugs
Line 7: Line 14:
import launchpadbugs.connector as Connector

BugList = Connector.ConnectBugList()
BugList.authentication = "cookie.txt"
>>> from launchpadbugs.connector import ConnectBugList
>>> BugList = ConnectBugList() # using the html mode
>>> bl = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs")
Line 13: Line 19:
=== Getting a list of bugs and print available information: === If you need a faster method to fetch the bug list but can abdicate additional information like status and importance of a bugreport it is possible to use the text mode of launchpad:

{{{#!python start=2
>>> BugList = ConnectBugList("text") # using the text mode
}}}

In some cases, e.g. if the resulting lists should contain private bugreports, authentication is necessary

{{{#!python start=4
>>> BugList.authentication="cookie.txt" #for text-based mozilla cookie files or
>>> BugList.authentication="cookie.sql" #for sql mozilla cookie files
}}}

It is also possible to do authentication via email-login and password. Note: This takes much longer than using cookie files, therefore python-launchpad-bugs provides a method to save the resulting cookie into a file

{{{#!python start=7
>>> BugList.authentication={"email": "login@email.com", "passwort": "YourPassword"}
>>> BugList.connection.save_cookie("/home/markus/.lpcookie")
}}}

There are currently different versions of launchpad, the stable bugs.launchpad.net and the testing environment bugs.edge.launchpad.net. Sometimes it makes sense to explicitly choose one of these versions to work with. In python-launchpad-bugs it is possible to define which version to use.
Line 15: Line 42:
l = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs")
for i in l.bugs:
    print i.bugnumber,
    print i.url,
    print i.summary,
    print i.importance,
    print i.status,
    print i.sourcepackage
>>> from launchpadbugs.lpconstants import HTTPCONNECTION
>>> BugList.set_connection_mode(HTTPCONNECTION.MODE.EDGE) # or
>>> BugList.set_connection_mode(HTTPCONNECTION.MODE.STABLE)
}}}

== Bug list objects ==

`BugList` objects are set-like objects, each member is an instance of `LPBugInfo`.

{{{#!python
>>> bl
<BugList https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs>
>>> print bl
BugList([<BugInfo 129341>,<BugInfo 88102>,<BugInfo 150887>])
>>> len(bl)
3
Line 24: Line 59:
{{{ 88521 https://bugs.launchpad.net/ubuntu/+source/bughelper/+bug/88521 selectively pulling attachments by name Medium Incomplete None
Line 26: Line 60:
88102 https://bugs.launchpad.net/ubuntu/+source/bughelper/+bug/88102 sort report by issue type rather than bug number Undecided Confirmed None === LPBugInfo ===

A `LPBugInfo` object has this attribute:

||'''Attribute'''||'''Description'''||'''Example'''||
|| .bugnumber || number of a bugreport (type of int) || ||
|| .url || url to this bugreport (task specific) || ||
|| .summary || one-line title of a bugreport || ||
|| .importance || importance of a bugreport || ||
|| .status || status of a bugreport || ||
|| .sourcepackage || returns affected package within a distribution or an empty string|| ||

{{{#!python
>>> b = bl.pop()
>>> b
<BugInfo 239007>
>>> print b
[Bug 239007 : Confirmed/Undecided]
>>> int(b)
239007
Line 30: Line 83:

It is easy to merge two `BugList`-objects
Line 31: Line 86:
l += BugList("https://bugs.launchpad.net/bughelper/+bugs")
print l.bugs
}}}
{{{ set([109628, 110937, 88521, 88102, 84723, 88102, 81291, 85152, 88521, 90084, 109547])
>>> bl
<BugList https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs>
>>> bl += BugList("https://bugs.launchpad.net/bughelper/+bugs")
>>> len(bl)
14
Line 37: Line 93:
=== Setting a filter and filter the set of bugs === === Filtering bug lists ===

With python-launchpad-bugs 0.3 there is a new way of filtering bug lists. First of all: there are two different ways of filtering

 * Filtering while fetching the list
 * Filtering the actual object

The way mentioned by the last item can easily be done by using python's buildin `filter()` function and does not change the actual object.[[BR]]
In contrast the first way is irreversible. It is possible to use URL-based filter options (options provided by `advanced-search` of launchpad) or functions to filter elements. This functions take an element of the bug list as the only argument and return either `False` or an instance of `LPBugInfo` or `LPBug`. If `False` is returned the related element is filtered out of the list.

As a very basic example let's have a look at all bugs in the bughelper project which have an even bugnumber and which importance is either "Medium" or "Low"
Line 39: Line 106:
BugList.set_filter(minbug=100000, filterbug="117701,109628", status="New")
l = l.filter()
print l.bugs
}}}
{{{ set([110937, 109547])
>>> from launchpadbugs.basebuglistfilter import URLBugListFilter
>>> bug_filter = URLBugListFilter()
>>> bug_filter.add_option("importance", ("Medium", "Low"))
>>> bug_filter.functions.append(lambda x: not int(x) % 2 and x)
>>> bl = BugList(bug_filter("https://bugs.launchpad.net/bughelper/+bugs"))
>>> print bl
BugList([<BugInfo 131378>,<BugInfo 88102>])
Line 47: Line 116:

`LPBugList` objects do also have a `.sort(<key>)` method which returns a sorted list. `<key>` could be nr, status or importance with an optional leading `-` for reverse order.
Line 48: Line 120:
print l.sort("nr")
}}}
{{{ [109547, 110937]
>>> bl = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs")
>>> print [str(i) for i in bl]
['[Bug 239007 : Confirmed/Undecided]', '[Bug 129341 : New/Wishlist]', '[Bug 88102 : Confirmed/Undecided]', '[Bug 150887 : In Progress/Wishlist]']
>>> print [str(i) for i in bl.sort("-status")]
['[Bug 129341 : New/Wishlist]', '[Bug 239007 : Confirmed/Undecided]', '[Bug 88102 : Confirmed/Undecided]', '[Bug 150887 : In Progress/Wishlist]']
Line 53: Line 127:
=== add LP urloptions to an url === == Raised Exeptions ==

If the url given as an argument to the buglist is not valid in launchpad a `LaunchpadURLError`-Error will be raised
Line 55: Line 131:
a = BugList("https://launchpad.net/ubuntu/+source/apport/+bugs?%s" %BugList.urlopt)
print a.bugs
>>> from launchpadbugs.exceptions import LaunchpadURLError
>>> try:
... bl = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelpcxcxcver/+bugs")
... except LaunchpadURLError, e:
... print e
...
    * message: Page not found
    * url: https://bugs.launchpad.net/ubuntu/+source/bughelpcxcxcver/+bugs
Line 58: Line 140:
{{{ set([123180, 122818, 123394, 119270, 123440, 87364, 105224, 108482, 95504, 114215, 118407, 118827, 119104, 95822, 121121, 121341, 122196, 123216, 122274, 122347, 122522, 122798, 89916, 122882, 94130, 122859, 123062])
}}}
New to python-launchpad-bugs 0.3 is that this types of errors always return the url in question.
Line 61: Line 142:
=== Raising `LPUrlError` for invalid urls ===
{{{#!python
try:
    a = BugList("https://bugs.launchpad.net/ubuntu/+source/firefokkksss/+bugs")
    print len(a.bugs)
except BugList.Error.LPUrlError, e:
    print e
}}}
{{{
"'Page not found (url: https://bugs.launchpad.net/ubuntu/+source/firefokkksss/+bugs)'"
}}}
== More on custom filter functions ==
Line 73: Line 144:
=== Use custom-made filter-functions ===
{{{#!python
bl = BugList("https://bugs.launchpad.net/bughelper/+bugs")
def RFE_filter(bugs):
    result = set()
    for b in bugs:
        if b.summary.startswith("RFE"):
            result.add(b)
    return result
            

for b in bl.filter(func=[RFE_filter]).bugs:
    print "%s (%s)" %(b.summary, b.bugnumber)
}}}
{{{ RFE: Web interface to bughelper (81291)
RFE: grep for package version (84723)
}}}
Another new feature of python-launchpad-bugs 0.3 are filter functions which are able to stop the entire fetching process. Let

BugList - tutorial

This is still work in progress

General workflow

This is how to use python-launchpad-bugs to get a list of bugs

   1 >>> from launchpadbugs.connector import ConnectBugList
   2 >>> BugList = ConnectBugList() # using the html mode
   3 >>> bl = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs")

If you need a faster method to fetch the bug list but can abdicate additional information like status and importance of a bugreport it is possible to use the text mode of launchpad:

   2 >>> BugList = ConnectBugList("text") # using the text mode

In some cases, e.g. if the resulting lists should contain private bugreports, authentication is necessary

   4 >>> BugList.authentication="cookie.txt" #for text-based mozilla cookie files   or
   5 >>> BugList.authentication="cookie.sql" #for sql mozilla cookie files

It is also possible to do authentication via email-login and password. Note: This takes much longer than using cookie files, therefore python-launchpad-bugs provides a method to save the resulting cookie into a file

   7 >>> BugList.authentication={"email": "login@email.com", "passwort": "YourPassword"}
   8 >>> BugList.connection.save_cookie("/home/markus/.lpcookie")

There are currently different versions of launchpad, the stable bugs.launchpad.net and the testing environment bugs.edge.launchpad.net. Sometimes it makes sense to explicitly choose one of these versions to work with. In python-launchpad-bugs it is possible to define which version to use.

   1 >>> from launchpadbugs.lpconstants import HTTPCONNECTION
   2 >>> BugList.set_connection_mode(HTTPCONNECTION.MODE.EDGE) # or
   3 >>> BugList.set_connection_mode(HTTPCONNECTION.MODE.STABLE)

Bug list objects

BugList objects are set-like objects, each member is an instance of LPBugInfo.

   1 >>> bl
   2 <BugList https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs>
   3 >>> print bl
   4 BugList([<BugInfo 129341>,<BugInfo 88102>,<BugInfo 150887>])
   5 >>> len(bl)
   6 3

LPBugInfo

A LPBugInfo object has this attribute:

Attribute

Description

Example

.bugnumber

number of a bugreport (type of int)

.url

url to this bugreport (task specific)

.summary

one-line title of a bugreport

.importance

importance of a bugreport

.status

status of a bugreport

.sourcepackage

returns affected package within a distribution or an empty string

   1 >>> b = bl.pop()
   2 >>> b
   3 <BugInfo 239007>
   4 >>> print b
   5 [Bug 239007 : Confirmed/Undecided]
   6 >>> int(b)
   7 239007

Adding some (upstream) bugs to the set

It is easy to merge two BugList-objects

   1 >>> bl
   2 <BugList https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs>
   3 >>> bl += BugList("https://bugs.launchpad.net/bughelper/+bugs")
   4 >>> len(bl)
   5 14

Filtering bug lists

With python-launchpad-bugs 0.3 there is a new way of filtering bug lists. First of all: there are two different ways of filtering

  • Filtering while fetching the list
  • Filtering the actual object

The way mentioned by the last item can easily be done by using python's buildin filter() function and does not change the actual object.BR In contrast the first way is irreversible. It is possible to use URL-based filter options (options provided by advanced-search of launchpad) or functions to filter elements. This functions take an element of the bug list as the only argument and return either False or an instance of LPBugInfo or LPBug. If False is returned the related element is filtered out of the list.

As a very basic example let's have a look at all bugs in the bughelper project which have an even bugnumber and which importance is either "Medium" or "Low"

   1 >>> from launchpadbugs.basebuglistfilter import URLBugListFilter
   2 >>> bug_filter = URLBugListFilter()
   3 >>> bug_filter.add_option("importance", ("Medium", "Low"))
   4 >>> bug_filter.functions.append(lambda x: not int(x) % 2 and x)
   5 >>> bl =  BugList(bug_filter("https://bugs.launchpad.net/bughelper/+bugs"))
   6 >>> print bl
   7 BugList([<BugInfo 131378>,<BugInfo 88102>])

Sorting the list of bugs

LPBugList objects do also have a .sort(<key>) method which returns a sorted list. <key> could be nr, status or importance with an optional leading - for reverse order.

   1 >>> bl =  BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs")
   2 >>> print [str(i) for i in bl]
   3 ['[Bug 239007 : Confirmed/Undecided]', '[Bug 129341 : New/Wishlist]', '[Bug 88102 : Confirmed/Undecided]', '[Bug 150887 : In Progress/Wishlist]']
   4 >>> print [str(i) for i in bl.sort("-status")]
   5 ['[Bug 129341 : New/Wishlist]', '[Bug 239007 : Confirmed/Undecided]', '[Bug 88102 : Confirmed/Undecided]', '[Bug 150887 : In Progress/Wishlist]']

Raised Exeptions

If the url given as an argument to the buglist is not valid in launchpad a LaunchpadURLError-Error will be raised

   1 >>> from launchpadbugs.exceptions import LaunchpadURLError
   2 >>> try:
   3 ...     bl =  BugList("https://bugs.launchpad.net/ubuntu/+source/bughelpcxcxcver/+bugs")
   4 ... except LaunchpadURLError, e:
   5 ...     print e
   6 ... 
   7     * message: Page not found
   8     * url: https://bugs.launchpad.net/ubuntu/+source/bughelpcxcxcver/+bugs

New to python-launchpad-bugs 0.3 is that this types of errors always return the url in question.

More on custom filter functions

Another new feature of python-launchpad-bugs 0.3 are filter functions which are able to stop the entire fetching process. Let


Go Back to [:BugHelper/Dev].BR CategoryBugHelper

BugHelper/Dev/python-launchpad-bugs/BugList (last edited 2008-08-06 17:01:38 by localhost)