BugList

Differences between revisions 1 and 14 (spanning 13 versions)
Revision 1 as of 2007-07-02 08:16:26
Size: 1301
Editor: vpn126
Comment:
Revision 14 as of 2008-07-03 12:48:30
Size: 4874
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
## page was renamed from BugHelper/Dev/python-launchpad-bugs/API changes/BugList example
||<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 2: Line 8:
= Example usage of BugList =
Line 4: Line 9:
''' Usage of `LaunchpadConnector` and setting authentification: '''
{{{ import launchpadBugs.Connector as Connector
== General workflow ==
Line 7: Line 11:
BugList = Connector.ConnectBugList()
BugList.authentification = "cookie.txt"
This is how to use python-launchpad-bugs to get a list of bugs

{{{#!python
>>> from launchpadbugs.connector import ConnectBugList
>>> BugList = ConnectBugList() # using the html mode
>>> bl = BugList("https://bugs.launchpad.net/ubuntu/+source/bughelper/+bugs")
Line 11: Line 19:
''' Getting a list of bugs and print available information: '''
{{{ l = bl.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
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
Line 22: Line 25:
''' Adding some (upstream) bugs to the set '''
{{{ l += bl.BugList("https://bugs.launchpad.net/bughelper/+bugs")
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.

{{{#!python
>>> 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
}}}

=== 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
}}}


=== Adding some (upstream) bugs to the set ===
{{{#!python
l += BugList("https://bugs.launchpad.net/bughelper/+bugs")
Line 26: Line 88:
{{{ set([109628, 110937, 88521, 88102, 84723, 88102, 81291, 85152, 88521, 90084, 109547])
}}}
Line 27: Line 91:
''' Setting a filter and filter the set of bugs '''
{{{ bl.set_filter(minbug=100000, filterbug="117701,109628", status="New")
=== Setting a filter and filter the set of bugs ===
{{{#!python
BugList
.set_filter(minbug=100000, filterbug="117701,109628", status="New")
Line 32: Line 97:
{{{ set([110937, 109547])
}}}
Line 33: Line 100:
''' add LP urloptions to an url '''
{{{ a = bl.
BugList("https://launchpad.net/ubuntu/+source/apport/+bugs?%s" %bl.URLOPT)
=== Sorting the list of bugs ===
{{{#!python
print l.sort("nr")
}}}
{{{ [109547, 110937]
}}}

===
add LP urloptions to an url ===
{{{#!python
a =
BugList("https://launchpad.net/ubuntu/+source/apport/+bugs?%s" %BugList.urlopt)
Line 37: Line 112:

''' Sorting the list of bugs '''
{{{ print l.sort("nr")
{{{ 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])
Line 42: Line 115:
''' Raising LPUrlError for invalid urls '''
{{{ try:
    a = bl.BugList("https://bugs.launchpad.net/ubuntu/+source/firefokkksss/+bugs")
=== Raising `LPUrlError` for invalid urls ===
{{{#!python
try:
    a = BugList("https://bugs.launchpad.net/ubuntu/+source/firefokkksss/+bugs")
Line 46: Line 120:
except bl.LPURLERROR, e: except BugList.Error.LPUrlError, e:
Line 49: Line 123:
{{{
"'Page not found (url: https://bugs.launchpad.net/ubuntu/+source/firefokkksss/+bugs)'"
}}}

=== 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)
}}}

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

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

   1 l += BugList("https://bugs.launchpad.net/bughelper/+bugs")
   2 print l.bugs

{{{ set([109628, 110937, 88521, 88102, 84723, 88102, 81291, 85152, 88521, 90084, 109547]) }}}

Setting a filter and filter the set of bugs

   1 BugList.set_filter(minbug=100000, filterbug="117701,109628", status="New")
   2 l = l.filter()
   3 print l.bugs

{{{ set([110937, 109547]) }}}

Sorting the list of bugs

   1 print l.sort("nr")

{{{ [109547, 110937] }}}

add LP urloptions to an url

   1 a = BugList("https://launchpad.net/ubuntu/+source/apport/+bugs?%s" %BugList.urlopt)
   2 print a.bugs

{{{ 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]) }}}

Raising `LPUrlError` for invalid urls

   1 try:
   2     a = BugList("https://bugs.launchpad.net/ubuntu/+source/firefokkksss/+bugs")
   3     print len(a.bugs)
   4 except BugList.Error.LPUrlError, e:
   5     print e

"'Page not found (url: https://bugs.launchpad.net/ubuntu/+source/firefokkksss/+bugs)'"

Use custom-made filter-functions

   1 bl = BugList("https://bugs.launchpad.net/bughelper/+bugs")
   2 def RFE_filter(bugs):
   3     result = set()
   4     for b in bugs:
   5         if b.summary.startswith("RFE"):
   6             result.add(b)
   7     return result
   8             
   9 
  10 for b in bl.filter(func=[RFE_filter]).bugs:
  11     print "%s (%s)" %(b.summary, b.bugnumber)

{{{ RFE: Web interface to bughelper (81291) RFE: grep for package version (84723) }}}


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

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