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
1=== modified file 'lib/lp/bugs/interfaces/bugattachment.py'
2--- lib/lp/bugs/interfaces/bugattachment.py 2010-09-03 19:32:28 +0000
3+++ lib/lp/bugs/interfaces/bugattachment.py 2010-11-02 19:57:57 +0000
4@@ -66,7 +66,34 @@
5
6
7 class IBugAttachment(IHasBug):
8- """A file attachment to an IBug."""
9+ """A file attachment to an IBug.
10+
11+ Launchpadlib example of accessing content of an attachment::
12+
13+ for attachment in bug.attachments:
14+ buffer = attachment.data.open()
15+ for line in buffer:
16+ print line
17+ buffer.close()
18+
19+ Launchpadlib example of accessing metadata about an attachment::
20+
21+ attachment = bug.attachments[0]
22+ print "title:", attachment.title
23+ print "ispatch:", attachment.type
24+
25+ For information about the file-like object returned by
26+ attachment.data.open() see lazr.restfulclient's documentation of the
27+ HostedFile object.
28+
29+ Details about the message associated with an attachment can be found on
30+ the "message" attribute::
31+
32+ message = attachment.message
33+ print "subject:", message.subject.encode('utf-8')
34+ print "owner:", message.owner.display_name.encode('utf-8')
35+ print "created:", message.date_created
36+ """
37 export_as_webservice_entry()
38
39 id = Int(title=_('ID'), required=True, readonly=True)
40
41=== modified file 'lib/lp/bugs/interfaces/bugtracker.py'
42--- lib/lp/bugs/interfaces/bugtracker.py 2010-09-29 21:18:47 +0000
43+++ lib/lp/bugs/interfaces/bugtracker.py 2010-11-02 19:57:57 +0000
44@@ -200,7 +200,24 @@
45
46
47 class IBugTracker(Interface):
48- """A remote bug system."""
49+ """A remote bug system.
50+
51+ Launchpadlib example: What bug tracker is used for a distro source
52+ package?
53+
54+ ::
55+
56+ product = source_package.upstream_product
57+ if product:
58+ tracker = product.bug_tracker
59+ if not tracker:
60+ project = product.project_group
61+ if project:
62+ tracker = project.bug_tracker
63+ if tracker:
64+ print "%s at %s" %(tracker.bug_tracker_type, tracker.base_url)
65+
66+ """
67 export_as_webservice_entry()
68
69 id = Int(title=_('ID'))
70
71=== modified file 'lib/lp/registry/interfaces/distribution.py'
72--- lib/lp/registry/interfaces/distribution.py 2010-10-29 10:01:34 +0000
73+++ lib/lp/registry/interfaces/distribution.py 2010-11-02 19:57:57 +0000
74@@ -626,7 +626,19 @@
75 class IDistribution(
76 IDistributionEditRestricted, IDistributionPublic, IHasBugSupervisor,
77 IRootContext, IStructuralSubscriptionTarget):
78- """An operating system distribution."""
79+ """An operating system distribution.
80+
81+ Launchpadlib example: retrieving the current version of a package in a
82+ particular distroseries.
83+
84+ ::
85+
86+ ubuntu = launchpad.distributions["ubuntu"]
87+ archive = ubuntu.main_archive
88+ series = ubuntu.current_series
89+ print archive.getPublishedSources(exact_match=True,
90+ source_name="apport", distro_series=series)[0].source_package_version
91+ """
92 export_as_webservice_entry()
93
94
95
96=== modified file 'lib/lp/registry/interfaces/person.py'
97--- lib/lp/registry/interfaces/person.py 2010-11-02 06:21:58 +0000
98+++ lib/lp/registry/interfaces/person.py 2010-11-02 19:57:57 +0000
99@@ -1714,9 +1714,22 @@
100
101
102 class ITeam(IPerson, ITeamPublic):
103- """ITeam extends IPerson.
104-
105- The teamowner should never be None.
106+ """A group of people and other teams.
107+
108+ Launchpadlib example of getting the date a user joined a team::
109+
110+ def get_join_date(team, user):
111+ team = launchpad.people[team]
112+ members = team.members_details
113+ for member in members:
114+ if member.member.name == user:
115+ return member.date_joined
116+ return None
117+
118+ Implementation notes:
119+
120+ - ITeam extends IPerson.
121+ - The teamowner should never be None.
122 """
123 export_as_webservice_entry('team')
124