]> git.decadent.org.uk Git - dak.git/commitdiff
Use a collections.defaultdict to avoid boilerplate definitions.
authorChris Lamb <lamby@debian.org>
Tue, 27 Oct 2009 10:52:33 +0000 (10:52 +0000)
committerChris Lamb <lamby@debian.org>
Tue, 27 Oct 2009 10:52:33 +0000 (10:52 +0000)
Signed-off-by: Chris Lamb <lamby@debian.org>
daklib/srcformats.py
daklib/utils.py

index 90459ef35a95562f9f7dc61d5c068779adfd6c93..e454e2bd444e900a8b47ff8b786f65aeba2ad80d 100644 (file)
@@ -19,12 +19,12 @@ class FormatOne(object):
     format = r'1.0'
 
     @classmethod
-    def reject_msgs(cls, native_tar, native_tar_gz, debian_tar, debian_diff, orig_tar, orig_tar_gz, more_orig_tar):
-        if not (native_tar_gz or (orig_tar_gz and debian_diff)):
+    def reject_msgs(cls, has):
+        if not (has['native_tar_gz'] or (has['orig_tar_gz'] and has['debian_diff'])):
             yield "no .tar.gz or .orig.tar.gz+.diff.gz in 'Files' field."
-        if (orig_tar_gz != orig_tar) or \
-           (native_tar_gz != native_tar) or \
-           debian_tar or more_orig_tar:
+        if (has['orig_tar_gz'] != has['orig_tar']) or \
+           (has['native_tar_gz'] != has['native_tar']) or \
+           has['debian_tar'] or has['more_orig_tar']:
             yield "contains source files not allowed in format %s" % cls.name
 
 class FormatThree(object):
@@ -34,10 +34,10 @@ class FormatThree(object):
     format = r'3\.\d+ \(native\)'
 
     @classmethod
-    def reject_msgs(cls, native_tar, native_tar_gz, debian_tar, debian_diff, orig_tar, orig_tar_gz, more_orig_tar):
-        if not native_tar:
+    def reject_msgs(cls, has):
+        if not has['native_tar']:
             yield "lack of required files for format %s" % cls.name
-        if orig_tar or debian_diff or debian_tar or more_orig_tar:
+        if has['orig_tar'] or has['debian_diff'] or has['debian_tar'] or has['more_orig_tar']:
             yield "contains source files not allowed in format %s" % cls.name
 
 class FormatThreeQuilt(object):
@@ -47,8 +47,8 @@ class FormatThreeQuilt(object):
     format = r'3\.\d+ \(quilt\)'
 
     @classmethod
-    def reject_msgs(cls, native_tar, native_tar_gz, debian_tar, debian_diff, orig_tar, orig_tar_gz, more_orig_tar):
-        if not(orig_tar and debian_tar):
+    def reject_msgs(cls, has):
+        if not (has['orig_tar'] and has['debian_tar']):
             yield "lack of required files for format %s" % cls.name
-        if debian_diff or native_tar:
+        if has['debian_diff'] or has['native_tar']:
             yield "contains source files not allowed in format %s" % cls.name
index 1c7aa802692cba07fdf2ca2b9908b02457044b65..c4f93fe5f651cc2b8bc5c6b82861a548f554aebc 100755 (executable)
@@ -49,6 +49,7 @@ from regexes import re_html_escaping, html_escaping, re_single_line_field, \
                     re_re_mark, re_whitespace_comment, re_issource
 
 from srcformats import srcformats
+from collections import defaultdict
 
 ################################################################################
 
@@ -362,13 +363,8 @@ def check_dsc_files(dsc_filename, dsc=None, dsc_files=None):
 
     # Ensure .dsc lists proper set of source files according to the format
     # announced
-    has_native_tar = 0
-    has_native_tar_gz = 0
-    has_orig_tar = 0
-    has_orig_tar_gz = 0
-    has_more_orig_tar = 0
-    has_debian_tar = 0
-    has_debian_diff = 0
+    has = defaultdict(lambda: 0)
+
     for f in dsc_files.keys():
         m = re_issource.match(f)
         if not m:
@@ -377,42 +373,35 @@ def check_dsc_files(dsc_filename, dsc=None, dsc_files=None):
             continue
         ftype = m.group(3)
         if ftype == "orig.tar.gz":
-            has_orig_tar_gz += 1
-            has_orig_tar += 1
+            has['orig_tar_gz'] += 1
+            has['orig_tar'] += 1
         elif ftype == "diff.gz":
-            has_debian_diff += 1
+            has['debian_diff'] += 1
         elif ftype == "tar.gz":
-            has_native_tar_gz += 1
-            has_native_tar += 1
+            has['native_tar_gz'] += 1
+            has['native_tar'] += 1
         elif re.match(r"debian\.tar\.(gz|bz2|lzma)", ftype):
-            has_debian_tar += 1
+            has['debian_tar'] += 1
         elif re.match(r"orig\.tar\.(gz|bz2|lzma)", ftype):
-            has_orig_tar += 1
+            has['orig_tar'] += 1
         elif re.match(r"tar\.(gz|bz2|lzma)", ftype):
-            has_native_tar += 1
+            has['native_tar'] += 1
         elif re.match(r"orig-.+\.tar\.(gz|bz2|lzma)", ftype):
-            has_more_orig_tar += 1
+            has['more_orig_tar'] += 1
         else:
             reject("%s: unexpected source file '%s'" % (dsc_filename, f))
-    if has_orig_tar > 1:
+    if has['orig_tar'] > 1:
         rejmsg.append("%s: lists multiple .orig tarballs." % (dsc_filename))
-    if has_native_tar > 1:
+    if has['native_tar'] > 1:
         rejmsg.append("%s: lists multiple native tarballs." % (dsc_filename))
-    if has_debian_tar > 1 or has_debian_diff > 1:
+    if has['debian_tar'] > 1 or has['debian_diff'] > 1:
         rejmsg.append("%s: lists multiple debian diff/tarballs." % (dsc_filename))
 
     for format in srcformats:
         if format.re_format.match(dsc['format']):
-            msgs = format.reject_msgs(
-                has_native_tar,
-                has_native_tar_gz,
-                has_debian_tar,
-                has_debian_diff,
-                has_orig_tar,
-                has_orig_tar_gz,
-                has_more_orig_tar
-            )
-            rejmsg.extend(['%s: %s' % (dsc_filename, x) for x in msgs])
+            rejmsg.extend([
+                '%s: %s' % (dsc_filename, x) for x in format.reject_msgs(has)
+            ])
             break
 
     return rejmsg