[csw-devel] SF.net SVN: gar:[14054] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sat Apr 2 14:05:31 CEST 2011


Revision: 14054
          http://gar.svn.sourceforge.net/gar/?rev=14054&view=rev
Author:   wahwah
Date:     2011-04-02 12:05:31 +0000 (Sat, 02 Apr 2011)

Log Message:
-----------
checkpkg: FileSetChecker in a separate file

This class will be reused in csw-upload-pkg, so it needs to live in
a separate file.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/submit_to_newpkgs.py
    csw/mgar/gar/v2/lib/python/submit_to_newpkgs_test.py

Added Paths:
-----------
    csw/mgar/gar/v2/lib/python/file_set_checker.py
    csw/mgar/gar/v2/lib/python/file_set_checker_test.py

Added: csw/mgar/gar/v2/lib/python/file_set_checker.py
===================================================================
--- csw/mgar/gar/v2/lib/python/file_set_checker.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/file_set_checker.py	2011-04-02 12:05:31 UTC (rev 14054)
@@ -0,0 +1,92 @@
+#!/opt/csw/bin/python2.6
+# coding=utf-8
+# vim:set sw=2 ts=2 sts=2 expandtab:
+
+import tag
+import os
+import opencsw
+import common_constants
+
+class FileSetChecker(object):
+  """Checks a file name set.
+
+  Doesn't check anything about package contents.  The purpose of this
+  class is to identify problems with the file set itself, e.g. an
+  uncommitted package or a missing i386 package.
+  """
+
+  def _CheckUncommitted(self, files_with_metadata):
+    tags = []
+    expected_vendor_tag = "CSW"
+    for filename, parsed_filename in files_with_metadata:
+      if parsed_filename["vendortag"] != expected_vendor_tag:
+        tags.append(tag.CheckpkgTag(
+          None,
+          "bad-vendor-tag",
+          "%s expected=%s actual=%s"
+          % (parsed_filename["catalogname"],
+             expected_vendor_tag,
+             parsed_filename["vendortag"])))
+    return tags
+
+  def _CheckMissingArchs(self, files_with_metadata):
+    tags = []
+    catalognames_by_arch = {}
+    # We check all the OS releases that are included in the file set.
+    # We won't report a missing i386-SunOS5.8 package if there was no
+    # SunOS5.8 package in the set.
+    osrels = set(x[1]["osrel"] for x in files_with_metadata)
+    # Prepopulate sets, so that we have one set per each arch-osrel pair
+    # that is applicable to this set of files.
+    for arch in common_constants.PHYSICAL_ARCHITECTURES:
+      for osrel in osrels:
+        key = arch, osrel
+        catalognames_by_arch[key] = set()
+    # Assign files from the set to appropriate set.
+    for file_path, file_metadata in files_with_metadata:
+      catalogname = file_metadata["catalogname"]
+      if file_metadata["arch"] == "all":
+        archs = common_constants.PHYSICAL_ARCHITECTURES
+      else:
+        archs = [file_metadata["arch"]]
+      osrel = file_metadata["osrel"]
+      for arch in archs:
+        key = arch, osrel
+        catalognames_by_arch[key].add(catalogname)
+    missing = {}
+    for key1, set1 in catalognames_by_arch.iteritems():
+      for catalogname in set1:
+        for key2, set2 in catalognames_by_arch.iteritems():
+          if catalogname not in set2:
+            arch, osrel = key2
+            missing_key = arch, osrel, catalogname
+            missing.setdefault(missing_key, set()).add(
+                "Because %s-%s-%s exists" % (catalogname, key1[0], key1[1]))
+    for arch, osrel, catalogname in missing:
+      error_tag_name = "%s-%s-missing" % (arch, osrel)
+      tags.append(tag.CheckpkgTag(None, error_tag_name, catalogname))
+    return tags
+
+  def CheckFiles(self, file_list):
+    """Checks a set of files. Returns error tags."""
+    files_with_metadata = []
+    for file_path in file_list:
+      pkg_path, basename = os.path.split(file_path)
+      parsed = opencsw.ParsePackageFileName(basename)
+      catalogname = parsed["catalogname"]
+      files_with_metadata.append((basename, parsed))
+      if parsed["arch"] == "all":
+        archs = common_constants.PHYSICAL_ARCHITECTURES
+      else:
+        archs = [parsed["arch"]]
+      for arch in archs:
+        for osrel in common_constants.OS_RELS:
+          key = arch, osrel
+          # catalognames_by_arch.setdefault(key, set()).add(catalogname)
+    tags = []
+    tags.extend(self._CheckMissingArchs(files_with_metadata))
+    tags.extend(self._CheckUncommitted(files_with_metadata))
+    return tags
+
+
+

Copied: csw/mgar/gar/v2/lib/python/file_set_checker_test.py (from rev 14053, csw/mgar/gar/v2/lib/python/submit_to_newpkgs_test.py)
===================================================================
--- csw/mgar/gar/v2/lib/python/file_set_checker_test.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/file_set_checker_test.py	2011-04-02 12:05:31 UTC (rev 14054)
@@ -0,0 +1,58 @@
+#!/usr/bin/env python2.6
+# coding=utf-8
+# vim:set sw=2 ts=2 sts=2 expandtab:
+
+# Try to use unittest2, fall back to unittest
+try:
+  import unittest2 as unittest
+except ImportError:
+  import unittest
+
+import file_set_checker
+import tag
+
+SAMPLE_FILES = [
+  # This file intentionally missing.
+  # '/home/experimental/maciej/libnspr4-4.8.6,REV=2010.10.16-SunOS5.9-i386-CSW.pkg.gz',
+  '/home/experimental/maciej/libnspr4-4.8.6,REV=2010.10.16-SunOS5.9-sparc-CSW.pkg.gz',
+  '/home/experimental/maciej/libnspr4_devel-4.8.6,REV=2010.10.16-SunOS5.9-i386-CSW.pkg.gz',
+  '/home/experimental/maciej/libnspr4_devel-4.8.6,REV=2010.10.16-SunOS5.9-sparc-CSW.pkg.gz',
+  '/home/experimental/maciej/nspr-4.8.6,REV=2010.10.16-SunOS5.9-all-CSW.pkg.gz',
+  '/home/experimental/maciej/nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-i386-CSW.pkg.gz',
+  '/home/experimental/maciej/nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-sparc-CSW.pkg.gz',
+]
+
+class FileSetCheckerUnitTest(unittest.TestCase):
+
+  def testMissingArchitecture(self):
+    fc = file_set_checker.FileSetChecker()
+    expected = [tag.CheckpkgTag(None, 'i386-SunOS5.9-missing', 'libnspr4')]
+    self.assertEqual(expected, fc.CheckFiles(SAMPLE_FILES))
+
+  def testMissingArchitectureWithOsrel(self):
+    files = [
+        'foo-1.0,REV=2011.03.30-SunOS5.9-i386-CSW.pkg.gz',
+        'foo-1.0,REV=2011.03.30-SunOS5.9-sparc-CSW.pkg.gz',
+        'foo-1.0,REV=2011.03.30-SunOS5.10-i386-CSW.pkg.gz',
+        # Intentionally missing
+        # 'foo-1.0,REV=2011.03.30-SunOS5.10-sparc-CSW.pkg.gz',
+    ]
+    fc = file_set_checker.FileSetChecker()
+    expected = [tag.CheckpkgTag(None, 'sparc-SunOS5.10-missing', 'foo')]
+    self.assertEqual(expected, fc.CheckFiles(files))
+
+  def testUncommitted(self):
+    fc = file_set_checker.FileSetChecker()
+    expected = [
+        tag.CheckpkgTag(None, 'bad-vendor-tag', 'nspr_devel expected=CSW actual=UNCOMMITTED'),
+        tag.CheckpkgTag(None, 'bad-vendor-tag', 'nspr_devel expected=CSW actual=UNCOMMITTED'),
+    ]
+    files = ['/home/experimental/maciej/'
+             'nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-sparc-UNCOMMITTED.pkg.gz',
+             '/home/experimental/maciej/'
+             'nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-i386-UNCOMMITTED.pkg.gz']
+    self.assertEqual(expected, fc.CheckFiles(files))
+
+
+if __name__ == '__main__':
+	unittest.main()

Modified: csw/mgar/gar/v2/lib/python/submit_to_newpkgs.py
===================================================================
--- csw/mgar/gar/v2/lib/python/submit_to_newpkgs.py	2011-04-02 12:04:48 UTC (rev 14053)
+++ csw/mgar/gar/v2/lib/python/submit_to_newpkgs.py	2011-04-02 12:05:31 UTC (rev 14054)
@@ -35,6 +35,7 @@
 import opencsw
 import tag
 import common_constants
+import file_set_checker
 
 
 CONFIG_INFO = """Create a file in ~/.releases.ini with the following content:
@@ -103,82 +104,6 @@
     raise PackageSubmissionError(msg)
 
 
-class FileSetChecker(object):
-
-  def _CheckUncommitted(self, files_with_metadata):
-    tags = []
-    expected_vendor_tag = "CSW"
-    for filename, parsed_filename in files_with_metadata:
-      if parsed_filename["vendortag"] != expected_vendor_tag:
-        tags.append(tag.CheckpkgTag(
-          None,
-          "bad-vendor-tag",
-          "%s expected=%s actual=%s"
-          % (parsed_filename["catalogname"],
-             expected_vendor_tag,
-             parsed_filename["vendortag"])))
-    return tags
-
-  def _CheckMissingArchs(self, files_with_metadata):
-    tags = []
-    catalognames_by_arch = {}
-    # We check all the OS releases that are included in the file set.
-    # We won't report a missing i386-SunOS5.8 package if there was no
-    # SunOS5.8 package in the set.
-    osrels = set(x[1]["osrel"] for x in files_with_metadata)
-    # Prepopulate sets, so that we have one set per each arch-osrel pair
-    # that is applicable to this set of files.
-    for arch in common_constants.PHYSICAL_ARCHITECTURES:
-      for osrel in osrels:
-      	key = arch, osrel
-      	catalognames_by_arch[key] = set()
-    # Assign files from the set to appropriate set.
-    for file_path, file_metadata in files_with_metadata:
-      catalogname = file_metadata["catalogname"]
-      if file_metadata["arch"] == "all":
-        archs = common_constants.PHYSICAL_ARCHITECTURES
-      else:
-        archs = [file_metadata["arch"]]
-      osrel = file_metadata["osrel"]
-      for arch in archs:
-        key = arch, osrel
-        catalognames_by_arch[key].add(catalogname)
-    missing = {}
-    for key1, set1 in catalognames_by_arch.iteritems():
-      for catalogname in set1:
-        for key2, set2 in catalognames_by_arch.iteritems():
-          if catalogname not in set2:
-            arch, osrel = key2
-            missing_key = arch, osrel, catalogname
-            missing.setdefault(missing_key, set()).add(
-                "Because %s-%s-%s exists" % (catalogname, key1[0], key1[1]))
-    for arch, osrel, catalogname in missing:
-      error_tag_name = "%s-%s-missing" % (arch, osrel)
-      tags.append(tag.CheckpkgTag(None, error_tag_name, catalogname))
-    return tags
-
-  def CheckFiles(self, file_list):
-    """Checks a set of files. Returns error tags."""
-    files_with_metadata = []
-    for file_path in file_list:
-      pkg_path, basename = os.path.split(file_path)
-      parsed = opencsw.ParsePackageFileName(basename)
-      catalogname = parsed["catalogname"]
-      files_with_metadata.append((basename, parsed))
-      if parsed["arch"] == "all":
-        archs = common_constants.PHYSICAL_ARCHITECTURES
-      else:
-        archs = [parsed["arch"]]
-      for arch in archs:
-        for osrel in common_constants.OS_RELS:
-          key = arch, osrel
-          # catalognames_by_arch.setdefault(key, set()).add(catalogname)
-    tags = []
-    tags.extend(self._CheckMissingArchs(files_with_metadata))
-    tags.extend(self._CheckUncommitted(files_with_metadata))
-    return tags
-
-
 def main():
   try:
     config = ConfigParser.SafeConfigParser()
@@ -275,7 +200,7 @@
     remote_package_files.append(dst_arg)
     package_base_file_name = os.path.split(p)[1]
     remote_package_references.append(dst_arg + "/" + package_base_file_name)
-  fc = FileSetChecker()
+  fc = file_set_checker.FileSetChecker()
   error_tags = fc.CheckFiles(files_to_rsync)
   if error_tags:
     for error_tag in error_tags:

Modified: csw/mgar/gar/v2/lib/python/submit_to_newpkgs_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/submit_to_newpkgs_test.py	2011-04-02 12:04:48 UTC (rev 14053)
+++ csw/mgar/gar/v2/lib/python/submit_to_newpkgs_test.py	2011-04-02 12:05:31 UTC (rev 14054)
@@ -7,50 +7,10 @@
   import unittest
 
 import submit_to_newpkgs as stn
-import tag
 
-SAMPLE_FILES = [
-  # This file intentionally missing.
-  # '/home/experimental/maciej/libnspr4-4.8.6,REV=2010.10.16-SunOS5.9-i386-CSW.pkg.gz',
-  '/home/experimental/maciej/libnspr4-4.8.6,REV=2010.10.16-SunOS5.9-sparc-CSW.pkg.gz',
-  '/home/experimental/maciej/libnspr4_devel-4.8.6,REV=2010.10.16-SunOS5.9-i386-CSW.pkg.gz',
-  '/home/experimental/maciej/libnspr4_devel-4.8.6,REV=2010.10.16-SunOS5.9-sparc-CSW.pkg.gz',
-  '/home/experimental/maciej/nspr-4.8.6,REV=2010.10.16-SunOS5.9-all-CSW.pkg.gz',
-  '/home/experimental/maciej/nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-i386-CSW.pkg.gz',
-  '/home/experimental/maciej/nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-sparc-CSW.pkg.gz',
-]
+# FileSetChecker class and unit tests have been moved to a separate
+# file.
 
-class FileSetCheckerUnitTest(unittest.TestCase):
 
-  def testMissingArchitecture(self):
-    fc = stn.FileSetChecker()
-    expected = [tag.CheckpkgTag(None, 'i386-SunOS5.9-missing', 'libnspr4')]
-    self.assertEqual(expected, fc.CheckFiles(SAMPLE_FILES))
-
-  def testMissingArchitectureWithOsrel(self):
-    files = [
-        'foo-1.0,REV=2011.03.30-SunOS5.9-i386-CSW.pkg.gz',
-        'foo-1.0,REV=2011.03.30-SunOS5.9-sparc-CSW.pkg.gz',
-        'foo-1.0,REV=2011.03.30-SunOS5.10-i386-CSW.pkg.gz',
-        # Intentionally missing
-        # 'foo-1.0,REV=2011.03.30-SunOS5.10-sparc-CSW.pkg.gz',
-    ]
-    fc = stn.FileSetChecker()
-    expected = [tag.CheckpkgTag(None, 'sparc-SunOS5.10-missing', 'foo')]
-    self.assertEqual(expected, fc.CheckFiles(files))
-
-  def testUncommitted(self):
-    fc = stn.FileSetChecker()
-    expected = [
-        tag.CheckpkgTag(None, 'bad-vendor-tag', 'nspr_devel expected=CSW actual=UNCOMMITTED'),
-        tag.CheckpkgTag(None, 'bad-vendor-tag', 'nspr_devel expected=CSW actual=UNCOMMITTED'),
-    ]
-    files = ['/home/experimental/maciej/'
-             'nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-sparc-UNCOMMITTED.pkg.gz',
-             '/home/experimental/maciej/'
-             'nspr_devel-4.8.6,REV=2010.10.16-SunOS5.9-i386-UNCOMMITTED.pkg.gz']
-    self.assertEqual(expected, fc.CheckFiles(files))
-
-
 if __name__ == '__main__':
 	unittest.main()


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list