Bug

Differences between revisions 2 and 3
Revision 2 as of 2007-07-24 14:23:56
Size: 1014
Editor: a89-182-217-41
Comment:
Revision 3 as of 2007-07-24 14:52:25
Size: 2303
Editor: a89-182-217-41
Comment:
Deletions are marked like this. Additions are marked like this.
Line 33: Line 33:
>>> print bug.attachments
[<Attachment (up: #8554243), (down: /home/markus/.bughelper/attachments-cache/buglog-data/120593/8554243/79140.patch)>, <Attachment (up: #8558770)>, <Attachment (up: #8554203)>, <Attachment (up: #8541039)>]
>>> for a in bug.attachments:
... print a
...
<Attachment (up: 8554243), (down: ../buglog-data/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.

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([i for i in bug.attachments.filter(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: ../buglog-data/120593/8554243/79140.patch)>
<Attachment (up: 8558770)>
<Attachment (up: 8554203)>
<Attachment (down: <path-to-file>/79140.patch)>

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 >>> import launchpadbugs.connector as Connector
   2 >>> Bug = Connector.ConnectBug()
   3 >>> bug = Bug(120593)

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

   3 >>> bug = Bug("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:

   4 >>> Bug.authentication="cookie.txt"

Attributes of a bugreport

Overview

add a table of all attributes

Attachments

Get a list of attachments:

   5 >>> for a in bug.attachments:
   6 ...     print a
   7 ... 
   8 <Attachment (up: 8554243), (down: ../buglog-data/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.

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([i for i in bug.attachments.filter(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: ../buglog-data/120593/8554243/79140.patch)>
  32 <Attachment (up: 8558770)>
  33 <Attachment (up: 8554203)>
  34 <Attachment (down: <path-to-file>/79140.patch)>

Comments

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