Merge lp:~wgrant/launchpad/bug-750640 into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 12746
Proposed branch: lp:~wgrant/launchpad/bug-750640
Merge into: lp:launchpad
Diff against target: 152 lines (+49/-8)
4 files modified
lib/lp/soyuz/doc/publishing.txt (+0/-1)
lib/lp/soyuz/model/publishing.py (+7/-1)
lib/lp/soyuz/tests/test_publish_archive_indexes.py (+31/-0)
lib/lp/soyuz/tests/test_publishing.py (+11/-6)
To merge this branch: bzr merge lp:~wgrant/launchpad/bug-750640
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+56276@code.launchpad.net

Commit message

[r=lifeless][bug=750640] Fix Source field generation rules in NMAF Packages files.

Description of the change

Stanzas in apt Packages files only need to include the Source field if the details differ from the binary's. If the name differs, it should be "Source: sourcename". If the version differs, it should be "Source: sourcename (sourceversion)". NMAF always acts as if the name differs, never omitting the field nor including the version.

This branch fixes that behaviour, and adds tests.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

+def get_field(stanza_fields, name):
30 + for key, value in stanza_fields.fields:
31 + if key == name:
32 + return value

isn't that just
dict(stanza_fields.fields).get(name)
?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/soyuz/doc/publishing.txt'
--- lib/lp/soyuz/doc/publishing.txt 2011-03-29 05:38:15 +0000
+++ lib/lp/soyuz/doc/publishing.txt 2011-04-05 08:43:41 +0000
@@ -923,7 +923,6 @@
923923
924 >>> print bpph.getIndexStanza() #doctest: -NORMALIZE_WHITESPACE924 >>> print bpph.getIndexStanza() #doctest: -NORMALIZE_WHITESPACE
925 Package: mozilla-firefox925 Package: mozilla-firefox
926 Source: mozilla-firefox
927 Priority: important926 Priority: important
928 Section: editors927 Section: editors
929 Maintainer: Mark Shuttleworth <mark@canonical.com>928 Maintainer: Mark Shuttleworth <mark@canonical.com>
930929
=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py 2011-03-24 05:21:26 +0000
+++ lib/lp/soyuz/model/publishing.py 2011-04-05 08:43:41 +0000
@@ -1007,9 +1007,15 @@
1007 if bpr.essential:1007 if bpr.essential:
1008 essential = 'yes'1008 essential = 'yes'
10091009
1010 source = None
1011 if bpr.version != spr.version:
1012 source = '%s (%s)' % (spr.name, spr.version)
1013 elif bpr.name != spr.name:
1014 source = spr.name
1015
1010 fields = IndexStanzaFields()1016 fields = IndexStanzaFields()
1011 fields.append('Package', bpr.name)1017 fields.append('Package', bpr.name)
1012 fields.append('Source', spr.name)1018 fields.append('Source', source)
1013 fields.append('Priority', self.priority.title.lower())1019 fields.append('Priority', self.priority.title.lower())
1014 fields.append('Section', self.section.name)1020 fields.append('Section', self.section.name)
1015 fields.append('Installed-Size', bpr.installedsize)1021 fields.append('Installed-Size', bpr.installedsize)
10161022
=== modified file 'lib/lp/soyuz/tests/test_publish_archive_indexes.py'
--- lib/lp/soyuz/tests/test_publish_archive_indexes.py 2010-08-21 13:54:20 +0000
+++ lib/lp/soyuz/tests/test_publish_archive_indexes.py 2011-04-05 08:43:41 +0000
@@ -13,6 +13,10 @@
13from lp.soyuz.tests.test_publishing import TestNativePublishingBase13from lp.soyuz.tests.test_publishing import TestNativePublishingBase
1414
1515
16def get_field(stanza_fields, name):
17 return dict(stanza_fields.fields).get(name)
18
19
16class TestNativeArchiveIndexes(TestNativePublishingBase):20class TestNativeArchiveIndexes(TestNativePublishingBase):
1721
18 def setUp(self):22 def setUp(self):
@@ -240,6 +244,33 @@
240 ],244 ],
241 pub_binary.getIndexStanza().splitlines())245 pub_binary.getIndexStanza().splitlines())
242246
247 def testBinaryOmitsIdenticalSourceName(self):
248 # Binaries omit the Source field if it identical to Package.
249 pub_source = self.getPubSource(sourcename='foo')
250 pub_binary = self.getPubBinaries(
251 binaryname='foo', pub_source=pub_source)[0]
252 self.assertIs(
253 None,
254 get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
255
256 def testBinaryIncludesDifferingSourceName(self):
257 # Binaries include a Source field if their name differs.
258 pub_source = self.getPubSource(sourcename='foo')
259 pub_binary = self.getPubBinaries(
260 binaryname='foo-bin', pub_source=pub_source)[0]
261 self.assertEqual(
262 u'foo',
263 get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
264
265 def testBinaryIncludesDifferingSourceVersion(self):
266 # Binaries also include a Source field if their versions differ.
267 pub_source = self.getPubSource(sourcename='foo', version='666')
268 pub_binary = self.getPubBinaries(
269 binaryname='foo', version='999', pub_source=pub_source)[0]
270 self.assertEqual(
271 u'foo (666)',
272 get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
273
243274
244class TestNativeArchiveIndexesReparsing(TestNativePublishingBase):275class TestNativeArchiveIndexesReparsing(TestNativePublishingBase):
245 """Tests for ensuring the native archive indexes that we publish276 """Tests for ensuring the native archive indexes that we publish
246277
=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
--- lib/lp/soyuz/tests/test_publishing.py 2011-03-06 23:24:11 +0000
+++ lib/lp/soyuz/tests/test_publishing.py 2011-04-05 08:43:41 +0000
@@ -173,7 +173,7 @@
173173
174 return package_upload174 return package_upload
175175
176 def getPubSource(self, sourcename=None, version='666', component='main',176 def getPubSource(self, sourcename=None, version=None, component='main',
177 filename=None, section='base',177 filename=None, section='base',
178 filecontent='I do not care about sources.',178 filecontent='I do not care about sources.',
179 changes_file_content="Fake: fake changes file content",179 changes_file_content="Fake: fake changes file content",
@@ -196,6 +196,8 @@
196 """196 """
197 if sourcename is None:197 if sourcename is None:
198 sourcename = self.default_package_name198 sourcename = self.default_package_name
199 if version is None:
200 version = '666'
199 spn = getUtility(ISourcePackageNameSet).getOrCreateByName(sourcename)201 spn = getUtility(ISourcePackageNameSet).getOrCreateByName(sourcename)
200202
201 component = getUtility(IComponentSet)[component]203 component = getUtility(IComponentSet)[component]
@@ -292,7 +294,7 @@
292 distroseries=None,294 distroseries=None,
293 archive=None,295 archive=None,
294 pub_source=None,296 pub_source=None,
295 version='666',297 version=None,
296 architecturespecific=False,298 architecturespecific=False,
297 builder=None,299 builder=None,
298 component='main',300 component='main',
@@ -329,7 +331,7 @@
329 build, binaryname + '-dbgsym', filecontent, summary,331 build, binaryname + '-dbgsym', filecontent, summary,
330 description, shlibdep, depends, recommends, suggests,332 description, shlibdep, depends, recommends, suggests,
331 conflicts, replaces, provides, pre_depends, enhances,333 conflicts, replaces, provides, pre_depends, enhances,
332 breaks, BinaryPackageFormat.DDEB)334 breaks, BinaryPackageFormat.DDEB, version=version)
333 pub_binaries += self.publishBinaryInArchive(335 pub_binaries += self.publishBinaryInArchive(
334 binarypackagerelease_ddeb, archive.debug_archive, status,336 binarypackagerelease_ddeb, archive.debug_archive, status,
335 pocket, scheduleddeletiondate, dateremoved)337 pocket, scheduleddeletiondate, dateremoved)
@@ -340,7 +342,7 @@
340 build, binaryname, filecontent, summary, description,342 build, binaryname, filecontent, summary, description,
341 shlibdep, depends, recommends, suggests, conflicts, replaces,343 shlibdep, depends, recommends, suggests, conflicts, replaces,
342 provides, pre_depends, enhances, breaks, format,344 provides, pre_depends, enhances, breaks, format,
343 binarypackagerelease_ddeb,345 binarypackagerelease_ddeb, version=version,
344 user_defined_fields=user_defined_fields)346 user_defined_fields=user_defined_fields)
345 pub_binaries += self.publishBinaryInArchive(347 pub_binaries += self.publishBinaryInArchive(
346 binarypackagerelease, archive, status, pocket,348 binarypackagerelease, archive, status, pocket,
@@ -363,7 +365,7 @@
363 depends=None, recommends=None, suggests=None, conflicts=None,365 depends=None, recommends=None, suggests=None, conflicts=None,
364 replaces=None, provides=None, pre_depends=None, enhances=None,366 replaces=None, provides=None, pre_depends=None, enhances=None,
365 breaks=None, format=BinaryPackageFormat.DEB, debug_package=None,367 breaks=None, format=BinaryPackageFormat.DEB, debug_package=None,
366 user_defined_fields=None, homepage=None):368 user_defined_fields=None, homepage=None, version=None):
367 """Return the corresponding `BinaryPackageRelease`."""369 """Return the corresponding `BinaryPackageRelease`."""
368 sourcepackagerelease = build.source_package_release370 sourcepackagerelease = build.source_package_release
369 distroarchseries = build.distro_arch_series371 distroarchseries = build.distro_arch_series
@@ -373,8 +375,11 @@
373 binarypackagename = getUtility(375 binarypackagename = getUtility(
374 IBinaryPackageNameSet).getOrCreateByName(binaryname)376 IBinaryPackageNameSet).getOrCreateByName(binaryname)
375377
378 if version is None:
379 version = sourcepackagerelease.version
380
376 binarypackagerelease = build.createBinaryPackageRelease(381 binarypackagerelease = build.createBinaryPackageRelease(
377 version=sourcepackagerelease.version,382 version=version,
378 component=sourcepackagerelease.component,383 component=sourcepackagerelease.component,
379 section=sourcepackagerelease.section,384 section=sourcepackagerelease.section,
380 binarypackagename=binarypackagename,385 binarypackagename=binarypackagename,