Merge lp:~jcsackett/launchpad/deprecate-official_codehosting into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 11484
Proposed branch: lp:~jcsackett/launchpad/deprecate-official_codehosting
Merge into: lp:launchpad
Diff against target: 330 lines (+72/-30)
8 files modified
lib/lp/registry/adapters.py (+18/-2)
lib/lp/registry/browser/distribution.py (+2/-1)
lib/lp/registry/browser/pillar.py (+16/-7)
lib/lp/registry/browser/productseries.py (+11/-3)
lib/lp/registry/browser/tests/pillar-views.txt (+8/-8)
lib/lp/registry/browser/tests/productseries-views.txt (+4/-4)
lib/lp/registry/configure.zcml (+7/-0)
lib/lp/registry/stories/product/xx-product-launchpad-usage.txt (+6/-5)
To merge this branch: bzr merge lp:~jcsackett/launchpad/deprecate-official_codehosting
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+33953@code.launchpad.net

Commit message

Replaces use of official_codehosting with the codehosting usage enum where possible.

Description of the change

= Summary =

Replaces use of official_codehosting with codehosting_attributes where possible.

== Proposed fix ==

Where official_codehosting is used, replace it with codehosting_usage and the ServiceUsage enums.

== Pre-implementation notes ==

Spoke with Curtis.

== Implementation details ==

As in Proposed fix.

== Tests ==

bin/test -vvc -t productseries-views.txt
bin/test -vvc -t pillar-views.txt
bin/test -vvc -t distribution-views.txt

== Demo and Q/A ==

Check out a project, product and distribution on launchpad.dev.

Everything should function as before--this shouldn't have introduced
any visible changes.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/adapters.py
  lib/lp/registry/configure.zcml
  lib/lp/registry/browser/distribution.py
  lib/lp/registry/browser/pillar.py
  lib/lp/registry/browser/productseries.py
  lib/lp/registry/browser/tests/pillar-views.txt
  lib/lp/registry/browser/tests/productseries-views.txt

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

This branch looks nice Jon. What would you think of creating some helper functions like:

uses_Launchpad(thing)

You could then collapse this:

175 + if self.codehosting_usage == ServiceUsage.LAUNCHPAD:
176 + configured = True
177 + else:
178 + configured = False
179 return [dict(link=set_branch,
181 + configured=configured)]

to:

179 return [dict(link=set_branch,
181 + configured=uses_launchpad(self.codehosting_usage)

I guess you could do the same with:

configured = (self.codehosting_usage == ServiceUsage.LAUNCHPAD)

with less overhead.

review: Approve (code)
Revision history for this message
j.c.sackett (jcsackett) wrote :

Brad,

I actually deliberately expanded some clauses into the if constructs because I found them easier to parse.

I'm not opposed to a helper function, since the inside of that would be fairly clear, but assigning a boolean
expression to a variable is sort of difficult to scan in a large block of code.

Thoughts?

On Aug 27, 2010, at 4:49 PM, Brad Crittenden wrote:

> Review: Approve code
> This branch looks nice Jon. What would you think of creating some helper functions like:
>
> uses_Launchpad(thing)
>
> You could then collapse this:
>
> 175 + if self.codehosting_usage == ServiceUsage.LAUNCHPAD:
> 176 + configured = True
> 177 + else:
> 178 + configured = False
> 179 return [dict(link=set_branch,
> 181 + configured=configured)]
>
> to:
>
> 179 return [dict(link=set_branch,
> 181 + configured=uses_launchpad(self.codehosting_usage)
>
> I guess you could do the same with:
>
> configured = (self.codehosting_usage == ServiceUsage.LAUNCHPAD)
>
> with less overhead.
> --
> https://code.launchpad.net/~jcsackett/launchpad/deprecate-official_codehosting/+merge/33953
> Your team Launchpad code reviewers from Canonical is subscribed to branch lp:launchpad/devel.
>
> --
> launchpad-reviews mailing list
> <email address hidden>
> https://lists.ubuntu.com/mailman/listinfo/launchpad-reviews

Revision history for this message
Brad Crittenden (bac) wrote :

On Aug 27, 2010, at 19:25, "j.c.sackett" <email address hidden> wrote:

> Brad,
>
> I actually deliberately expanded some clauses into the if constructs because I found them easier to parse.
>
> I'm not opposed to a helper function, since the inside of that would be fairly clear, but assigning a boolean
> expression to a variable is sort of difficult to scan in a large block of code.
>
> Thoughts?

What you have now is fine to land. If we find ourselves repeating that logic elsewhere then we can create a helper.

Brad

>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/adapters.py'
2--- lib/lp/registry/adapters.py 2010-08-20 20:31:18 +0000
3+++ lib/lp/registry/adapters.py 2010-08-31 14:49:44 +0000
4@@ -7,16 +7,25 @@
5
6 __all__ = [
7 'distroseries_to_launchpadusage',
8+ 'distroseries_to_serviceusage',
9 'PollSubset',
10 'productseries_to_product',
11 ]
12
13
14-from zope.component import getUtility
15+from zope.component import (
16+ adapter,
17+ getUtility,
18+ )
19 from zope.component.interfaces import ComponentLookupError
20-from zope.interface import implements
21+from zope.interface import (
22+ implementer,
23+ implements,
24+ )
25
26 from canonical.launchpad.webapp.interfaces import ILaunchpadPrincipal
27+from lp.app.interfaces.launchpad import IServiceUsage
28+from lp.registry.interfaces.distroseries import IDistroSeries
29 from lp.registry.interfaces.poll import (
30 IPollSet,
31 IPollSubset,
32@@ -25,6 +34,13 @@
33 )
34
35
36+@implementer(IServiceUsage)
37+@adapter(IDistroSeries)
38+def distroseries_to_serviceusage(distroseries):
39+ """Adapts `IDistroSeries` object to `IServiceUsage`."""
40+ return distroseries.distribution
41+
42+
43 def distroseries_to_launchpadusage(distroseries):
44 """Adapts `IDistroSeries` object to `ILaunchpadUsage`."""
45 return distroseries.distribution
46
47=== modified file 'lib/lp/registry/browser/distribution.py'
48--- lib/lp/registry/browser/distribution.py 2010-08-26 22:44:30 +0000
49+++ lib/lp/registry/browser/distribution.py 2010-08-31 14:49:44 +0000
50@@ -80,6 +80,7 @@
51 QuestionTargetFacetMixin,
52 QuestionTargetTraversalMixin,
53 )
54+from lp.app.enums import ServiceUsage
55 from lp.app.errors import NotFoundError
56 from lp.blueprints.browser.specificationtarget import (
57 HasSpecificationsMenuMixin,
58@@ -133,7 +134,7 @@
59 url = canonical_url(self.context, rootsite='bugs')
60 uses.append(href_template % (url, 'Bug Tracking'))
61 if IProduct.providedBy(self.context):
62- if self.context.official_codehosting:
63+ if self.context.codehosting_usage == ServiceUsage.LAUNCHPAD:
64 url = canonical_url(self.context, rootsite='code')
65 uses.append(href_template % (url, 'Branches'))
66 if self.context.official_rosetta:
67
68=== modified file 'lib/lp/registry/browser/pillar.py'
69--- lib/lp/registry/browser/pillar.py 2010-08-20 20:31:18 +0000
70+++ lib/lp/registry/browser/pillar.py 2010-08-31 14:49:44 +0000
71@@ -31,6 +31,8 @@
72 nearest,
73 )
74 from canonical.launchpad.webapp.tales import MenuAPI
75+from lp.app.enums import ServiceUsage
76+from lp.app.interfaces.launchpad import IServiceUsage
77 from lp.registry.browser.structuralsubscription import (
78 StructuralSubscriptionMenuMixin,
79 )
80@@ -73,9 +75,16 @@
81 enabled=self.pillar.official_rosetta)
82
83 def submit_code(self):
84+ if self.pillar.codehosting_usage in [
85+ ServiceUsage.LAUNCHPAD,
86+ ServiceUsage.EXTERNAL,
87+ ]:
88+ enabled = True
89+ else:
90+ enabled = False
91 return Link(
92 '+addbranch', 'Submit code', site='code', icon='code',
93- enabled=self.pillar.official_codehosting)
94+ enabled=enabled)
95
96 def register_blueprint(self):
97 return Link(
98@@ -96,19 +105,20 @@
99 self.official_answers = False
100 self.official_blueprints = False
101 self.official_rosetta = False
102- self.official_codehosting = False
103+ self.codehosting_usage = ServiceUsage.UNKNOWN
104 pillar = nearest(self.context, IPillar)
105 if IProjectGroup.providedBy(pillar):
106 for product in pillar.products:
107 self._set_official_launchpad(product)
108 # Project groups do not support submit code, override the
109 # default.
110- self.official_codehosting = False
111+ self.codehosting_usage = ServiceUsage.NOT_APPLICABLE
112 else:
113 self._set_official_launchpad(pillar)
114 if IDistroSeries.providedBy(self.context):
115 self.official_answers = False
116- self.official_codehosting = False
117+ distribution = self.context.distribution
118+ self.codehosting_usage = distribution.codehosting_usage
119 elif IDistributionSourcePackage.providedBy(self.context):
120 self.official_blueprints = False
121 self.official_rosetta = False
122@@ -128,8 +138,7 @@
123 self.official_blueprints = True
124 if pillar.official_rosetta:
125 self.official_rosetta = True
126- if pillar.official_codehosting:
127- self.official_codehosting = True
128+ self.codehosting_usage = IServiceUsage(pillar).codehosting_usage
129
130 @property
131 def has_involvement(self):
132@@ -137,7 +146,7 @@
133 return (
134 self.official_malone or self.official_answers
135 or self.official_blueprints or self.official_rosetta
136- or self.official_codehosting)
137+ or self.codehosting_usage == ServiceUsage.LAUNCHPAD)
138
139 @property
140 def enabled_links(self):
141
142=== modified file 'lib/lp/registry/browser/productseries.py'
143--- lib/lp/registry/browser/productseries.py 2010-08-23 04:48:17 +0000
144+++ lib/lp/registry/browser/productseries.py 2010-08-31 14:49:44 +0000
145@@ -83,6 +83,7 @@
146 from canonical.launchpad.webapp.tales import MenuAPI
147 from canonical.widgets.itemswidgets import LaunchpadRadioWidget
148 from canonical.widgets.textwidgets import StrippedTextWidget
149+from lp.app.enums import ServiceUsage
150 from lp.app.errors import (
151 NotFoundError,
152 UnexpectedFormData,
153@@ -237,7 +238,7 @@
154 def submit_code(self):
155 target = canonical_url(
156 self.pillar, view_name='+addbranch', rootsite='code')
157- enabled = self.view.official_codehosting
158+ enabled = self.view.codehosting_usage == ServiceUsage.LAUNCHPAD
159 return Link(
160 target, 'Submit code', icon='code', enabled=enabled)
161
162@@ -251,7 +252,10 @@
163
164 def __init__(self, context, request):
165 super(ProductSeriesInvolvementView, self).__init__(context, request)
166- self.official_codehosting = self.context.branch is not None
167+ if self.context.branch is not None:
168+ self.codehosting_usage = ServiceUsage.LAUNCHPAD
169+ else:
170+ self.codehosting_usage = ServiceUsage.UNKNOWN
171 self.official_answers = False
172
173 @property
174@@ -260,8 +264,12 @@
175 series_menu = MenuAPI(self.context).overview
176 set_branch = series_menu['set_branch']
177 set_branch.text = 'Configure series branch'
178+ if self.codehosting_usage == ServiceUsage.LAUNCHPAD:
179+ configured = True
180+ else:
181+ configured = False
182 return [dict(link=set_branch,
183- configured=self.official_codehosting)]
184+ configured=configured)]
185
186
187 class ProductSeriesOverviewMenu(
188
189=== modified file 'lib/lp/registry/browser/tests/pillar-views.txt'
190--- lib/lp/registry/browser/tests/pillar-views.txt 2010-08-19 20:11:11 +0000
191+++ lib/lp/registry/browser/tests/pillar-views.txt 2010-08-31 14:49:44 +0000
192@@ -39,8 +39,8 @@
193 False
194 >>> view.official_blueprints
195 False
196- >>> view.official_codehosting
197- False
198+ >>> view.codehosting_usage.name
199+ 'NOT_APPLICABLE'
200
201 The view provides a list of enabled links that is rendered by the template.
202
203@@ -200,23 +200,23 @@
204 >>> product.official_codehosting
205 False
206 >>> view = create_view(product, '+get-involved')
207- >>> view.official_codehosting
208- False
209+ >>> view.codehosting_usage.name
210+ 'UNKNOWN'
211
212 >>> product.development_focus.branch = factory.makeBranch(
213 ... product=product)
214 >>> product.official_codehosting
215 True
216 >>> view = create_view(product, '+get-involved')
217- >>> view.official_codehosting
218- True
219+ >>> view.codehosting_usage.name
220+ 'LAUNCHPAD'
221
222 Project groups cannot make links to register a branch, so
223 official_codehosting is always false.
224
225 >>> view = create_view(project_group, '+get-involved')
226- >>> view.official_codehosting
227- False
228+ >>> view.codehosting_usage.name
229+ 'NOT_APPLICABLE'
230
231 DistroSeries can use this view. The distribution is used to set the links.
232
233
234=== modified file 'lib/lp/registry/browser/tests/productseries-views.txt'
235--- lib/lp/registry/browser/tests/productseries-views.txt 2010-08-23 04:48:17 +0000
236+++ lib/lp/registry/browser/tests/productseries-views.txt 2010-08-31 14:49:44 +0000
237@@ -39,8 +39,8 @@
238 True
239 >>> print view.official_rosetta
240 True
241- >>> print view.official_codehosting
242- False
243+ >>> print view.codehosting_usage.name
244+ UNKNOWN
245 >>> for link in view.enabled_links:
246 ... print link.url
247 http://bugs.launchpad.dev/app/simple/+filebug
248@@ -54,8 +54,8 @@
249
250 >>> series.branch = factory.makeBranch()
251 >>> view = create_view(series, '+get-involved')
252- >>> print view.official_codehosting
253- True
254+ >>> print view.codehosting_usage.name
255+ LAUNCHPAD
256 >>> for link in view.enabled_links:
257 ... print link.url
258 http://bugs.launchpad.dev/app/simple/+filebug
259
260=== modified file 'lib/lp/registry/configure.zcml'
261--- lib/lp/registry/configure.zcml 2010-08-23 03:25:20 +0000
262+++ lib/lp/registry/configure.zcml 2010-08-31 14:49:44 +0000
263@@ -171,6 +171,8 @@
264 factory="lp.registry.adapters.distroseries_to_launchpadusage"
265 permission="zope.Public"/>
266 <adapter
267+ factory="lp.registry.adapters.distroseries_to_serviceusage" />
268+ <adapter
269 provides="canonical.launchpad.webapp.interfaces.IBreadcrumb"
270 for="lp.registry.interfaces.distroseries.IDistroSeries"
271 factory="lp.registry.browser.distroseries.DistroSeriesBreadcrumb"
272@@ -1379,6 +1381,11 @@
273 factory="lp.registry.adapters.productseries_to_product"
274 permission="zope.Public"/>
275 <adapter
276+ provides="lp.app.interfaces.launchpad.IServiceUsage"
277+ for="lp.registry.interfaces.productseries.IProductSeries"
278+ factory="lp.registry.adapters.productseries_to_product"
279+ permission="zope.Public"/>
280+ <adapter
281 provides="lp.app.interfaces.launchpad.ILaunchpadUsage"
282 for="lp.registry.interfaces.productseries.IProductSeries"
283 factory="lp.registry.adapters.productseries_to_product"
284
285=== modified file 'lib/lp/registry/stories/product/xx-product-launchpad-usage.txt'
286--- lib/lp/registry/stories/product/xx-product-launchpad-usage.txt 2010-08-25 00:01:57 +0000
287+++ lib/lp/registry/stories/product/xx-product-launchpad-usage.txt 2010-08-31 14:49:44 +0000
288@@ -47,7 +47,8 @@
289 >>> registrant_browser.getControl('Somewhere else').selected = True
290 >>> registrant_browser.getControl('Change').click()
291
292-We'll also set it as officially using codehosting.
293+We'll also set up a development focus branch. Because it's a mirrored
294+branch, codehosting won't show up as a service the product uses.
295
296 >>> registrant_browser.getLink('Configure project branch').click()
297 >>> registrant_browser.getControl(name='field.branch_location').value = (
298@@ -89,7 +90,7 @@
299
300 >>> uses = find_tag_by_id(registrant_browser.contents, id='uses')
301 >>> print extract_text(uses)
302- Uses Launchpad for: Branches and Translations.
303+ Uses Launchpad for: Translations.
304
305 Blueprints can be enabled too, though it isn't easy.
306
307@@ -110,12 +111,12 @@
308
309
310 On the product page, we can see that the product doesn't use any bug
311-tracker, not even Launchpad, but does use other apps.
312+tracker, not even Launchpad, but does use Translations.
313
314 >>> registrant_browser.open('http://launchpad.dev/firefox')
315 >>> uses = find_tag_by_id(registrant_browser.contents, id='uses')
316 >>> print extract_text(uses)
317- Uses Launchpad for: Blueprints, Branches, and Translations.
318+ Uses Launchpad for: Blueprints and Translations.
319
320 Setting a usage to external is reflected in the "Uses" message.
321 Change translations to external.
322@@ -127,7 +128,7 @@
323
324 >>> uses = find_tag_by_id(registrant_browser.contents, id='uses')
325 >>> print extract_text(uses)
326- Uses Launchpad for: Blueprints and Branches.
327+ Uses Launchpad for: Blueprints.
328
329
330 Tracking bugs by email