~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
=========================
Binary Package Publishing
=========================

Binary package publishing details are available via a custom operation on
archives, getPublishedBinaries().

    >>> cprov_archive = webservice.get("/~cprov/+archive/ppa").jsonBody()
    >>> pubs = webservice.named_get(
    ...     cprov_archive['self_link'], 'getPublishedBinaries').jsonBody()

    >>> def print_publications(pubs):
    ...     for display_name in sorted(
    ...         entry['display_name'] for entry in pubs['entries']):
    ...         print display_name

    >>> print_publications(pubs)
    mozilla-firefox 1.0 in warty hppa
    mozilla-firefox 1.0 in warty i386
    pmount 0.1-1 in warty hppa
    pmount 0.1-1 in warty i386

getPublishedBinaries() can accept some optional filtering parameters to reduce
the number of returned publications.

Search by name and version using an exact match:

    >>> pubs = webservice.named_get(
    ...     cprov_archive['self_link'], 'getPublishedBinaries',
    ...     binary_name="pmount", version="0.1-1",
    ...     exact_match=True).jsonBody()
    >>> print_publications(pubs)
    pmount 0.1-1 in warty hppa
    pmount 0.1-1 in warty i386

Search by publishing status:

    >>> pubs = webservice.named_get(
    ...     cprov_archive['self_link'], 'getPublishedBinaries',
    ...     status="Published").jsonBody()
    >>> print_publications(pubs)
    mozilla-firefox 1.0 in warty hppa
    mozilla-firefox 1.0 in warty i386
    pmount 0.1-1 in warty hppa
    pmount 0.1-1 in warty i386

Search by distroseries and pocket:

    >>> distros = webservice.get("/distros").jsonBody()
    >>> ubuntu = distros['entries'][0]
    >>> warty = webservice.named_get(
    ...     ubuntu['self_link'], 'getSeries',
    ...     name_or_version='warty').jsonBody()

    >>> pubs = webservice.named_get(
    ...     cprov_archive['self_link'], 'getPublishedBinaries',
    ...     distro_series=warty['self_link'], pocket="Release").jsonBody()
    >>> print_publications(pubs)
    mozilla-firefox 1.0 in warty hppa
    mozilla-firefox 1.0 in warty i386
    pmount 0.1-1 in warty hppa
    pmount 0.1-1 in warty i386

Each binary publication exposes a number of properties:

    >>> from lazr.restful.testing.webservice import pprint_entry
    >>> pprint_entry(pubs['entries'][0])
    architecture_specific: True
    archive_link: u'http://.../~cprov/+archive/ppa'
    binary_package_name: u'mozilla-firefox'
    binary_package_version: u'1.0'
    component_name: u'main'
    date_created: u'2007-08-10T13:00:00+00:00'
    date_made_pending: None
    date_published: u'2007-08-10T13:00:01+00:00'
    date_removed: None
    date_superseded: None
    display_name: u'mozilla-firefox 1.0 in warty hppa'
    distro_arch_series_link: u'http://.../ubuntu/warty/hppa'
    pocket: u'Release'
    priority_name: u'IMPORTANT'
    removal_comment: None
    removed_by_link: None
    resource_type_link: u'http://.../#binary_package_publishing_history'
    scheduled_deletion_date: None
    section_name: u'base'
    self_link: u'http://.../~cprov/+archive/ppa/+binarypub/30'
    status: u'Published'


Security
========

Create a private PPA for Celso with some binaries.

    >>> login("foo.bar@canonical.com")
    >>> from zope.component import getUtility
    >>> from lp.registry.interfaces.distribution import IDistributionSet
    >>> from lp.registry.interfaces.person import IPersonSet
    >>> from lp.soyuz.tests.test_publishing import (
    ...      SoyuzTestPublisher)
    >>> from lp.soyuz.enums import (
    ...     PackagePublishingStatus)
    >>> cprov_db = getUtility(IPersonSet).getByName('cprov')
    >>> ubuntu_db = getUtility(IDistributionSet).getByName('ubuntu')
    >>> cprov_private_ppa_db = factory.makeArchive(
    ...     private=True, owner=cprov_db, name="p3a",
    ...     distribution=ubuntu_db)
    >>> test_publisher = SoyuzTestPublisher()
    >>> test_publisher.prepareBreezyAutotest()
    >>> private_source_pub = test_publisher.getPubBinaries(
    ...     status=PackagePublishingStatus.PUBLISHED,
    ...     binaryname='privacy-test-bin',
    ...     archive=cprov_private_ppa_db)
    >>> logout()

Only Celso (or anyone who participates on the PPA owner team) has
access to the PPA publications.

    >>> cprov_private_ppa = webservice.get("/~cprov/+archive/p3a").jsonBody()
    >>> cprov_bins_response = webservice.named_get(
    ...     cprov_private_ppa['self_link'], 'getPublishedBinaries')
    >>> print cprov_bins_response
    HTTP/1.1 200 Ok
    ...

Any other user attempt would result in a 401 error.

    >>> response = user_webservice.named_get(
    ...     cprov_private_ppa['self_link'], 'getPublishedBinaries')
    >>> print response
    HTTP/1.1 401 Unauthorized
    ...

If the user attempts to access the publication URL directly they will
also fail in their quest.

    >>> pubs = cprov_bins_response.jsonBody()
    >>> private_publication_url = pubs['entries'][0]['self_link']
    >>> response = user_webservice.get(private_publication_url)
    >>> print response
    HTTP/1.1 401 Unauthorized
    ...


Download counts
===============

We can retrieve the total download count for a binary in this archive.

    >>> webservice.named_get(
    ...     pubs['entries'][0]['self_link'], 'getDownloadCount').jsonBody()
    0

    >>> login("foo.bar@canonical.com")

    >>> from datetime import date
    >>> from lp.services.worlddata.interfaces.country import ICountrySet
    >>> australia = getUtility(ICountrySet)['AU']

    >>> firefox_db = cprov_db.archive.getAllPublishedBinaries(
    ...     name='mozilla-firefox')[0]
    >>> firefox_db.archive.updatePackageDownloadCount(
    ...     firefox_db.binarypackagerelease, date(2010, 2, 21), australia, 10)
    >>> firefox_db.archive.updatePackageDownloadCount(
    ...     firefox_db.binarypackagerelease, date(2010, 2, 23), None, 8)

    >>> logout()

    >>> firefox = webservice.named_get(
    ...     cprov_archive['self_link'], 'getPublishedBinaries',
    ...     binary_name='mozilla-firefox').jsonBody()['entries'][0]
    >>> webservice.named_get(
    ...     firefox['self_link'], 'getDownloadCount').jsonBody()
    18

Detailed download counts are also available from the getDownloadCounts method.

    >>> counts = webservice.named_get(
    ...     firefox['self_link'], 'getDownloadCounts').jsonBody()['entries']
    >>> len(counts)
    2

A detailed count object can be retrieved by its URL.

    >>> pprint_entry(webservice.get(counts[1]['self_link']).jsonBody())
    archive_link: u'http://.../~cprov/+archive/ppa'
    binary_package_name: u'mozilla-firefox'
    binary_package_version: u'1.0'
    count: 10
    country_link: u'http://.../+countries/AU'
    day: u'2010-02-21'
    resource_type_link: u'http://.../#binary_package_release_download_count'
    self_link: u'http://.../~cprov/+archive/ppa/+binaryhits/mozilla-firefox/1.0/hppa/2010-02-21/AU'

We can also filter by date.

    >>> counts = webservice.named_get(
    ...     firefox['self_link'], 'getDownloadCounts',
    ...     start_date='2010-02-22').jsonBody()['entries']
    >>> len(counts)
    1

    >>> pprint_entry(webservice.get(counts[0]['self_link']).jsonBody())
    archive_link: u'http://.../~cprov/+archive/ppa'
    binary_package_name: u'mozilla-firefox'
    binary_package_version: u'1.0'
    count: 8
    country_link: None
    day: u'2010-02-23'
    resource_type_link: u'http://.../#binary_package_release_download_count'
    self_link: u'http://.../~cprov/+archive/ppa/+binaryhits/mozilla-firefox/1.0/hppa/2010-02-23/unknown'

But other URLs result in a 404.

    >>> print webservice.get(
    ...     '/~cprov/+archive/ppa/+binaryhits/moz')
    HTTP/1.1 404 Not Found
    ...

    >>> print webservice.get(
    ...     '/~cprov/+archive/ppa/+binaryhits/phoenix/1.0/hppa/2010-02-23/unknown')
    HTTP/1.1 404 Not Found
    ...

    >>> print webservice.get(
    ...     '/~cprov/+archive/ppa/+binaryhits/mozilla-firefox/1.1/hppa/2010-02-23/unknown')
    HTTP/1.1 404 Not Found
    ...

    >>> print webservice.get(
    ...     '/~cprov/+archive/ppa/+binaryhits/mozilla-firefox/1.0/foo/2010-02-23/unknown')
    HTTP/1.1 404 Not Found
    ...

    >>> print webservice.get(
    ...     '/~cprov/+archive/ppa/+binaryhits/mozilla-firefox/1.0/hppa/2010-02-25/unknown')
    HTTP/1.1 404 Not Found
    ...

    >>> print webservice.get(
    ...     '/~cprov/+archive/ppa/+binaryhits/mozilla-firefox/1.0/hppa/2010-02-23/XX')
    HTTP/1.1 404 Not Found
    ...

getDailyDownloadTotals returns a dict mapping dates to total counts.

    >>> webservice.named_get(
    ...     firefox['self_link'], 'getDailyDownloadTotals').jsonBody()
    {u'2010-02-21': 10, u'2010-02-23': 8}