Merge lp:~wgrant/launchpad/kill-bpb-is_new into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 16978
Proposed branch: lp:~wgrant/launchpad/kill-bpb-is_new
Merge into: lp:launchpad
Diff against target: 166 lines (+39/-45)
5 files modified
lib/lp/soyuz/doc/binarypackagerelease.txt (+1/-14)
lib/lp/soyuz/interfaces/binarypackagerelease.py (+0/-9)
lib/lp/soyuz/model/binarypackagerelease.py (+0/-21)
lib/lp/soyuz/model/queue.py (+22/-1)
lib/lp/soyuz/tests/test_packageupload.py (+16/-0)
To merge this branch: bzr merge lp:~wgrant/launchpad/kill-bpb-is_new
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+215069@code.launchpad.net

Commit message

Move the BinaryPackageRelease NEWness check to PackageUploadBuild, to get some of the DAS- and archive-specific bits out of the agnostic BinaryPackageRelease.

Description of the change

This branch moves some context-specific properties from BinaryPackageRelease to PackageUploadBuild. They're still evil and context-specific, but they're at least not on the archive- and DAS-agnostic BinaryPackageRelease object.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Nice cleanup!

There is a weird behaviour of makeBinaryPackageUpload() in the test that forces you to check properties of the *second* binary (when it should be only one). But that is unrelated to this change and surely manifest itself in many other tests, let's fix it later.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/doc/binarypackagerelease.txt'
2--- lib/lp/soyuz/doc/binarypackagerelease.txt 2012-12-26 01:32:19 +0000
3+++ lib/lp/soyuz/doc/binarypackagerelease.txt 2014-04-10 02:37:07 +0000
4@@ -35,20 +35,6 @@
5 ... firefox_bin_release.distributionsourcepackagerelease)
6 True
7
8-The 'is_new' property tells us whether or not this
9-BinaryPackageRelease has ever been published for the DistroArchSeries
10-it was built for. If not, then 'is_new' will be True, otherwise False.
11-
12- >>> firefox_bin_release.is_new
13- False
14-
15- >>> pmount_bin_release = BinaryPackageRelease.get(20)
16- >>> pmount_bin_release.name, pmount_bin_release.version
17- (u'pmount', u'0.1-1')
18-
19- >>> pmount_bin_release.is_new
20- True
21-
22 The IBinaryPackageNameSet.getNotNewByNames() returns all the
23 BinaryPackageName records for BinaryPackageReleases that are published
24 in the supplied distroseries in the archives with the supplied
25@@ -61,6 +47,7 @@
26 >>> from lp.soyuz.interfaces.binarypackagename import (
27 ... IBinaryPackageNameSet)
28 >>> foobar_name = getUtility(IBinaryPackageNameSet)['foobar']
29+ >>> pmount_bin_release = BinaryPackageRelease.get(20)
30 >>> name_ids = (
31 ... foobar_name.id,
32 ... pmount_bin_release.binarypackagename.id,
33
34=== modified file 'lib/lp/soyuz/interfaces/binarypackagerelease.py'
35--- lib/lp/soyuz/interfaces/binarypackagerelease.py 2013-01-07 02:40:55 +0000
36+++ lib/lp/soyuz/interfaces/binarypackagerelease.py 2014-04-10 02:37:07 +0000
37@@ -26,7 +26,6 @@
38 Bool,
39 Date,
40 Datetime,
41- Dict,
42 Int,
43 List,
44 Object,
45@@ -92,14 +91,6 @@
46 "The sourcepackage release in this distribution from which this "
47 "binary was built.")
48
49- is_new = Bool(
50- title=_("New Binary."),
51- description=_("True if there binary version was never published for "
52- "the architeture it was built for. False otherwise."))
53-
54- # This is a dictionary for fast retrieval over the webservice.
55- properties = Dict(title=_("The properties of this binary."))
56-
57 def addFile(file):
58 """Create a BinaryPackageFile record referencing this build
59 and attach the provided library file alias (file).
60
61=== modified file 'lib/lp/soyuz/model/binarypackagerelease.py'
62--- lib/lp/soyuz/model/binarypackagerelease.py 2013-01-07 02:40:55 +0000
63+++ lib/lp/soyuz/model/binarypackagerelease.py 2014-04-10 02:37:07 +0000
64@@ -121,27 +121,6 @@
65 """See `IBinaryPackageRelease`."""
66 return self.build.source_package_release.sourcepackagename.name
67
68- @property
69- def is_new(self):
70- """See `IBinaryPackageRelease`."""
71- distroarchseries = self.build.distro_arch_series
72- distroarchseries_binary_package = distroarchseries.getBinaryPackage(
73- self.binarypackagename)
74- return distroarchseries_binary_package.currentrelease is None
75-
76- @property
77- def properties(self):
78- """See `IBinaryPackageRelease`."""
79- return {
80- "name": self.name,
81- "version": self.version,
82- "is_new": self.is_new,
83- "architecture": self.build.arch_tag,
84- "component": self.component.name,
85- "section": self.section.name,
86- "priority": self.priority.name,
87- }
88-
89 @cachedproperty
90 def files(self):
91 return list(
92
93=== modified file 'lib/lp/soyuz/model/queue.py'
94--- lib/lp/soyuz/model/queue.py 2013-12-20 05:42:43 +0000
95+++ lib/lp/soyuz/model/queue.py 2014-04-10 02:37:07 +0000
96@@ -1150,6 +1150,27 @@
97 return made_changes
98
99
100+def get_properties_for_binary(bpr):
101+ # XXX wgrant 2014-04-08: This is so, so wrong, as it assumes that
102+ # the BPR is only ever published where it was built. But that holds
103+ # whenever this code is called for now, as copies don't use
104+ # PackageUploadBuild.
105+ das = bpr.build.distro_arch_series
106+ distroarchseries_binary_package = das.getBinaryPackage(
107+ bpr.binarypackagename)
108+ is_new = distroarchseries_binary_package.currentrelease is None
109+
110+ return {
111+ "name": bpr.name,
112+ "version": bpr.version,
113+ "is_new": is_new,
114+ "architecture": bpr.build.arch_tag,
115+ "component": bpr.component.name,
116+ "section": bpr.section.name,
117+ "priority": bpr.priority.name,
118+ }
119+
120+
121 class PackageUploadBuild(SQLBase):
122 """A Queue item's related builds."""
123 implements(IPackageUploadBuild)
124@@ -1166,7 +1187,7 @@
125 def binaries(self):
126 """See `IPackageUploadBuild`."""
127 for binary in self.build.binarypackages:
128- yield binary.properties
129+ yield get_properties_for_binary(binary)
130
131 def checkComponentAndSection(self):
132 """See `IPackageUploadBuild`."""
133
134=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
135--- lib/lp/soyuz/tests/test_packageupload.py 2013-06-20 05:50:00 +0000
136+++ lib/lp/soyuz/tests/test_packageupload.py 2014-04-10 02:37:07 +0000
137@@ -34,6 +34,7 @@
138 from lp.services.mail.sendmail import format_address_for_person
139 from lp.soyuz.adapters.overrides import SourceOverride
140 from lp.soyuz.enums import (
141+ PackagePublishingStatus,
142 PackageUploadCustomFormat,
143 PackageUploadStatus,
144 )
145@@ -1135,6 +1136,21 @@
146 self.assertCanOpenRedirectedUrl(browser, ws_binary_file_url)
147 self.assertCanOpenRedirectedUrl(browser, ws_upload.changes_file_url)
148
149+ def test_binary_is_new(self):
150+ # The is_new property is False if a binary with this name has
151+ # already been published in the same DistroArchSeries.
152+ person = self.makeQueueAdmin([self.universe])
153+ upload, ws_upload = self.makeBinaryPackageUpload(
154+ person, binarypackagename="hello")
155+ self.assertTrue(ws_upload.getBinaryProperties()[1]['is_new'])
156+ with person_logged_in(person):
157+ das = upload.builds[0].build.distro_arch_series
158+ self.factory.makeBinaryPackagePublishingHistory(
159+ binarypackagename="hello", archive=das.main_archive,
160+ distroarchseries=das, status=PackagePublishingStatus.PUBLISHED)
161+ transaction.commit()
162+ self.assertFalse(ws_upload.getBinaryProperties()[1]['is_new'])
163+
164 def test_overrideBinaries_limited_component_permissions(self):
165 # Overriding between two components requires queue admin of both.
166 person = self.makeQueueAdmin([self.universe])