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
|
Distribution Soyuz Views
========================
>>> from lp.registry.interfaces.distribution import IDistributionSet
>>> login("foo.bar@canonical.com")
>>> ubuntu = getUtility(IDistributionSet).getByName("ubuntu")
DistributionArchivesView
------------------------
>>> from lp.registry.interfaces.person import IPersonSet
The DistributionArchivesView includes an archive_list property that
returns a list of copy archives only for the given distribution (because
only copy archives are exposed through the distribution/+archives UI):
>>> distro_archives_view = create_initialized_view(ubuntu,
... name="+archives")
>>> archives = distro_archives_view.archive_list
>>> archives.count()
0
And then after creating a copy archive for Ubuntu:
>>> copy_location = factory.makeCopyArchiveLocation(
... distribution=ubuntu,
... name="intrepid-security-rebuild")
>>> archives = distro_archives_view.archive_list
>>> archives.count()
1
Disabled archives will be visible:
>>> foo_bar = getUtility(IPersonSet).getByName('name16')
>>> copy_location = factory.makeCopyArchiveLocation(
... distribution=ubuntu, enabled=False, owner=foo_bar)
>>> archives = distro_archives_view.archive_list
>>> archives.count()
2
DistributionPackageSearchView
-----------------------------
The DistributionPackageSearchView adds some functionality to the base
PackageSearchView class, specifically for making the results more useful.
By default the view will be initialized as a binary-package-name search,
and the search_by_binary_name property is used to determine the search
type (in templates):
Note: The substring search for binary names now uses the cached binary
names on the DistributionSourcePackageCache, which unfortunately are
not up-to-date in the test data. Hence only seeing mozilla-firefox returned
here.
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search",
... form={'text': 'a'},
... query_string='text=a')
>>> distro_pkg_search_view.search_by_binary_name
True
>>> for package in distro_pkg_search_view.search_results:
... print package.name
mozilla-firefox
Additionally, a helper property 'source_search_url' is included providing
easy access to the equivalent search on sources:
>>> print distro_pkg_search_view.source_search_url
http://launchpad.dev/ubuntu/+search?search_type=source&text=a
Unicode form variables remain encoded as UTF-8 (as expected by the
server) when building the 'source_search_url'.
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search",
... form={'text': u'\xe7'},
... query_string='text=%C3%A7')
>>> print distro_pkg_search_view.source_search_url
http://launchpad.dev/ubuntu/+search?search_type=source&text=%C3%A7
But users can specify that the search should be on source-package-names
instead:
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search", form={
... 'text': 'a',
... 'search_type': 'source'
... })
>>> distro_pkg_search_view.search_by_binary_name
False
>>> for package in distro_pkg_search_view.search_results:
... print package.name
alsa-utils
commercialpackage
foobar
mozilla-firefox
netapplet
Unless the distribution being searched does not support binaries, in which
cases it will always be on source:
>>> debian = factory.makeDistribution(
... name='mydebian', displayname='debian-without-binaries')
>>> debian.has_published_binaries
False
>>> distro_pkg_search_view = create_initialized_view(
... debian, name="+search", form={'search_type': 'binary'})
>>> distro_pkg_search_view.search_by_binary_name
False
Leading and trailing white-space is stripped from the search text.
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search",
... form={'text': ' a '},
... query_string='text=a')
>>> distro_pkg_search_view.text
'a'
If there is more than one text parameter value, the last one is used.
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search",
... form={'text': ['a','b']},
... query_string='text=a&text=b')
>>> distro_pkg_search_view.text
'b'
Exact matches
.............
The DistributionPackageSearchView view has an exact_matches property
and a has_exact_matches property which are used to find packages that
match exactly on the binary/source name.
In the following example, there is one source package that has a binary
with the exact name 'mozilla-firefox':
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search", form={'text': 'mozilla-firefox'})
>>> distro_pkg_search_view.has_exact_matches
True
>>> for package in distro_pkg_search_view.exact_matches:
... print package.name
mozilla-firefox
The view can also help the template know when to display exact matches.
>>> distro_pkg_search_view.display_exact_matches
True
Exact matches do not need to be displayed when the user views subsequent
batches.
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search", form={
... 'text': 'mozilla-firefox',
... 'batch': '2',
... 'start': '2',
... })
>>> distro_pkg_search_view.display_exact_matches
False
But they are displayed when returning to the first batch.
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search", form={
... 'text': 'mozilla-firefox',
... 'batch': '2',
... 'start': '0',
... })
>>> distro_pkg_search_view.display_exact_matches
True
Searches against source packages should not display exact matches either:
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search", form={
... 'text': 'mozilla-firefox',
... 'search_type': 'source',
... })
>>> distro_pkg_search_view.display_exact_matches
False
The DistributionPackageSearchView also has a helper property to
help templates print the list of distroseries that an exactly-matched
package is available in:
>>> distro_pkg_search_view.distroseries_names
{u'mozilla-firefox': u'warty'}
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search", form={'text': 'foobar'})
>>> distro_pkg_search_view.distroseries_names
{u'foobar': ''}
Another helper on the DistributionPackageSearchView is the
matching_binary_names property which can be used by templates to get
a list of the binary names that matched the search term for each
package:
>>> distro_pkg_search_view = create_initialized_view(
... ubuntu, name="+search", form={'text': 'moz'})
>>> distro_pkg_search_view.matching_binary_names
{u'mozilla-firefox': u'mozilla-firefox, mozilla-firefox-data'}
The matching_binary_names property uses a protected helper method
'_listFirstFiveMatchingNames' which ensures only the first five matching
names are returned. An ellipse is used to indicate when more than five
names match:
>>> print distro_pkg_search_view._listFirstFiveMatchingNames(
... 'moz',
... 'mozilla-firefox mozilla-data moziki '
... 'limozine moza lamoz') # doctest: -ELLIPSIS
mozilla-firefox, mozilla-data, moziki, limozine, moza, ...
Substring matches
.................
The DistributionPackageSearchView includes substring matches by default.
>>> search_results = distro_pkg_search_view.search_results
>>> search_results.count()
1
>>> for pkg in search_results:
... print pkg.name
mozilla-firefox
|