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
|
= Source Package Publishing Views =
The default view for SourcePackagePublishingHistory offers a
convenience property that can be used to display files that are
related to that publication; this includes binary and source
files. The property returns a sorted list of dictionaries with URLs,
filenames and filesizes.
>>> from zope.component import getMultiAdapter
>>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
>>> from lp.testing import celebrity_logged_in
We'll create SourcePackagePublishingHistory entries for
alsa-utils and foobar in ubuntu to test with:
>>> from lp.soyuz.tests.test_publishing import (
... SoyuzTestPublisher)
>>> from lp.soyuz.enums import (
... PackagePublishingStatus)
>>> with celebrity_logged_in('admin'):
... stp = SoyuzTestPublisher()
... stp.prepareBreezyAutotest()
... alsa_pub = stp.getPubSource(sourcename='alsa-utils-test')
... foo_pub = stp.getPubSource(sourcename='foobar-test',
... status=PackagePublishingStatus.DELETED)
The base class BasePublishingRecordView provides a few helper methods
and properties for querying the publishing history record:
If the publishing record does not include a removal comment, then
the view property returns 'None provided.'
>>> view = getMultiAdapter(
... (foo_pub, LaunchpadTestRequest()), name="+listing-compact")
>>> view.wasDeleted()
True
>>> print view.context.removal_comment
None
>>> view.removal_comment
u'None provided.'
Otherwise the removal comment will be returned
>>> login('foo.bar@canonical.com')
>>> foo_pub.removal_comment = "It had to go."
>>> print view.context.removal_comment
It had to go.
>>> print view.removal_comment
It had to go.
The SourcePackagePublishingView implements the
'published_source_and_binary_files' property which returns a list of
dictionaries containing:
* url: the librarian file url;
* class: either 'source' or 'binary' CSS class;
* filesize: the filesize stored in librarian;
* filename: the filename to be presented to user;
for each file related with the alsa-utils source publication in ubuntu.
>>> view = getMultiAdapter(
... (alsa_pub, LaunchpadTestRequest()),
... name="+listing-archive-detailed")
>>> view.published_source_and_binary_files
[{'url': u'http://launchpad.dev/ubuntutest/+archive/primary/+files/alsa-utils-test_666.dsc',
'class': 'source',
'filesize': 28,
'filename': u'alsa-utils-test_666.dsc'}]
'iceweasel' source in Celso's PPA contains binary files that can be
inspected.
>>> from lp.registry.interfaces.person import IPersonSet
>>> cprov = getUtility(IPersonSet).getByName("cprov")
>>> iceweasel_source_pub = cprov.archive.getPublishedSources(
... 'iceweasel').first()
>>> ppa_source_view = getMultiAdapter(
... (iceweasel_source_pub, LaunchpadTestRequest()),
... name="+listing-archive-detailed")
>>> ppa_source_view.published_source_and_binary_files
[{'url': u'http://launchpad.dev/~cprov/+archive/ppa/+files/firefox_0.9.2.orig.tar.gz',
'class': 'source',
'filesize': 9922560,
'filename': u'firefox_0.9.2.orig.tar.gz'},
{'url': u'http://launchpad.dev/~cprov/+archive/ppa/+files/iceweasel-1.0.dsc',
'class': 'source',
'filesize': 123,
'filename': u'iceweasel-1.0.dsc'},
{'url': u'http://launchpad.dev/~cprov/+archive/ppa/+files/mozilla-firefox_0.9_i386.deb',
'class': 'binary',
'filesize': 3,
'filename': u'mozilla-firefox_0.9_i386.deb'}]
Yet using SourcePackagePublishingView classes we can verify how it
allows the template to find out if it is a source or a binary
publication.
Continuing to use the 'iceweasel' source publication in Celso's PPA.
>>> source_details_view = getMultiAdapter(
... (iceweasel_source_pub, LaunchpadTestRequest()),
... name="+record-details")
We probe the 'is_source' and 'is_binary' properties.
>>> print source_details_view.is_source
True
>>> print source_details_view.is_binary
False
Similarly, we use one of the 'iceweasel' binaries published in Celso's
PPA to see how the same mechanism works for
BinaryPackagePublishingHistoryView.
>>> iceweasel_binary_pub = iceweasel_source_pub.getPublishedBinaries()[0]
>>> binary_details_view = getMultiAdapter(
... (iceweasel_binary_pub, LaunchpadTestRequest()),
... name="+record-details")
>>> print binary_details_view.is_source
False
>>> print binary_details_view.is_binary
True
Make sure the 'timestamp_map' class attribute in BasePublishingRecordView
covers all PackagePublishingStatus values.
This test will fail if we add a new value to the PackagePublishingStatus
enumeration but neglect to update BasePublishingRecordView.timestamp_map
accordingly.
>>> from lp.soyuz.browser.publishing import (
... BasePublishingRecordView)
>>> for pps in PackagePublishingStatus.items:
... print '%s -> %s' % (
... pps, BasePublishingRecordView.timestamp_map[pps])
Pending -> datecreated
Published -> datepublished
Superseded -> datesuperseded
Deleted -> dateremoved
Obsolete -> scheduleddeletiondate
Any key that's not in the PackagePublishingStatus enumeration will cause an
exception to be thrown.
>>> print BasePublishingRecordView.timestamp_map['key_not_there']
Traceback (most recent call last):
...
KeyError: 'key_not_there'
== SourcePublishingRecordView ==
The SourcePublishingRecordView includes a build_status_summary property
that returns a dict summary of the build status for the context record:
>>> src_pub_record_view = create_initialized_view(
... iceweasel_source_pub,
... name="+listing-compact")
Create a small function for displaying the results:
>>> def print_build_summary(summary):
... print "%s\n%s\nRelevant builds:\n%s" % (
... summary['status'].title,
... summary['status'].description,
... "\n".join(
... " - %s" % build.title for build in summary['builds'])
... )
>>> print_build_summary(src_pub_record_view.build_status_summary)
FULLYBUILT_PENDING
All builds were built successfully but have not yet been published.
Relevant builds:
- i386 build of iceweasel 1.0 in ubuntu warty RELEASE
The view also helps templates to decide on the icon that should be used
to summarize the current state of the context's associated builds:
>>> print src_pub_record_view.build_status_img_src
/@@/build-success-publishing
As well as some helpers to determine the publishing status from templates:
>>> src_pub_record_view.builds_successful_and_published
False
>>> src_pub_record_view.builds_successful_and_pending
True
>>> for build in src_pub_record_view.pending_builds:
... print build.title
i386 build of iceweasel 1.0 in ubuntu warty RELEASE
|