← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jelmer/launchpad/publisher-use-debian-2 into lp:launchpad

 

Jelmer Vernooij has proposed merging lp:~jelmer/launchpad/publisher-use-debian-2 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jelmer/launchpad/publisher-use-debian-2/+merge/45011

Make more use of the standard python-debian rather than our custom file generators in the publisher.

Also, clean up some lint in the related files.
-- 
https://code.launchpad.net/~jelmer/launchpad/publisher-use-debian-2/+merge/45011
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jelmer/launchpad/publisher-use-debian-2 into lp:launchpad.
=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2010-12-15 23:34:35 +0000
+++ lib/lp/soyuz/model/publishing.py	2011-01-02 23:08:53 +0000
@@ -18,6 +18,7 @@
 
 from collections import defaultdict
 from datetime import datetime
+from debian.deb822 import Packages, Sources
 import operator
 import os
 import re
@@ -352,7 +353,8 @@
 class IndexStanzaFields:
     """Store and format ordered Index Stanza fields."""
 
-    def __init__(self):
+    def __init__(self, klass):
+        self.klass = klass
         self.fields = []
 
     def append(self, name, value):
@@ -373,36 +375,33 @@
         Empty fields values will cause the exclusion of the field.
         The output order will preserve the insertion order, FIFO.
         """
-        output_lines = []
+        stanza = self.klass()
         for name, value in self.fields:
             if not value:
                 continue
 
-            # do not add separation space for the special field 'Files'
-            if name != 'Files':
-                value = ' %s' % value
-
-            # XXX Michael Nelson 20090930 bug=436182. We have an issue
-            # in the upload parser that has
-            #   1. introduced '\n' at the end of multiple-line-spanning
-            #      fields, such as dsc_binaries, but potentially others,
-            #   2. stripped the leading space from each subsequent line
-            #      of dsc_binaries values that span multiple lines.
-            # This is causing *incorrect* Source indexes to be created.
-            # This work-around can be removed once the fix for bug 436182
-            # is in place and the tainted data has been cleaned.
-            # First, remove any trailing \n or spaces.
-            value = value.rstrip()
-
-            # Second, as we have corrupt data where subsequent lines
-            # of values spanning multiple lines are not preceded by a
-            # space, we ensure that any \n in the value that is *not*
-            # followed by a white-space character has a space inserted.
-            value = re.sub(r"\n(\S)", r"\n \1", value)
-
-            output_lines.append('%s:%s' % (name, value))
-
-        return '\n'.join(output_lines)
+            if isinstance(value, basestring):
+                # XXX Michael Nelson 20090930 bug=436182. We have an issue
+                # in the upload parser that has
+                #   1. introduced '\n' at the end of multiple-line-spanning
+                #      fields, such as dsc_binaries, but potentially others,
+                #   2. stripped the leading space from each subsequent line
+                #      of dsc_binaries values that span multiple lines.
+                # This is causing *incorrect* Source indexes to be created.
+                # This work-around can be removed once the fix for bug 436182
+                # is in place and the tainted data has been cleaned.
+                # First, remove any trailing \n or spaces.
+                value = value.rstrip()
+
+                # Second, as we have corrupt data where subsequent lines
+                # of values spanning multiple lines are not preceded by a
+                # space, we ensure that any \n in the value that is *not*
+                # followed by a white-space character has a space inserted.
+                value = re.sub(r"\n(\S)", r"\n \1", value)
+
+            stanza[name] = value
+
+        return stanza.dump()
 
 
 class SourcePackagePublishingHistory(SQLBase, ArchivePublisherBase):
@@ -680,13 +679,13 @@
         # Special fields preparation.
         spr = self.sourcepackagerelease
         pool_path = makePoolPath(spr.name, self.component.name)
-        files_subsection = ''.join(
-            ['\n %s %s %s' % (spf.libraryfile.content.md5,
-                              spf.libraryfile.content.filesize,
-                              spf.libraryfile.filename)
-             for spf in spr.files])
+        files_subsection = [{
+            'md5sum': spf.libraryfile.content.md5,
+            'size': spf.libraryfile.content.filesize,
+            'name': spf.libraryfile.filename} for spf in spr.files]
+
         # Filling stanza options.
-        fields = IndexStanzaFields()
+        fields = IndexStanzaFields(Sources)
         fields.append('Package', spr.name)
         fields.append('Binary', spr.dsc_binaries)
         fields.append('Version', spr.version)
@@ -816,7 +815,6 @@
         assert self.component in (
             self.archive.getComponentsForSeries(self.distroseries))
 
-
     def _proxied_urls(self, files, parent):
         """Run the files passed through `ProxiedLibraryFileAlias`."""
         return [
@@ -969,7 +967,7 @@
         if bpr.essential:
             essential = 'yes'
 
-        fields = IndexStanzaFields()
+        fields = IndexStanzaFields(Packages)
         fields.append('Package', bpr.name)
         fields.append('Source', spr.name)
         fields.append('Priority', self.priority.title.lower())

=== 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-01-02 23:08:53 +0000
@@ -3,12 +3,12 @@
 
 """Test native archive index generation for Soyuz."""
 
+import apt_pkg
+from debian.deb822 import Packages, Sources
 import os
 import tempfile
 import unittest
 
-import apt_pkg
-
 from lp.soyuz.model.publishing import IndexStanzaFields
 from lp.soyuz.tests.test_publishing import TestNativePublishingBase
 
@@ -55,7 +55,7 @@
             pub_source.getIndexStanza().splitlines())
 
     def testSourceStanzaCustomFields(self):
-        """Check just-created source publication Index stanza 
+        """Check just-created source publication Index stanza
         with custom fields (Python-Version).
         """
         pub_source = self.getPubSource(
@@ -370,17 +370,16 @@
 
 
 class TestIndexStanzaFieldsHelper(unittest.TestCase):
-    """Check how this auxiliary class works...
-
-    This class provides simple FIFO API for aggregating fields
-    (name & values) in a ordered way.
-
-    Provides an method to format the option in a ready-to-use string.
-    """
-
 
     def test_simple(self):
-        fields = IndexStanzaFields()
+        """Check how this auxiliary class works...
+
+        This class provides simple FIFO API for aggregating fields
+        (name & values) in a ordered way.
+
+        Provides an method to format the option in a ready-to-use string.
+        """
+        fields = IndexStanzaFields(Packages)
         fields.append('breakfast', 'coffee')
         fields.append('lunch', 'beef')
         fields.append('dinner', 'fish')
@@ -392,7 +391,7 @@
              ], fields.makeOutput().splitlines())
 
     def test_preserves_order(self):
-        fields = IndexStanzaFields()
+        fields = IndexStanzaFields(Packages)
         fields.append('one', 'um')
         fields.append('three', 'tres')
         fields.append('two', 'dois')
@@ -406,15 +405,18 @@
         # Special treatment for field named 'Files'
         # do not add a space between <name>:<value>
         # <value> will always start with a new line.
-        fields = IndexStanzaFields()
+        fields = IndexStanzaFields(Sources)
         fields.append('one', 'um')
-        fields.append('Files', '<no_sep>')
-
+        fields.append('Files', {
+            "md5sum": "foo",
+            "size": "42",
+            "name": "universe"})
         self.assertEqual(
-            ['one: um', 'Files:<no_sep>'], fields.makeOutput().splitlines())
+            ['one: um', 'Files:  foo 42 universe'],
+            fields.makeOutput().splitlines())
 
     def test_extend(self):
-        fields = IndexStanzaFields()
+        fields = IndexStanzaFields(Sources)
         fields.append('one', 'um')
         fields.extend([('three', 'tres'), ['four', 'five']])