← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/refactor-nuf-creation into lp:launchpad/devel

 

William Grant has proposed merging lp:~wgrant/launchpad/refactor-nuf-creation into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


This branch factors out and tests part of ChangesFile.processFiles. This will be used by a later branch to enable NascentUpload tests without having to create real uploads.
-- 
https://code.launchpad.net/~wgrant/launchpad/refactor-nuf-creation/+merge/30851
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/refactor-nuf-creation into lp:launchpad/devel.
=== modified file 'lib/lp/archiveuploader/changesfile.py'
--- lib/lp/archiveuploader/changesfile.py	2009-10-12 09:55:31 +0000
+++ lib/lp/archiveuploader/changesfile.py	2010-07-24 10:12:53 +0000
@@ -21,10 +21,13 @@
     DebBinaryUploadFile, SourceUploadFile, UdebBinaryUploadFile,
     UploadError, UploadWarning, splitComponentAndSection)
 from lp.archiveuploader.utils import (
+    determine_binary_file_type, determine_source_file_type,
     re_isadeb, re_issource, re_changes_file_name)
 from lp.archiveuploader.tagfiles import (
     parse_tagfile, TagFileParseError)
-from canonical.launchpad.interfaces import SourcePackageUrgency
+from lp.registry.interfaces.sourcepackage import (SourcePackageFileType,
+    SourcePackageUrgency)
+from lp.soyuz.interfaces.binarypackagerelease import BinaryPackageFileType
 
 
 class ChangesFile(SignableTagFile):
@@ -161,8 +164,6 @@
             # CHECKSUM SIZE [COMPONENT/]SECTION PRIORITY FILENAME
             digest, size, component_and_section, priority_name, filename = (
                 fileline.strip().split())
-            source_match = re_issource.match(filename)
-            binary_match = re_isadeb.match(filename)
             filepath = os.path.join(self.dirname, filename)
             try:
                 if self.isCustom(component_and_section):
@@ -172,42 +173,22 @@
                     file_instance = CustomUploadFile(
                         filepath, digest, size, component_and_section,
                         priority_name, self.policy, self.logger)
-                elif source_match:
-                    package = source_match.group(1)
-                    if filename.endswith("dsc"):
-                        file_instance = DSCFile(
-                            filepath, digest, size, component_and_section,
-                            priority_name, package, self.version, self,
-                            self.policy, self.logger)
-                        # Store the DSC because it is very convenient
+                else:
+                    package, cls = determine_file_class_and_name(filename)
+
+                    if cls is None:
+                        yield UploadError(
+                            "Unable to identify file %s (%s) in changes."
+                            % (filename, component_and_section))
+                        continue
+
+                    file_instance = cls(
+                        filepath, digest, size, component_and_section,
+                        priority_name, package, self.version, self,
+                        self.policy, self.logger)
+
+                    if cls == DSCFile:
                         self.dsc = file_instance
-                    else:
-                        file_instance = SourceUploadFile(
-                            filepath, digest, size, component_and_section,
-                            priority_name, package, self.version, self,
-                            self.policy, self.logger)
-                elif binary_match:
-                    package = binary_match.group(1)
-                    if filename.endswith("udeb"):
-                        file_instance = UdebBinaryUploadFile(
-                            filepath, digest, size, component_and_section,
-                            priority_name, package, self.version, self,
-                            self.policy, self.logger)
-                    elif filename.endswith("ddeb"):
-                        file_instance = DdebBinaryUploadFile(
-                            filepath, digest, size, component_and_section,
-                            priority_name, package, self.version, self,
-                            self.policy, self.logger)
-                    else:
-                        file_instance = DebBinaryUploadFile(
-                            filepath, digest, size, component_and_section,
-                            priority_name, package, self.version, self,
-                            self.policy, self.logger)
-                else:
-                    yield UploadError(
-                        "Unable to identify file %s (%s) in changes."
-                        % (filename, component_and_section))
-                    continue
             except UploadError, error:
                 yield error
             else:
@@ -362,3 +343,25 @@
         return self.changes_comment + changes_author
 
 
+def determine_file_class_and_name(filename):
+    """Determine the name and PackageUploadFile subclass for the filename."""
+    source_match = re_issource.match(filename)
+    binary_match = re_isadeb.match(filename)
+    if source_match:
+        package = source_match.group(1)
+        if (determine_source_file_type(filename) ==
+            SourcePackageFileType.DSC):
+            cls = DSCFile
+        else:
+            cls = SourceUploadFile
+    elif binary_match:
+        package = binary_match.group(1)
+        cls = {
+            BinaryPackageFileType.DEB: DebBinaryUploadFile,
+            BinaryPackageFileType.DDEB: DdebBinaryUploadFile,
+            BinaryPackageFileType.UDEB: UdebBinaryUploadFile,
+            }[determine_binary_file_type(filename)]
+    else:
+        return None, None
+
+    return package, cls

=== added file 'lib/lp/archiveuploader/tests/test_changesfile.py'
--- lib/lp/archiveuploader/tests/test_changesfile.py	1970-01-01 00:00:00 +0000
+++ lib/lp/archiveuploader/tests/test_changesfile.py	2010-07-24 10:12:53 +0000
@@ -0,0 +1,52 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Test ChangesFile functionality."""
+
+__metaclass__ = type
+
+from testtools import TestCase
+
+from lp.archiveuploader.changesfile import determine_file_class_and_name
+from lp.archiveuploader.dscfile import DSCFile
+from lp.archiveuploader.nascentuploadfile import (
+    DebBinaryUploadFile, DdebBinaryUploadFile, SourceUploadFile,
+    UdebBinaryUploadFile)
+
+
+class TestDetermineFileClassAndName(TestCase):
+
+    def testSourceFile(self):
+        # A non-DSC source file is a SourceUploadFile.
+        self.assertEquals(
+            ('foo', SourceUploadFile),
+            determine_file_class_and_name('foo_1.0.diff.gz'))
+
+    def testDSCFile(self):
+        # A DSC is a DSCFile, since they're special.
+        self.assertEquals(
+            ('foo', DSCFile),
+            determine_file_class_and_name('foo_1.0.dsc'))
+
+    def testDEBFile(self):
+        # A binary file is the appropriate PackageUploadFile subclass.
+        self.assertEquals(
+            ('foo', DebBinaryUploadFile),
+            determine_file_class_and_name('foo_1.0_all.deb'))
+        self.assertEquals(
+            ('foo', DdebBinaryUploadFile),
+            determine_file_class_and_name('foo_1.0_all.ddeb'))
+        self.assertEquals(
+            ('foo', UdebBinaryUploadFile),
+            determine_file_class_and_name('foo_1.0_all.udeb'))
+
+    def testUnmatchingFile(self):
+        # Files with unknown extensions or none at all are not
+        # identified.
+        self.assertEquals(
+            (None, None),
+            determine_file_class_and_name('foo_1.0.notdsc'))
+        self.assertEquals(
+            (None, None),
+            determine_file_class_and_name('foo'))
+

=== modified file 'lib/lp/archiveuploader/tests/test_utils.py'
--- lib/lp/archiveuploader/tests/test_utils.py	2010-07-18 00:26:33 +0000
+++ lib/lp/archiveuploader/tests/test_utils.py	2010-07-24 10:12:53 +0000
@@ -81,6 +81,11 @@
             determine_binary_file_type('foo_1.0-1_all.deb'),
             BinaryPackageFileType.DEB)
 
+        # .ddeb -> DDEB
+        self.assertEquals(
+            determine_binary_file_type('foo_1.0-1_all.ddeb'),
+            BinaryPackageFileType.DDEB)
+
         # .udeb -> UDEB
         self.assertEquals(
             determine_binary_file_type('foo_1.0-1_all.udeb'),

=== modified file 'lib/lp/archiveuploader/utils.py'
--- lib/lp/archiveuploader/utils.py	2009-12-10 13:53:30 +0000
+++ lib/lp/archiveuploader/utils.py	2010-07-24 10:12:53 +0000
@@ -98,6 +98,8 @@
         return BinaryPackageFileType.DEB
     elif filename.endswith(".udeb"):
         return BinaryPackageFileType.UDEB
+    elif filename.endswith(".ddeb"):
+        return BinaryPackageFileType.DDEB
     else:
         return None