Merge lp:~benji/launchpad/add-launchpadlib-examples into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Leonard Richardson
Approved revision: no longer in the source branch.
Merged at revision: 11852
Proposed branch: lp:~benji/launchpad/add-launchpadlib-examples
Merge into: lp:launchpad
Diff against target: 123 lines (+75/-6)
4 files modified
lib/lp/bugs/interfaces/bugattachment.py (+28/-1)
lib/lp/bugs/interfaces/bugtracker.py (+18/-1)
lib/lp/registry/interfaces/distribution.py (+13/-1)
lib/lp/registry/interfaces/person.py (+16/-3)
To merge this branch: bzr merge lp:~benji/launchpad/add-launchpadlib-examples
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Review via email: mp+39845@code.launchpad.net

Description of the change

Integrate the examples added to the launchpadlib docs by https://launchpad.net/arsenal.

The reStructured Text is somewhat simplistic, but it's what our stack can handle at the moment.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

This looks good with one exception. The example starting on line 19 shows how to use the HostedFile class. It doesn't belong in the documentation for the Launchpad web service: it (or something equivalent) should show up when you run help() on a HostedFile object.

review: Needs Fixing
Revision history for this message
Benji York (benji) wrote :

> This looks good with one exception. The example starting on line 19
> shows how to use the HostedFile class. It doesn't belong in the
> documentation for the Launchpad web service: it (or something
> equivalent) should show up when you run help() on a HostedFile object.

I replaced that bit with a note to the user about finding information
about the HostedFile object in the lazr.restfulclient documentation.

Revision history for this message
Leonard Richardson (leonardr) wrote :

It seems like if we're going to put that cross-reference in one place, we should mention it for every single link to a hosted file. But since the goal here is simple cleanup, and this is definitely an improvement, (and I don't actually want to mention it every single time) I'm not going to press the issue. Let's see how users respond and take it from there.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/bugs/interfaces/bugattachment.py'
--- lib/lp/bugs/interfaces/bugattachment.py 2010-09-03 19:32:28 +0000
+++ lib/lp/bugs/interfaces/bugattachment.py 2010-11-02 19:57:57 +0000
@@ -66,7 +66,34 @@
6666
6767
68class IBugAttachment(IHasBug):68class IBugAttachment(IHasBug):
69 """A file attachment to an IBug."""69 """A file attachment to an IBug.
70
71 Launchpadlib example of accessing content of an attachment::
72
73 for attachment in bug.attachments:
74 buffer = attachment.data.open()
75 for line in buffer:
76 print line
77 buffer.close()
78
79 Launchpadlib example of accessing metadata about an attachment::
80
81 attachment = bug.attachments[0]
82 print "title:", attachment.title
83 print "ispatch:", attachment.type
84
85 For information about the file-like object returned by
86 attachment.data.open() see lazr.restfulclient's documentation of the
87 HostedFile object.
88
89 Details about the message associated with an attachment can be found on
90 the "message" attribute::
91
92 message = attachment.message
93 print "subject:", message.subject.encode('utf-8')
94 print "owner:", message.owner.display_name.encode('utf-8')
95 print "created:", message.date_created
96 """
70 export_as_webservice_entry()97 export_as_webservice_entry()
7198
72 id = Int(title=_('ID'), required=True, readonly=True)99 id = Int(title=_('ID'), required=True, readonly=True)
73100
=== modified file 'lib/lp/bugs/interfaces/bugtracker.py'
--- lib/lp/bugs/interfaces/bugtracker.py 2010-09-29 21:18:47 +0000
+++ lib/lp/bugs/interfaces/bugtracker.py 2010-11-02 19:57:57 +0000
@@ -200,7 +200,24 @@
200200
201201
202class IBugTracker(Interface):202class IBugTracker(Interface):
203 """A remote bug system."""203 """A remote bug system.
204
205 Launchpadlib example: What bug tracker is used for a distro source
206 package?
207
208 ::
209
210 product = source_package.upstream_product
211 if product:
212 tracker = product.bug_tracker
213 if not tracker:
214 project = product.project_group
215 if project:
216 tracker = project.bug_tracker
217 if tracker:
218 print "%s at %s" %(tracker.bug_tracker_type, tracker.base_url)
219
220 """
204 export_as_webservice_entry()221 export_as_webservice_entry()
205222
206 id = Int(title=_('ID'))223 id = Int(title=_('ID'))
207224
=== modified file 'lib/lp/registry/interfaces/distribution.py'
--- lib/lp/registry/interfaces/distribution.py 2010-10-29 10:01:34 +0000
+++ lib/lp/registry/interfaces/distribution.py 2010-11-02 19:57:57 +0000
@@ -626,7 +626,19 @@
626class IDistribution(626class IDistribution(
627 IDistributionEditRestricted, IDistributionPublic, IHasBugSupervisor,627 IDistributionEditRestricted, IDistributionPublic, IHasBugSupervisor,
628 IRootContext, IStructuralSubscriptionTarget):628 IRootContext, IStructuralSubscriptionTarget):
629 """An operating system distribution."""629 """An operating system distribution.
630
631 Launchpadlib example: retrieving the current version of a package in a
632 particular distroseries.
633
634 ::
635
636 ubuntu = launchpad.distributions["ubuntu"]
637 archive = ubuntu.main_archive
638 series = ubuntu.current_series
639 print archive.getPublishedSources(exact_match=True,
640 source_name="apport", distro_series=series)[0].source_package_version
641 """
630 export_as_webservice_entry()642 export_as_webservice_entry()
631643
632644
633645
=== modified file 'lib/lp/registry/interfaces/person.py'
--- lib/lp/registry/interfaces/person.py 2010-11-02 06:21:58 +0000
+++ lib/lp/registry/interfaces/person.py 2010-11-02 19:57:57 +0000
@@ -1714,9 +1714,22 @@
17141714
17151715
1716class ITeam(IPerson, ITeamPublic):1716class ITeam(IPerson, ITeamPublic):
1717 """ITeam extends IPerson.1717 """A group of people and other teams.
17181718
1719 The teamowner should never be None.1719 Launchpadlib example of getting the date a user joined a team::
1720
1721 def get_join_date(team, user):
1722 team = launchpad.people[team]
1723 members = team.members_details
1724 for member in members:
1725 if member.member.name == user:
1726 return member.date_joined
1727 return None
1728
1729 Implementation notes:
1730
1731 - ITeam extends IPerson.
1732 - The teamowner should never be None.
1720 """1733 """
1721 export_as_webservice_entry('team')1734 export_as_webservice_entry('team')
17221735