Merge lp:~cjwatson/launchpad/recipe-name-policy into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17898
Proposed branch: lp:~cjwatson/launchpad/recipe-name-policy
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/git-recipe-browser-existing
Diff against target: 165 lines (+38/-5)
6 files modified
lib/lp/code/browser/sourcepackagerecipe.py (+3/-5)
lib/lp/code/interfaces/branchtarget.py (+4/-0)
lib/lp/code/interfaces/gitnamespace.py (+4/-0)
lib/lp/code/model/branchtarget.py (+15/-0)
lib/lp/code/model/gitnamespace.py (+3/-0)
lib/lp/code/model/tests/test_branchtarget.py (+9/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/recipe-name-policy
Reviewer Review Type Date Requested Status
William Grant (community) code Approve
Review via email: mp+282303@code.launchpad.net

Commit message

Add allow_recipe_name_from_target to IBranchTarget and IGitNamespacePolicy, so that SourcePackageRecipeAddView doesn't have to do isinstance checks.

Description of the change

Add allow_recipe_name_from_target to IBranchTarget and IGitNamespacePolicy, so that SourcePackageRecipeAddView doesn't have to do isinstance checks.

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/code/browser/sourcepackagerecipe.py'
2--- lib/lp/code/browser/sourcepackagerecipe.py 2016-01-12 14:17:30 +0000
3+++ lib/lp/code/browser/sourcepackagerecipe.py 2016-01-12 14:17:30 +0000
4@@ -57,7 +57,6 @@
5 SimpleTerm,
6 SimpleVocabulary,
7 )
8-from zope.security.proxy import isinstance as zope_isinstance
9
10 from lp import _
11 from lp.app.browser.launchpadform import (
12@@ -99,7 +98,6 @@
13 ISourcePackageRecipeSource,
14 MINIMAL_RECIPE_TEXT_BZR,
15 )
16-from lp.code.model.branchtarget import PersonBranchTarget
17 from lp.code.vocabularies.sourcepackagerecipe import BuildableDistroSeries
18 from lp.registry.interfaces.series import SeriesStatus
19 from lp.services.fields import PersonChoice
20@@ -746,10 +744,10 @@
21 """A generator of recipe names."""
22 # +junk-daily doesn't make a very good recipe name, so use the
23 # branch name in that case.
24- if zope_isinstance(self.context.target, PersonBranchTarget):
25+ if self.context.target.allow_recipe_name_from_target:
26+ branch_target_name = self.context.target.name.split('/')[-1]
27+ else:
28 branch_target_name = self.context.name
29- else:
30- branch_target_name = self.context.target.name.split('/')[-1]
31 yield "%s-daily" % branch_target_name
32 counter = itertools.count(1)
33 while True:
34
35=== modified file 'lib/lp/code/interfaces/branchtarget.py'
36--- lib/lp/code/interfaces/branchtarget.py 2015-09-28 23:50:43 +0000
37+++ lib/lp/code/interfaces/branchtarget.py 2016-01-12 14:17:30 +0000
38@@ -98,6 +98,10 @@
39 supports_code_imports = Attribute(
40 "Does this target support code imports at all?")
41
42+ allow_recipe_name_from_target = Attribute(
43+ "Can recipe names reasonably be generated from the target name "
44+ "rather than the branch name?")
45+
46 def areBranchesMergeable(other_target):
47 """Are branches from other_target mergeable into this target?"""
48
49
50=== modified file 'lib/lp/code/interfaces/gitnamespace.py'
51--- lib/lp/code/interfaces/gitnamespace.py 2015-04-28 23:25:08 +0000
52+++ lib/lp/code/interfaces/gitnamespace.py 2016-01-12 14:17:30 +0000
53@@ -96,6 +96,10 @@
54 supports_merge_proposals = Attribute(
55 "Does this namespace support merge proposals at all?")
56
57+ allow_recipe_name_from_target = Attribute(
58+ "Can recipe names reasonably be generated from the target name "
59+ "rather than the branch name?")
60+
61 def getAllowedInformationTypes(who):
62 """Get the information types that a repository in this namespace can
63 have.
64
65=== modified file 'lib/lp/code/model/branchtarget.py'
66--- lib/lp/code/model/branchtarget.py 2015-09-28 23:50:43 +0000
67+++ lib/lp/code/model/branchtarget.py 2016-01-12 14:17:30 +0000
68@@ -122,6 +122,11 @@
69 """See `IBranchTarget`."""
70 return True
71
72+ @property
73+ def allow_recipe_name_from_target(self):
74+ """See `IBranchTarget`."""
75+ return True
76+
77 def areBranchesMergeable(self, other_target):
78 """See `IBranchTarget`."""
79 # Branches are mergable into a PackageTarget if the source package
80@@ -238,6 +243,11 @@
81 """See `IBranchTarget`."""
82 return False
83
84+ @property
85+ def allow_recipe_name_from_target(self):
86+ """See `IBranchTarget`."""
87+ return False
88+
89 def areBranchesMergeable(self, other_target):
90 """See `IBranchTarget`."""
91 return False
92@@ -323,6 +333,11 @@
93 """See `IBranchTarget`."""
94 return True
95
96+ @property
97+ def allow_recipe_name_from_target(self):
98+ """See `IBranchTarget`."""
99+ return True
100+
101 def areBranchesMergeable(self, other_target):
102 """See `IBranchTarget`."""
103 # Branches are mergable into a PackageTarget if the source package
104
105=== modified file 'lib/lp/code/model/gitnamespace.py'
106--- lib/lp/code/model/gitnamespace.py 2015-10-09 15:49:14 +0000
107+++ lib/lp/code/model/gitnamespace.py 2016-01-12 14:17:30 +0000
108@@ -237,6 +237,7 @@
109 has_defaults = False
110 allow_push_to_set_default = False
111 supports_merge_proposals = False
112+ allow_recipe_name_from_target = False
113
114 def __init__(self, person):
115 self.owner = person
116@@ -314,6 +315,7 @@
117 has_defaults = True
118 allow_push_to_set_default = True
119 supports_merge_proposals = True
120+ allow_recipe_name_from_target = True
121
122 def __init__(self, person, project):
123 self.owner = person
124@@ -398,6 +400,7 @@
125 has_defaults = True
126 allow_push_to_set_default = False
127 supports_merge_proposals = True
128+ allow_recipe_name_from_target = True
129
130 def __init__(self, person, distro_source_package):
131 self.owner = person
132
133=== modified file 'lib/lp/code/model/tests/test_branchtarget.py'
134--- lib/lp/code/model/tests/test_branchtarget.py 2015-09-28 23:50:43 +0000
135+++ lib/lp/code/model/tests/test_branchtarget.py 2016-01-12 14:17:30 +0000
136@@ -215,6 +215,9 @@
137 self.assertEqual(owner, code_import.branch.owner)
138 self.assertEqual(self.target, code_import.branch.target)
139
140+ def test_allow_recipe_name_from_target(self):
141+ self.assertTrue(self.target.allow_recipe_name_from_target)
142+
143 def test_related_branches(self):
144 (branch, related_series_branch_info,
145 related_package_branches) = (
146@@ -335,6 +338,9 @@
147 self.factory.getUniqueString("name-"),
148 RevisionControlSystems.GIT, url=self.factory.getUniqueURL())
149
150+ def test_does_not_allow_recipe_name_from_target(self):
151+ self.assertFalse(self.target.allow_recipe_name_from_target)
152+
153
154 class TestProductBranchTarget(TestCaseWithFactory, BaseBranchTargetTests):
155
156@@ -470,6 +476,9 @@
157 self.assertEqual(owner, code_import.branch.owner)
158 self.assertEqual(self.target, code_import.branch.target)
159
160+ def test_allow_recipe_name_from_target(self):
161+ self.assertTrue(self.target.allow_recipe_name_from_target)
162+
163 def test_related_branches(self):
164 (branch, related_series_branch_info,
165 related_package_branches) = (