Merge lp:~stevenk/launchpad/no-count-distribution-ppas into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 16417
Proposed branch: lp:~stevenk/launchpad/no-count-distribution-ppas
Merge into: lp:launchpad
Diff against target: 330 lines (+9/-201)
6 files modified
lib/lp/registry/browser/distribution.py (+3/-27)
lib/lp/soyuz/doc/archive.txt (+0/-73)
lib/lp/soyuz/interfaces/archive.py (+1/-13)
lib/lp/soyuz/model/archive.py (+1/-27)
lib/lp/soyuz/stories/ppa/xx-ubuntu-ppas.txt (+0/-30)
lib/lp/soyuz/templates/distribution-ppa-list.pt (+4/-31)
To merge this branch: bzr merge lp:~stevenk/launchpad/no-count-distribution-ppas
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+142818@code.launchpad.net

Commit message

Delete the PPA statistics from Distribution:+ppas, and the methods that the properties back onto.

Description of the change

Delete the PPA statistics from Distribution:+ppas, and the methods that the properties back onto. Due to the TAL requiring registered_ppas to work out whether to allow search, I wrote another method on the view that backs onto IDistribution.getAllPPAs() -- since that returns a ResultSet, hopefully calling is_empty() on it means it's performant.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/distribution.py'
2--- lib/lp/registry/browser/distribution.py 2012-09-21 06:52:06 +0000
3+++ lib/lp/registry/browser/distribution.py 2013-01-11 00:27:23 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Browser views for distributions."""
10@@ -780,32 +780,8 @@
11 return self.batchnav.currentBatch()
12
13 @property
14- def number_of_registered_ppas(self):
15- """The number of archives with PPA purpose.
16-
17- It doesn't include private PPAs.
18- """
19- return self.context.searchPPAs(show_inactive=True).count()
20-
21- @property
22- def number_of_active_ppas(self):
23- """The number of PPAs with at least one source publication.
24-
25- It doesn't include private PPAs.
26- """
27- return self.context.searchPPAs(show_inactive=False).count()
28-
29- @property
30- def number_of_ppa_sources(self):
31- """The number of sources published across all PPAs."""
32- return getUtility(IArchiveSet).getNumberOfPPASourcesForDistribution(
33- self.context)
34-
35- @property
36- def number_of_ppa_binaries(self):
37- """The number of binaries published across all PPAs."""
38- return getUtility(IArchiveSet).getNumberOfPPABinariesForDistribution(
39- self.context)
40+ def distribution_has_ppas(self):
41+ return not self.context.getAllPPAs().is_empty()
42
43 @property
44 def latest_ppa_source_publications(self):
45
46=== modified file 'lib/lp/soyuz/doc/archive.txt'
47--- lib/lp/soyuz/doc/archive.txt 2012-12-26 01:32:19 +0000
48+++ lib/lp/soyuz/doc/archive.txt 2013-01-11 00:27:23 +0000
49@@ -1118,79 +1118,6 @@
50 >>> print sorted(set(archive_purposes))
51 ['COPY', 'DEBUG', 'PARTNER', 'PPA', 'PRIMARY']
52
53-ArchiveSet utility also offers counters in the distribution context for:
54-
55- * The number of published sources in public PPAs
56- (getNumberOfPPASourcesForDistribution);
57-
58- * The number of published binaries in public PPAs
59- (getNumberOfPPABinariesForDistribution);
60-
61-Those counters are obtained from the cached package counters for each
62-PPA, so they will change when the caches get updated.
63-
64-Those counters explicity exclude packages in private PPAs.
65-
66-The current counters says we only have 4 source and 4 binary published
67-in public PPAs.
68-
69- >>> archive_set.getNumberOfPPASourcesForDistribution(ubuntu)
70- 4
71- >>> archive_set.getNumberOfPPABinariesForDistribution(ubuntu)
72- 4
73-
74-As mentioned caches for private PPAs are not considered.
75-
76- >>> print cprov_private_ppa.private
77- True
78-
79- >>> cprov_private_ppa.sources_cached
80- 0
81- >>> cprov_private_ppa.binaries_cached
82- 0
83-
84- >>> from zope.security.proxy import removeSecurityProxy
85- >>> naked_cprov_archive = removeSecurityProxy(cprov_private_ppa)
86- >>> naked_cprov_archive.sources_cached = 1000
87- >>> naked_cprov_archive.binaries_cached = 2000
88- >>> naked_cprov_archive.syncUpdate()
89-
90- >>> archive_set.getNumberOfPPASourcesForDistribution(ubuntu)
91- 4
92- >>> archive_set.getNumberOfPPABinariesForDistribution(ubuntu)
93- 4
94-
95-On the other hand, changes in the a public PPA are immediately
96-considered.
97-
98- >>> print no_priv.archive.private
99- False
100-
101- >>> no_priv.archive.sources_cached
102- 0
103- >>> no_priv.archive.binaries_cached
104- 0
105- >>> naked_no_priv_archive = removeSecurityProxy(no_priv.archive)
106- >>> naked_no_priv_archive.sources_cached = 10
107- >>> naked_no_priv_archive.binaries_cached = 2
108- >>> naked_no_priv_archive.syncUpdate()
109-
110- >>> archive_set.getNumberOfPPASourcesForDistribution(ubuntu)
111- 14
112- >>> archive_set.getNumberOfPPABinariesForDistribution(ubuntu)
113- 6
114-
115-Since we currently only create archives for ubuntu distribution, the
116-counters for other distributions are always 'zero'.
117-
118- >>> debian = getUtility(IDistributionSet).getByName('debian')
119-
120- >>> archive_set.getNumberOfPPASourcesForDistribution(debian)
121- 0
122-
123- >>> archive_set.getNumberOfPPABinariesForDistribution(debian)
124- 0
125-
126 'getPPAsForUser' returns all the PPAs a given user participates in. It
127 uses `TeamParticipation` relationships to calculate all the PPAs the
128 user is allowed to upload or copy packages to.
129
130=== modified file 'lib/lp/soyuz/interfaces/archive.py'
131--- lib/lp/soyuz/interfaces/archive.py 2013-01-07 02:40:55 +0000
132+++ lib/lp/soyuz/interfaces/archive.py 2013-01-11 00:27:23 +0000
133@@ -1,4 +1,4 @@
134-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
135+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
136 # GNU Affero General Public License version 3 (see the file LICENSE).
137
138 """Archive interfaces."""
139@@ -1974,18 +1974,6 @@
140
141 title = Attribute('Title')
142
143- def getNumberOfPPASourcesForDistribution(distribution):
144- """Return the number of sources for PPAs in a given distribution.
145-
146- Only public and published sources are considered.
147- """
148-
149- def getNumberOfPPABinariesForDistribution(distribution):
150- """Return the number of binaries for PPAs in a given distribution.
151-
152- Only public and published sources are considered.
153- """
154-
155 def new(purpose, owner, name=None, displayname=None, distribution=None,
156 description=None, enabled=True, require_virtualized=True,
157 private=False, suppress_subscription_notifications=False):
158
159=== modified file 'lib/lp/soyuz/model/archive.py'
160--- lib/lp/soyuz/model/archive.py 2013-01-02 06:05:27 +0000
161+++ lib/lp/soyuz/model/archive.py 2013-01-11 00:27:23 +0000
162@@ -1,4 +1,4 @@
163-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
164+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
165 # GNU Affero General Public License version 3 (see the file LICENSE).
166
167 """Database class for table Archive."""
168@@ -2305,32 +2305,6 @@
169 """See `IArchiveSet`."""
170 return iter(Archive.select())
171
172- def getNumberOfPPASourcesForDistribution(self, distribution):
173- cur = cursor()
174- query = """
175- SELECT SUM(sources_cached) FROM Archive
176- WHERE purpose = %s AND private = FALSE AND
177- distribution = %s
178- """ % sqlvalues(ArchivePurpose.PPA, distribution)
179- cur.execute(query)
180- size = cur.fetchall()[0][0]
181- if size is None:
182- return 0
183- return int(size)
184-
185- def getNumberOfPPABinariesForDistribution(self, distribution):
186- cur = cursor()
187- query = """
188- SELECT SUM(binaries_cached) FROM Archive
189- WHERE purpose = %s AND private = FALSE AND
190- distribution = %s
191- """ % sqlvalues(ArchivePurpose.PPA, distribution)
192- cur.execute(query)
193- size = cur.fetchall()[0][0]
194- if size is None:
195- return 0
196- return int(size)
197-
198 def getPPAOwnedByPerson(self, person, name=None, statuses=None,
199 has_packages=False):
200 """See `IArchiveSet`."""
201
202=== modified file 'lib/lp/soyuz/stories/ppa/xx-ubuntu-ppas.txt'
203--- lib/lp/soyuz/stories/ppa/xx-ubuntu-ppas.txt 2012-08-09 11:23:20 +0000
204+++ lib/lp/soyuz/stories/ppa/xx-ubuntu-ppas.txt 2013-01-11 00:27:23 +0000
205@@ -30,22 +30,6 @@
206 Hoary (5.04) - development i386 (official)
207 Warty (4.10) - current i386 (official)
208
209-The sample data contains three PPAs. Only Celso's and Mark's have
210-packages (the active ones). Altogether there 4 sources and 4 binaries
211-published across all ubuntu PPAs.
212-
213- >>> print extract_text(
214- ... find_tag_by_id(anon_browser.contents, 'ppa_statistics'))
215- Statistics
216- Registered PPAs:
217- 3
218- Active PPAs:
219- 2
220- Published sources:
221- 4
222- Published binaries:
223- 4
224-
225 Up to 5 latest source publications are also presented in the 'Latest
226 sources' section.
227
228@@ -90,13 +74,6 @@
229 Sarge (3.1) - frozen
230 Woody (3.0) - current i386 (official)
231
232-Archive and package counter are empty.
233-
234- >>> print extract_text(
235- ... find_tag_by_id(anon_browser.contents, 'ppa_statistics'))
236- Statistics
237- Debian does not have any registered PPA.
238-
239 'Latest uploads' section is not presented.
240
241 >>> print find_tag_by_id(anon_browser.contents, 'ppa_latest_uploads')
242@@ -140,9 +117,6 @@
243
244 When a search is requested the information sections are not rendered.
245
246- >>> print find_tag_by_id(anon_browser.contents, 'ppa_statistics')
247- None
248-
249 >>> print find_tag_by_id(anon_browser.contents, 'ppa_most_active')
250 None
251
252@@ -160,10 +134,6 @@
253 >>> anon_browser.open("http://launchpad.dev/ubuntu/+ppas")
254
255 >>> find_tag_by_id(
256- ... anon_browser.contents, 'ppa_statistics') is not None
257- True
258-
259- >>> find_tag_by_id(
260 ... anon_browser.contents, 'ppa_most_active') is not None
261 True
262
263
264=== modified file 'lib/lp/soyuz/templates/distribution-ppa-list.pt'
265--- lib/lp/soyuz/templates/distribution-ppa-list.pt 2010-10-10 21:54:16 +0000
266+++ lib/lp/soyuz/templates/distribution-ppa-list.pt 2013-01-11 00:27:23 +0000
267@@ -9,8 +9,7 @@
268 <body>
269
270 <div metal:fill-slot="main"
271- tal:define="registered_ppas view/number_of_registered_ppas;
272- batch view/search_results;
273+ tal:define="batch view/search_results;
274 no_search python:not (view.name_filter or batch);
275 empty_results python:view.name_filter and not batch">
276
277@@ -24,7 +23,7 @@
278 >help page</a>.</p>
279
280 <form name="ppa_search" action="" method="GET"
281- tal:condition="registered_ppas">
282+ tal:condition="view/distribution_has_ppas">
283 <p>Search user-contributed software packages published in any
284 <tal:distribution replace="context/title"
285 >Ubuntu</tal:distribution> PPA.</p>
286@@ -55,34 +54,8 @@
287
288 <div class="yui-u first">
289
290- <div id="ppa_statistics" class="portlet">
291- <h2>Statistics</h2>
292- <div class="two-column-list" tal:condition="registered_ppas">
293- <dl>
294- <dt> Registered PPAs:</dt>
295- <dd tal:content="registered_ppas">10</dd>
296- </dl>
297- <dl>
298- <dt>Active PPAs:</dt>
299- <dd tal:content="view/number_of_active_ppas">4</dd>
300- </dl>
301- <dl>
302- <dt>Published sources:</dt>
303- <dd tal:content="view/number_of_ppa_sources">20</dd>
304- </dl>
305- <dl>
306- <dt>Published binaries:</dt>
307- <dd tal:content="view/number_of_ppa_binaries">20</dd>
308- </dl>
309- </div>
310- <p tal:condition="not: registered_ppas">
311- <span tal:replace="context/displayname">Ubuntu Linux</span>
312- does not have any registered PPA.
313- </p>
314- </div> <!-- ppa_statistics -->
315-
316 <div id="ppa_latest_uploads" class="portlet"
317- tal:condition="registered_ppas">
318+ tal:condition="view/distribution_has_ppas">
319 <h2>Latest uploads</h2>
320 <ul class="source package">
321 <li class="sprite package-source"
322@@ -99,7 +72,7 @@
323 </div> <!-- ppa_latest_uploads -->
324
325 <div id="ppa_most_active" class="portlet"
326- tal:condition="registered_ppas">
327+ tal:condition="view/distribution_has_ppas">
328 <h2>Most active</h2>
329 <p>PPAs with the highest number of uploads in the
330 last 7 days.</p>