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
1=== modified file 'lib/lp/soyuz/doc/publishing.txt'
2--- lib/lp/soyuz/doc/publishing.txt 2011-03-29 05:38:15 +0000
3+++ lib/lp/soyuz/doc/publishing.txt 2011-04-05 08:43:41 +0000
4@@ -923,7 +923,6 @@
5
6 >>> print bpph.getIndexStanza() #doctest: -NORMALIZE_WHITESPACE
7 Package: mozilla-firefox
8- Source: mozilla-firefox
9 Priority: important
10 Section: editors
11 Maintainer: Mark Shuttleworth <mark@canonical.com>
12
13=== modified file 'lib/lp/soyuz/model/publishing.py'
14--- lib/lp/soyuz/model/publishing.py 2011-03-24 05:21:26 +0000
15+++ lib/lp/soyuz/model/publishing.py 2011-04-05 08:43:41 +0000
16@@ -1007,9 +1007,15 @@
17 if bpr.essential:
18 essential = 'yes'
19
20+ source = None
21+ if bpr.version != spr.version:
22+ source = '%s (%s)' % (spr.name, spr.version)
23+ elif bpr.name != spr.name:
24+ source = spr.name
25+
26 fields = IndexStanzaFields()
27 fields.append('Package', bpr.name)
28- fields.append('Source', spr.name)
29+ fields.append('Source', source)
30 fields.append('Priority', self.priority.title.lower())
31 fields.append('Section', self.section.name)
32 fields.append('Installed-Size', bpr.installedsize)
33
34=== modified file 'lib/lp/soyuz/tests/test_publish_archive_indexes.py'
35--- lib/lp/soyuz/tests/test_publish_archive_indexes.py 2010-08-21 13:54:20 +0000
36+++ lib/lp/soyuz/tests/test_publish_archive_indexes.py 2011-04-05 08:43:41 +0000
37@@ -13,6 +13,10 @@
38 from lp.soyuz.tests.test_publishing import TestNativePublishingBase
39
40
41+def get_field(stanza_fields, name):
42+ return dict(stanza_fields.fields).get(name)
43+
44+
45 class TestNativeArchiveIndexes(TestNativePublishingBase):
46
47 def setUp(self):
48@@ -240,6 +244,33 @@
49 ],
50 pub_binary.getIndexStanza().splitlines())
51
52+ def testBinaryOmitsIdenticalSourceName(self):
53+ # Binaries omit the Source field if it identical to Package.
54+ pub_source = self.getPubSource(sourcename='foo')
55+ pub_binary = self.getPubBinaries(
56+ binaryname='foo', pub_source=pub_source)[0]
57+ self.assertIs(
58+ None,
59+ get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
60+
61+ def testBinaryIncludesDifferingSourceName(self):
62+ # Binaries include a Source field if their name differs.
63+ pub_source = self.getPubSource(sourcename='foo')
64+ pub_binary = self.getPubBinaries(
65+ binaryname='foo-bin', pub_source=pub_source)[0]
66+ self.assertEqual(
67+ u'foo',
68+ get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
69+
70+ def testBinaryIncludesDifferingSourceVersion(self):
71+ # Binaries also include a Source field if their versions differ.
72+ pub_source = self.getPubSource(sourcename='foo', version='666')
73+ pub_binary = self.getPubBinaries(
74+ binaryname='foo', version='999', pub_source=pub_source)[0]
75+ self.assertEqual(
76+ u'foo (666)',
77+ get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
78+
79
80 class TestNativeArchiveIndexesReparsing(TestNativePublishingBase):
81 """Tests for ensuring the native archive indexes that we publish
82
83=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
84--- lib/lp/soyuz/tests/test_publishing.py 2011-03-06 23:24:11 +0000
85+++ lib/lp/soyuz/tests/test_publishing.py 2011-04-05 08:43:41 +0000
86@@ -173,7 +173,7 @@
87
88 return package_upload
89
90- def getPubSource(self, sourcename=None, version='666', component='main',
91+ def getPubSource(self, sourcename=None, version=None, component='main',
92 filename=None, section='base',
93 filecontent='I do not care about sources.',
94 changes_file_content="Fake: fake changes file content",
95@@ -196,6 +196,8 @@
96 """
97 if sourcename is None:
98 sourcename = self.default_package_name
99+ if version is None:
100+ version = '666'
101 spn = getUtility(ISourcePackageNameSet).getOrCreateByName(sourcename)
102
103 component = getUtility(IComponentSet)[component]
104@@ -292,7 +294,7 @@
105 distroseries=None,
106 archive=None,
107 pub_source=None,
108- version='666',
109+ version=None,
110 architecturespecific=False,
111 builder=None,
112 component='main',
113@@ -329,7 +331,7 @@
114 build, binaryname + '-dbgsym', filecontent, summary,
115 description, shlibdep, depends, recommends, suggests,
116 conflicts, replaces, provides, pre_depends, enhances,
117- breaks, BinaryPackageFormat.DDEB)
118+ breaks, BinaryPackageFormat.DDEB, version=version)
119 pub_binaries += self.publishBinaryInArchive(
120 binarypackagerelease_ddeb, archive.debug_archive, status,
121 pocket, scheduleddeletiondate, dateremoved)
122@@ -340,7 +342,7 @@
123 build, binaryname, filecontent, summary, description,
124 shlibdep, depends, recommends, suggests, conflicts, replaces,
125 provides, pre_depends, enhances, breaks, format,
126- binarypackagerelease_ddeb,
127+ binarypackagerelease_ddeb, version=version,
128 user_defined_fields=user_defined_fields)
129 pub_binaries += self.publishBinaryInArchive(
130 binarypackagerelease, archive, status, pocket,
131@@ -363,7 +365,7 @@
132 depends=None, recommends=None, suggests=None, conflicts=None,
133 replaces=None, provides=None, pre_depends=None, enhances=None,
134 breaks=None, format=BinaryPackageFormat.DEB, debug_package=None,
135- user_defined_fields=None, homepage=None):
136+ user_defined_fields=None, homepage=None, version=None):
137 """Return the corresponding `BinaryPackageRelease`."""
138 sourcepackagerelease = build.source_package_release
139 distroarchseries = build.distro_arch_series
140@@ -373,8 +375,11 @@
141 binarypackagename = getUtility(
142 IBinaryPackageNameSet).getOrCreateByName(binaryname)
143
144+ if version is None:
145+ version = sourcepackagerelease.version
146+
147 binarypackagerelease = build.createBinaryPackageRelease(
148- version=sourcepackagerelease.version,
149+ version=version,
150 component=sourcepackagerelease.component,
151 section=sourcepackagerelease.section,
152 binarypackagename=binarypackagename,