Bug

Differences between revisions 1 and 24 (spanning 23 versions)
Revision 1 as of 2007-07-24 14:14:29
Size: 643
Editor: a89-182-217-41
Comment: started this tutorial
Revision 24 as of 2008-08-04 10:52:26
Size: 8844
Editor: a89-182-195-225
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
||<tablestyle="float:right; font-size: 0.9em; width:40%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;">'''Contents'''[[BR]][[TableOfContents]]||
Line 7: Line 9:
>>> import launchpadbugs.connector as Connector
>>> Bug = Connector.ConnectBug()
>>> bug = Bug(126927)
>>> from launchpadbugs.connector import ConnectBug
>>> Bug = ConnectBug() # using the html mode of launchpad
>>> bug = Bug(120593)
}}}

This will give you read-write access to a bugreport, but if you are looking for a faster but read-only method you can also use:

{{{#!python start=2
>>> Bug = ConnectBug("text") # using the text mode of launchpad
Line 14: Line 22:
{{{#!python start=3
>>> bug = Bug("https://bugs.launchpad.net/buglog-data/+bug/126927")
{{{#!python start=4
>>> bug = Bug(url="https://bugs.launchpad.net/buglog-data/+bug/120593")
Line 20: Line 28:
{{{#!python start=4
>>> Bug.authentication="cookie.txt"
}}}
{{{#!python start=5
>>> Bug.authentication="cookie.txt" #for text-based mozilla cookie files or
>>> Bug.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, therefor python-launchpad-bugs provides a method to save the resulting cookie into a file

{{{#!python start=7
>>> Bug.authentication={"email": "login@email.com", "passwort": "YourPassword"}
>>> Bug.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
>>> b = Bug(123456)
>>> b.url
'https://bugs.launchpad.net/ubuntu/+source/xine-lib/+bug/123456'
>>> Bug.set_connection_mode(HTTPCONNECTION.MODE.EDGE)
>>> b = Bug(123456)
>>> b.url
'https://bugs.edge.launchpad.net/ubuntu/+source/xine-lib/+bug/123456'
}}}
Line 27: Line 56:

||'''Attribute'''||'''Description'''||'''Example'''||
||.activity||Activity Log of a bugreport (type: list)|| [#activity] ||
||.assignee||Person assigned to a bugreport (type: user)|| [#user] ||
||.attachments||List of attachments|| [#attachments] ||
||.branches||List of bzr branches (only available in html mode) || ||
||.bugnumber||Number of a bugreport (type: int)|| ||
||.changed||List of local changes to a bugreport|| [#changed] ||
||.comments||List of comments|| [#comments] ||
||.date|| || ||
||.description|| || ||
||.duplicate_of|| || ||
||.duplicates||List of duplicates of a bug|| ||
||.get_subscriptions_category||Subscribers broken into 'directly', 'notified', and 'duplicates'|| ||
||.importance|| || ||
||.info|| || ||
||.infotable|| || [#tasks] ||
||.milestone|| || ||
||.nickname|| || ||
||.private|| || ||
||.reporter|| || ||
||.security|| || ||
||.sourcepackage|| || ||
||.status|| || ||
||.subscriptions||All subscribers|| ||
||.summary|| || ||
||.tags|| || ||
||.target|| || ||
||.text|| || ||
||.title|| || ||
||.url|| || ||

=== Activity Log ===

[[Anchor(activity)]] Get the Activity Log:

{{{#!python start=5
>>> print b.activity[:3] #slice the list so it's more readable
[<thekorn 2007-06-15 16:29:00 UTC 'bug'>, <thekorn 2007-06-15 18:41:00 UTC 'description'>, <thekorn 2007-07-18 07:38:00 UTC 'name'>]
}}}

Members of this list have the following attributes:
 * .date, datetime object indicating the time of the change
 * .user, lphelper.user object
 * .what, string saying what changed
 * .old_value. of type str
 * .new_value, of type str
 * .message, of type str

=== Attachments ===

[[Anchor(attachments)]] Get a list of attachments:

{{{#!python start=5
>>> for a in bug.attachments:
... print a
...
<Attachment (up: 8554243), (down: <path-to-file>/120593/8554243/79140.patch)>
<Attachment (up: 8558770)>
<Attachment (up: 8554203)>
<Attachment (up: 8541039)>
}}}

As you can see there are four files attached to the bug and the first attachment has already been downloaded.

There are two ways of downloading an attachment:

{{{#!python start=7
>>> bug.attachments[0].text #this will get the content and
                            # download the file to
                            # ~/.bughelper/attachments-cache/<package>/<bugnumber>/<attachment_id>/<filename>
'content of the file'
>>> bug.attachments[0].download("/tmp/filename.ext") #this will download the file to /tmp/filename.ext
}}}

You can for example filter the list of attachments by the filename:

{{{#!python start=12
>>> def test_filter(a):
... import re
... return re.match("assignee.*", a.lp_filename)
...
>>> [i for i in bug.attachments.filter(test_filter)]
[<Attachment (up: 8541039)>]
>>> bug.attachments[8541039].lp_filename
'assignee.patch'
}}}

These filtered attachments can be easily removed:

{{{#!python start=20
>>> bug.attachments.remove(func=test_filter)
True
}}}

To add an attachment you have to create an new attachment-object:

{{{#!python start=22
>>> attachment = Bug.NewAttachment(localfilename="<path-to-file>/79140.patch")
>>> attachment.description = "example patch"
>>> attachment.is_patch = True
>>> attachment
<Attachment (down: <path-to-file>/79140.patch)>
}}}

Now you have to add this attachment to the bugreport:

{{{#!python start=27
>>> bug.attachments.add(attachment)
>>> for a in bug.attachments:
... print a
...
<Attachment (up: 8554243), (down: <path-to-file>/120593/8554243/79140.patch)>
<Attachment (up: 8558770)>
<Attachment (up: 8554203)>
<Attachment (down: <path-to-file>/79140.patch)>
}}}

=== Comments ===

[[Anchor(comments)]] Get a list of comments:
{{{#!python start=35
>>> [c for c in bug.comments][0:2]
[<Comment 1 by thekorn on 2007-07-20>, <Comment 2 by thekorn on 2007-07-20>]
}}}

Create a new comment and add this comment to the bugreport:
{{{#!python start=37
>>> comment = Bug.NewComment(text="this is a test comment",subject="test comment")
>>> bug.comments.add(comment)
>>> [c for c in bug.comments]
[<Comment 1 by thekorn on 2007-07-20>, <Comment 2 by thekorn on 2007-07-20>, ... , <Comment 'unknown'>]
}}}

=== Tasks ===

[[Anchor(tasks)]] Create a new task:
{{{#!python
>>> import launchpadbugs.connector as con
>>> Bug = con.ConnectBug()
>>> Bug.authentication = "cookies.sqlite"
>>> task = Bug.NewTask("project", "bzr-fs")
>>> b = Bug(214490)
>>> b.infotable.addTask(task)
>>> b.commit()
}}}

=== User ===

[[Anchor(user)]] User are String-like objects with an additional attribute `.realname`.[[BR]]
{{{#!python
>>> str(bug.assignee)
'thekorn'
>>> repr(bug.assignee)
'<user thekorn (Markus Korn)>'
>>> bug.assignee.realname
'Markus Korn'
}}}

== Commit changes ==

=== get a list of changes ===

[[Anchor(changed)]] {{{#!python start=41
>>> for i in bug.changed:
... print i
...
(<Attachmentlist> changed: (<Attachment (up: 8541039)> deleted), (<Attachment (down: <path-to-file>/79140.patch)> added))
(<Commentslist> changed: (<Comment 'unknown'> added))
}}}

=== commit changes ===
{{{#!python start=46
>>> bug.commit()
}}}

There are two possible arguments to `.commit()`:
 * `force_changes=<bool>`:
  * `False (default)`:
  * `True`: ''Example:'' If a user tries to add a tag `foo` to a bugreport and `foo` s not a tag in this product yet, launchpad will raise an error. If this option is set to `True` `foo` will be added to the list of tags to this project and than added to this bugreport.
 * `ignore_lp_errors=<bool>`:
  * `True (default)`: ignores launchpad processing errors
  * `False`: raises a `ValueError` if launchpad is unable to change a value

== Filing a bug report ==

{{{#!python
bug = Bug.New(product={"name": "python-launchpad-bugs"},
    summary="RFE: Add function to create a new bugreport",
    description="""It would be nice if a user could create a bugreport via a script using python-launchpad-bugs.

Markus""")
}}}

 * product is a dictionary like `{"name": <lpname of the product>, "target": <distribution>}`
  * `product={"name": "python-launchpad-bugs"}` creates a bug in https://bugs.launchpad.net/python-launchpad-bugs/
  * `product={"name": "python-launchpad-bugs", "target": "ubuntu"}` creates a bug in https://bugs.launchpad.net/ubuntu/+source/python-launchpad-bugs/
  * `product={"name": "ubuntu"}` creates a bug in https://bugs.launchpad.net/ubuntu/ (bug in "ubuntu" without a sourcepackage)
 * other optional arguments to `.New()`:
  * tags: list of tags like `["foo", "bar"]`
  * `security_related` (default: `False`)

Bug - tutorial

General workflow

That is the way to use python-launchpad-bugs to get information on a bugreport or to edit a bugreport:

   1 >>> from launchpadbugs.connector import ConnectBug
   2 >>> Bug = ConnectBug() # using the html mode of launchpad
   3 >>> bug = Bug(120593)

This will give you read-write access to a bugreport, but if you are looking for a faster but read-only method you can also use:

   2 >>> Bug = ConnectBug("text") # using the text mode of launchpad

It is also possible to get a bugreport by its url:

   4 >>> bug = Bug(url="https://bugs.launchpad.net/buglog-data/+bug/120593")

If you want to change the bugreport or view private bugs you have to set Bug.authentication:

   5 >>> Bug.authentication="cookie.txt" #for text-based mozilla cookie files   or
   6 >>> Bug.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, therefor python-launchpad-bugs provides a method to save the resulting cookie into a file

   7 >>> Bug.authentication={"email": "login@email.com", "passwort": "YourPassword"}
   8 >>> Bug.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 >>> b = Bug(123456)
   3 >>> b.url
   4 'https://bugs.launchpad.net/ubuntu/+source/xine-lib/+bug/123456'
   5 >>> Bug.set_connection_mode(HTTPCONNECTION.MODE.EDGE)
   6 >>> b = Bug(123456)
   7 >>> b.url
   8 'https://bugs.edge.launchpad.net/ubuntu/+source/xine-lib/+bug/123456'

Attributes of a bugreport

Overview

Attribute

Description

Example

.activity

Activity Log of a bugreport (type: list)

[#activity]

.assignee

Person assigned to a bugreport (type: user)

[#user]

.attachments

List of attachments

[#attachments]

.branches

List of bzr branches (only available in html mode)

.bugnumber

Number of a bugreport (type: int)

.changed

List of local changes to a bugreport

[#changed]

.comments

List of comments

[#comments]

.date

.description

.duplicate_of

.duplicates

List of duplicates of a bug

.get_subscriptions_category

Subscribers broken into 'directly', 'notified', and 'duplicates'

.importance

.info

.infotable

[#tasks]

.milestone

.nickname

.private

.reporter

.security

.sourcepackage

.status

.subscriptions

All subscribers

.summary

.tags

.target

.text

.title

.url

Activity Log

Anchor(activity) Get the Activity Log:

   5 >>> print b.activity[:3] #slice the list so it's more readable
   6 [<thekorn 2007-06-15 16:29:00 UTC 'bug'>, <thekorn 2007-06-15 18:41:00 UTC 'description'>, <thekorn 2007-07-18 07:38:00 UTC 'name'>]

Members of this list have the following attributes:

  • .date, datetime object indicating the time of the change
  • .user, lphelper.user object
  • .what, string saying what changed
  • .old_value. of type str
  • .new_value, of type str
  • .message, of type str

Attachments

Anchor(attachments) Get a list of attachments:

   5 >>> for a in bug.attachments:
   6 ...     print a
   7 ... 
   8 <Attachment (up: 8554243), (down: <path-to-file>/120593/8554243/79140.patch)>
   9 <Attachment (up: 8558770)>
  10 <Attachment (up: 8554203)>
  11 <Attachment (up: 8541039)>

As you can see there are four files attached to the bug and the first attachment has already been downloaded.

There are two ways of downloading an attachment:

   7 >>> bug.attachments[0].text #this will get the content and
   8                             # download the file to
   9                             # ~/.bughelper/attachments-cache/<package>/<bugnumber>/<attachment_id>/<filename>
  10 'content of the file'
  11 >>> bug.attachments[0].download("/tmp/filename.ext") #this will download the file to /tmp/filename.ext

You can for example filter the list of attachments by the filename:

  12 >>> def test_filter(a):
  13 ...     import re
  14 ...     return re.match("assignee.*", a.lp_filename)
  15 ... 
  16 >>> [i for i in bug.attachments.filter(test_filter)]
  17 [<Attachment (up: 8541039)>]
  18 >>> bug.attachments[8541039].lp_filename
  19 'assignee.patch'

These filtered attachments can be easily removed:

  20 >>> bug.attachments.remove(func=test_filter)
  21 True

To add an attachment you have to create an new attachment-object:

  22 >>> attachment = Bug.NewAttachment(localfilename="<path-to-file>/79140.patch")
  23 >>> attachment.description = "example patch"
  24 >>> attachment.is_patch = True
  25 >>> attachment
  26 <Attachment (down: <path-to-file>/79140.patch)>

Now you have to add this attachment to the bugreport:

  27 >>> bug.attachments.add(attachment)
  28 >>> for a in bug.attachments:
  29 ...     print a
  30 ... 
  31 <Attachment (up: 8554243), (down: <path-to-file>/120593/8554243/79140.patch)>
  32 <Attachment (up: 8558770)>
  33 <Attachment (up: 8554203)>
  34 <Attachment (down: <path-to-file>/79140.patch)>

Comments

Anchor(comments) Get a list of comments:

  35 >>> [c for c in bug.comments][0:2]
  36 [<Comment 1 by thekorn on 2007-07-20>, <Comment 2 by thekorn on 2007-07-20>]

Create a new comment and add this comment to the bugreport:

  37 >>> comment = Bug.NewComment(text="this is a test comment",subject="test comment")
  38 >>> bug.comments.add(comment)
  39 >>> [c for c in bug.comments]
  40 [<Comment 1 by thekorn on 2007-07-20>, <Comment 2 by thekorn on 2007-07-20>, ... , <Comment 'unknown'>]

Tasks

Anchor(tasks) Create a new task:

   1 >>> import launchpadbugs.connector as con
   2 >>> Bug = con.ConnectBug()
   3 >>> Bug.authentication = "cookies.sqlite"
   4 >>> task = Bug.NewTask("project", "bzr-fs")
   5 >>> b = Bug(214490)
   6 >>> b.infotable.addTask(task)
   7 >>> b.commit()

User

Anchor(user) User are String-like objects with an additional attribute .realname.BR

   1 >>> str(bug.assignee)
   2 'thekorn'
   3 >>> repr(bug.assignee)
   4 '<user thekorn (Markus Korn)>'
   5 >>> bug.assignee.realname
   6 'Markus Korn'

Commit changes

get a list of changes

Anchor(changed)

  41 >>> for i in bug.changed:
  42 ...     print i
  43 ... 
  44 (<Attachmentlist> changed: (<Attachment (up: 8541039)> deleted), (<Attachment (down: <path-to-file>/79140.patch)> added))
  45 (<Commentslist> changed: (<Comment 'unknown'> added))

commit changes

  46 >>> bug.commit()

There are two possible arguments to .commit():

  • force_changes=<bool>:

    • False (default):

    • True: Example: If a user tries to add a tag foo to a bugreport and foo s not a tag in this product yet, launchpad will raise an error. If this option is set to True foo will be added to the list of tags to this project and than added to this bugreport.

  • ignore_lp_errors=<bool>:

    • True (default): ignores launchpad processing errors

    • False: raises a ValueError if launchpad is unable to change a value

Filing a bug report

   1 bug = Bug.New(product={"name": "python-launchpad-bugs"},
   2     summary="RFE: Add function to create a new bugreport",
   3     description="""It would be nice if a user could create a bugreport via a script using python-launchpad-bugs.
   4 
   5 Markus""")

BugHelper/Dev/python-launchpad-bugs/Bug (last edited 2008-08-12 22:24:51 by c-24-21-234-111)