Merge lp:~cjwatson/launchpad/bpph-source into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17420
Proposed branch: lp:~cjwatson/launchpad/bpph-source
Merge into: lp:launchpad
Diff against target: 196 lines (+57/-11)
7 files modified
lib/lp/_schema_circular_imports.py (+3/-1)
lib/lp/soyuz/interfaces/binarypackagebuild.py (+17/-1)
lib/lp/soyuz/interfaces/publishing.py (+8/-1)
lib/lp/soyuz/model/binarypackagebuild.py (+4/-4)
lib/lp/soyuz/model/publishing.py (+5/-1)
lib/lp/soyuz/model/queue.py (+2/-2)
lib/lp/soyuz/tests/test_binarypackagebuild.py (+18/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/bpph-source
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+255070@code.launchpad.net

Commit message

Add and export BinaryPackagePublishingHistory.build and BinaryPackageBuild.getLatestSourcePublication.

Description of the change

Add and export BinaryPackagePublishingHistory.build and BinaryPackageBuild.getLatestSourcePublication. This provides a simple way to get from a BPPH to an SPPH on the webservice, which was previously more or less impossible to do accurately unless you already had the SPPH in hand, and certainly inefficient. At the moment I need this for new-style ddeb publication, where we want to walk through Archive.getPublishedBinaries() results and need to know the source package name so that we can publish them to the right directory.

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

It may be acceptable to make this BinaryPackageBuild.getPublishedSource, but it's certainly not BinaryPackagePublishingHistory.getPublishedSource -- it can return a publication in a totally different archive.

If you just want the source name, I'd expose BinaryPackageBuild.source_package_name instead.

review: Needs Fixing (code)
Revision history for this message
William Grant (wgrant) wrote :

On second thought, BinaryPackageBuild.getLatestSourcePublication makes more sense than getPublishedSource.

Revision history for this message
Colin Watson (cjwatson) wrote :

How does this look now? ddeb-retriever only needs the source package name, it's true, but pull-lp-source wants the source version and component too, so I'd rather kill two birds with one stone and export a way to get to the SPPH.

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/_schema_circular_imports.py'
2--- lib/lp/_schema_circular_imports.py 2015-01-30 18:24:07 +0000
3+++ lib/lp/_schema_circular_imports.py 2015-04-08 10:36:06 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Update the interface schema values due to circular imports.
10@@ -363,6 +363,8 @@
11 IBinaryPackagePublishingHistory, 'distroarchseries',
12 IDistroArchSeries)
13 patch_reference_property(
14+ IBinaryPackagePublishingHistory, 'build', IBinaryPackageBuild)
15+patch_reference_property(
16 IBinaryPackagePublishingHistory, 'archive', IArchive)
17 patch_reference_property(
18 ISourcePackagePublishingHistory, 'archive', IArchive)
19
20=== modified file 'lib/lp/soyuz/interfaces/binarypackagebuild.py'
21--- lib/lp/soyuz/interfaces/binarypackagebuild.py 2014-11-06 02:42:36 +0000
22+++ lib/lp/soyuz/interfaces/binarypackagebuild.py 2015-04-08 10:36:06 +0000
23@@ -1,4 +1,4 @@
24-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
25+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
26 # GNU Affero General Public License version 3 (see the file LICENSE).
27
28 """BinaryPackageBuild interfaces."""
29@@ -23,10 +23,12 @@
30 from lazr.restful.declarations import (
31 error_status,
32 export_as_webservice_entry,
33+ export_read_operation,
34 export_write_operation,
35 exported,
36 operation_for_version,
37 operation_parameters,
38+ operation_returns_entry,
39 )
40 from lazr.restful.fields import Reference
41 from zope.interface import (
42@@ -220,6 +222,20 @@
43 `IBinaryPackageFile`, `ILibraryFileAlias`, `ILibraryFileContent`).
44 """
45
46+ @operation_returns_entry(ISourcePackagePublishingHistory)
47+ @export_read_operation()
48+ @operation_for_version("devel")
49+ def getLatestSourcePublication():
50+ """The latest source publication corresponding to this build.
51+
52+ Unlike current_source_publication, this returns publications even if
53+ they are no longer active.
54+
55+ :return: An `ISourcePackagePublishingHistory`, or None if no
56+ corresponding source publication can be located (which is a bug,
57+ but is true for some old production builds).
58+ """
59+
60
61 class IBinaryPackageBuildEdit(Interface):
62 """A Build interface for items requiring launchpad.Edit."""
63
64=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
65--- lib/lp/soyuz/interfaces/publishing.py 2014-11-09 09:01:26 +0000
66+++ lib/lp/soyuz/interfaces/publishing.py 2015-04-08 10:36:06 +0000
67@@ -1,4 +1,4 @@
68-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
69+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
70 # GNU Affero General Public License version 3 (see the file LICENSE).
71
72 """Publishing interfaces."""
73@@ -792,6 +792,13 @@
74 TextLine(
75 title=_("Binary Package Version"),
76 required=False, readonly=True))
77+ build = exported(
78+ Reference(
79+ # Really IBinaryPackageBuild, fixed in _schema_circular_imports.
80+ Interface,
81+ title=_("Build"),
82+ description=_("The build that produced this binary package."),
83+ required=True, readonly=True))
84 architecture_specific = exported(
85 Bool(
86 title=_("Architecture Specific"),
87
88=== modified file 'lib/lp/soyuz/model/binarypackagebuild.py'
89--- lib/lp/soyuz/model/binarypackagebuild.py 2015-02-11 14:43:23 +0000
90+++ lib/lp/soyuz/model/binarypackagebuild.py 2015-04-08 10:36:06 +0000
91@@ -1,4 +1,4 @@
92-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
93+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
94 # GNU Affero General Public License version 3 (see the file LICENSE).
95
96 __metaclass__ = type
97@@ -215,7 +215,7 @@
98 source_package_name = Reference(
99 source_package_name_id, 'SourcePackageName.id')
100
101- def _getLatestPublication(self):
102+ def getLatestSourcePublication(self):
103 from lp.soyuz.model.publishing import SourcePackagePublishingHistory
104 store = Store.of(self)
105 results = store.find(
106@@ -230,7 +230,7 @@
107 @property
108 def current_component(self):
109 """See `IBuild`."""
110- latest_publication = self._getLatestPublication()
111+ latest_publication = self.getLatestSourcePublication()
112 # Production has some buggy builds without source publications.
113 # They seem to have been created by early versions of gina and
114 # the readding of hppa.
115@@ -241,7 +241,7 @@
116 def current_source_publication(self):
117 """See `IBuild`."""
118 from lp.soyuz.interfaces.publishing import active_publishing_status
119- latest_publication = self._getLatestPublication()
120+ latest_publication = self.getLatestSourcePublication()
121 if (latest_publication is not None and
122 latest_publication.status in active_publishing_status):
123 return latest_publication
124
125=== modified file 'lib/lp/soyuz/model/publishing.py'
126--- lib/lp/soyuz/model/publishing.py 2014-11-09 09:01:26 +0000
127+++ lib/lp/soyuz/model/publishing.py 2015-04-08 10:36:06 +0000
128@@ -1,4 +1,4 @@
129-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
130+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
131 # GNU Affero General Public License version 3 (see the file LICENSE).
132
133 __metaclass__ = type
134@@ -769,6 +769,10 @@
135 return self.binarypackagerelease.version
136
137 @property
138+ def build(self):
139+ return self.binarypackagerelease.build
140+
141+ @property
142 def architecture_specific(self):
143 """See `IBinaryPackagePublishingHistory`"""
144 return self.binarypackagerelease.architecturespecific
145
146=== modified file 'lib/lp/soyuz/model/queue.py'
147--- lib/lp/soyuz/model/queue.py 2014-08-09 19:31:03 +0000
148+++ lib/lp/soyuz/model/queue.py 2015-04-08 10:36:06 +0000
149@@ -1,4 +1,4 @@
150-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
151+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
152 # GNU Affero General Public License version 3 (see the file LICENSE).
153
154 __metaclass__ = type
155@@ -879,7 +879,7 @@
156 first_build = self.builds[:1]
157 if first_build:
158 [first_build] = first_build
159- return first_build.build._getLatestPublication()
160+ return first_build.build.getLatestSourcePublication()
161 else:
162 return None
163
164
165=== modified file 'lib/lp/soyuz/tests/test_binarypackagebuild.py'
166--- lib/lp/soyuz/tests/test_binarypackagebuild.py 2014-10-31 07:00:29 +0000
167+++ lib/lp/soyuz/tests/test_binarypackagebuild.py 2015-04-08 10:36:06 +0000
168@@ -1,4 +1,4 @@
169-# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
170+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
171 # GNU Affero General Public License version 3 (see the file LICENSE).
172
173 """Test Build features."""
174@@ -188,6 +188,23 @@
175 self.assertEqual(BuildStatus.CANCELLING, build.status)
176 self.assertEqual(bq, build.buildqueue_record)
177
178+ def test_getLatestSourcePublication(self):
179+ distroseries = self.factory.makeDistroSeries()
180+ archive = self.factory.makeArchive(
181+ distribution=distroseries.distribution)
182+ other_archive = self.factory.makeArchive(
183+ distribution=distroseries.distribution)
184+ spph = self.factory.makeSourcePackagePublishingHistory(
185+ distroseries=distroseries, archive=archive)
186+ self.factory.makeSourcePackagePublishingHistory(
187+ distroseries=distroseries, archive=other_archive,
188+ sourcepackagerelease=spph.sourcepackagerelease)
189+ das = self.factory.makeDistroArchSeries(distroseries=distroseries)
190+ build = self.factory.makeBinaryPackageBuild(
191+ source_package_release=spph.sourcepackagerelease,
192+ distroarchseries=das, archive=archive)
193+ self.assertEqual(spph, build.getLatestSourcePublication())
194+
195
196 class TestBuildUpdateDependencies(TestCaseWithFactory):
197