[csw-devel] SF.net SVN: gar:[10433] csw/mgar/gar/v2

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Jul 5 12:13:27 CEST 2010


Revision: 10433
          http://gar.svn.sourceforge.net/gar/?rev=10433&view=rev
Author:   wahwah
Date:     2010-07-05 10:13:27 +0000 (Mon, 05 Jul 2010)

Log Message:
-----------
mGAR v2: Refactoring, removing circular dependencies between opencsw.py and checkpkg.py

Modified Paths:
--------------
    csw/mgar/gar/v2/bin/analyze_module_results.py
    csw/mgar/gar/v2/lib/python/checkpkg.py
    csw/mgar/gar/v2/lib/python/checkpkg_test.py
    csw/mgar/gar/v2/lib/python/opencsw.py
    csw/mgar/gar/v2/lib/python/package_checks.py
    csw/mgar/gar/v2/lib/python/package_checks_test.py
    csw/mgar/gar/v2/tests/run_tests.py

Added Paths:
-----------
    csw/mgar/gar/v2/lib/python/configuration.py
    csw/mgar/gar/v2/lib/python/overrides.py
    csw/mgar/gar/v2/lib/python/overrides_test.py
    csw/mgar/gar/v2/lib/python/tag.py
    csw/mgar/gar/v2/lib/python/tag_test.py

Modified: csw/mgar/gar/v2/bin/analyze_module_results.py
===================================================================
--- csw/mgar/gar/v2/bin/analyze_module_results.py	2010-07-05 09:29:13 UTC (rev 10432)
+++ csw/mgar/gar/v2/bin/analyze_module_results.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -13,6 +13,7 @@
 sys.path.append(os.path.join(*path_list))
 import checkpkg
 import opencsw
+import overrides
 
 def main():
   parser = optparse.OptionParser()
@@ -29,15 +30,15 @@
   for file_name in files:
     full_path = os.path.join(options.extractdir, file_name)
     error_tags.extend(checkpkg.ErrorTagsFromFile(full_path))
-  overrides = reduce(operator.add, overrides_list)
+  override_list = reduce(operator.add, overrides_list)
   (tags_after_overrides,
-   unapplied_overrides) = checkpkg.ApplyOverrides(error_tags, overrides)
+   unapplied_overrides) = overrides.ApplyOverrides(error_tags, override_list)
   exit_code = bool(tags_after_overrides)
   if tags_after_overrides:
     print "If any of the reported errors were false positives, you can"
     print "override them pasting the lines below to the GAR recipe."
-    for tag in tags_after_overrides:
-      print tag.ToGarSyntax()
+    for checkpkg_tag in tags_after_overrides:
+      print checkpkg_tag.ToGarSyntax()
     print "Please note that checkpkg isn't suggesting you should "
     print "use these overrides.  It only informs what the overrides could "
     print "look like.  You need to understand what are the reported issues about"

Modified: csw/mgar/gar/v2/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg.py	2010-07-05 09:29:13 UTC (rev 10432)
+++ csw/mgar/gar/v2/lib/python/checkpkg.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -26,12 +26,13 @@
 import opencsw
 import package_checks
 import models as m
+import configuration as c
+import tag
 
 DEBUG_BREAK_PKGMAP_AFTER = False
 DB_SCHEMA_VERSION = 3L
 PACKAGE_STATS_VERSION = 6L
 SYSTEM_PKGMAP = "/var/sadm/install/contents"
-WS_RE = re.compile(r"\s+")
 NEEDED_SONAMES = "needed sonames"
 RUNPATH = "runpath"
 SONAME = "soname"
@@ -347,7 +348,7 @@
         continue
       if line.startswith("#"):
         continue
-      fields = re.split(WS_RE, line)
+      fields = re.split(c.WS_RE, line)
       pkgmap_entry_path = fields[0].split("=")[0]
       pkgmap_entry_dir, pkgmap_entry_base_name = os.path.split(pkgmap_entry_path)
       # The following SQLObject-driven inserts are 60 times slower than the raw
@@ -373,7 +374,7 @@
     logging.info("All lines of %s were processed.", pkgmap_path)
 
   def _ParsePkginfoLine(self, line):
-    fields = re.split(WS_RE, line)
+    fields = re.split(c.WS_RE, line)
     pkgname = fields[1]
     pkg_desc = u" ".join(fields[2:])
     return pkgname, pkg_desc
@@ -451,7 +452,7 @@
   def _InferPackagesFromPkgmapLine(self, line):
     """A stub of a function, to be enhanced."""
     line = line.strip()
-    parts = re.split(WS_RE, line)
+    parts = re.split(c.WS_RE, line)
     return [parts[-1]]
 
   def GetPathsAndPkgnamesByBasename(self, filename):
@@ -625,7 +626,7 @@
   runpath = []
   rpath = []
   for line in dump_output.splitlines():
-    fields = re.split(WS_RE, line)
+    fields = re.split(c.WS_RE, line)
     # TODO: Make it a unit test
     # logging.debug("%s says: %s", DUMP_BIN, fields)
     if len(fields) < 3:
@@ -648,38 +649,6 @@
   return binary_data
 
 
-class CheckpkgTag(object):
-  """Represents a tag to be written to the checkpkg tag file."""
-
-  def __init__(self, pkgname, tag_name, tag_info=None, severity=None, msg=None):
-    self.pkgname = pkgname
-    self.tag_name = tag_name
-    self.tag_info = tag_info
-    self.severity = severity
-    self.msg = msg
-
-  def __repr__(self):
-    return (u"CheckpkgTag(%s, %s, %s)"
-            % (repr(self.pkgname),
-               repr(self.tag_name),
-               repr(self.tag_info)))
-
-  def ToGarSyntax(self):
-    """Presents the error tag using GAR syntax."""
-    msg_lines = []
-    if self.msg:
-      msg_lines.extend(textwrap(self.msg, 70,
-                                initial_indent="# ",
-                                subsequent_indent="# "))
-    if self.tag_info:
-      tag_postfix = "|%s" % self.tag_info.replace(" ", "|")
-    else:
-      tag_postfix = ""
-    msg_lines.append(u"CHECKPKG_OVERRIDES_%s += %s%s"
-                     % (self.pkgname, self.tag_name, tag_postfix))
-    return "\n".join(msg_lines)
-
-
 class CheckpkgManagerBase(object):
   """Common functions between the older and newer calling functions."""
 
@@ -816,7 +785,7 @@
 class IndividualCheckInterface(CheckInterfaceBase):
   """To be passed to the checking functions.
 
-  Wraps the creation of CheckpkgTag objects.
+  Wraps the creation of tag.CheckpkgTag objects.
   """
 
   def __init__(self, pkgname, system_pkgmap=None):
@@ -825,8 +794,8 @@
     self.errors = []
 
   def ReportError(self, tag_name, tag_info=None, msg=None):
-    tag = CheckpkgTag(self.pkgname, tag_name, tag_info, msg=msg)
-    self.errors.append(tag)
+    checkpkg_tag = tag.CheckpkgTag(self.pkgname, tag_name, tag_info, msg=msg)
+    self.errors.append(checkpkg_tag)
 
 
 class SetCheckInterface(CheckInterfaceBase):
@@ -837,8 +806,8 @@
     self.errors = []
 
   def ReportError(self, pkgname, tag_name, tag_info=None, msg=None):
-    tag = CheckpkgTag(pkgname, tag_name, tag_info, msg=msg)
-    self.errors.append(tag)
+    checkpkg_tag = tag.CheckpkgTag(pkgname, tag_name, tag_info, msg=msg)
+    self.errors.append(checkpkg_tag)
 
 
 class CheckpkgMessenger(object):
@@ -916,95 +885,6 @@
     return super(CheckpkgManager2, self).Run()
 
 
-def ParseTagLine(line):
-  """Parses a line from the tag.${module} file.
-
-  Returns a triplet of pkgname, tagname, tag_info.
-  """
-  level_1 = line.strip().split(":")
-  if len(level_1) > 1:
-    data_1 = ":".join(level_1[1:])
-    pkgname = level_1[0]
-  else:
-    data_1 = level_1[0]
-    pkgname = None
-  level_2 = re.split(WS_RE, data_1.strip())
-  tag_name = level_2[0]
-  if len(level_2) > 1:
-    tag_info = " ".join(level_2[1:])
-  else:
-    tag_info = None
-  return (pkgname, tag_name, tag_info)
-
-
-class Override(object):
-  """Represents an override of a certain checkpkg tag.
-
-  It's similar to checkpkg.CheckpkgTag, but serves a different purpose.
-  """
-
-  def __init__(self, pkgname, tag_name, tag_info):
-    self.pkgname = pkgname
-    self.tag_name = tag_name
-    self.tag_info = tag_info
-
-  def __repr__(self):
-    return (u"Override(%s, %s, %s)"
-            % (repr(self.pkgname), repr(self.tag_name), repr(self.tag_info)))
-
-  def DoesApply(self, tag):
-    """Figures out if this override applies to the given tag."""
-    basket_a = {}
-    basket_b = {}
-    if self.pkgname:
-      basket_a["pkgname"] = self.pkgname
-      basket_b["pkgname"] = tag.pkgname
-    if self.tag_info:
-      basket_a["tag_info"] = self.tag_info
-      basket_b["tag_info"] = tag.tag_info
-    basket_a["tag_name"] = self.tag_name
-    basket_b["tag_name"] = tag.tag_name
-    return basket_a == basket_b
-
-
-def ParseOverrideLine(line):
-  level_1 = line.split(":")
-  if len(level_1) > 1:
-    pkgname = level_1[0]
-    data_1 = ":".join(level_1[1:])
-  else:
-    pkgname = None
-    data_1 = level_1[0]
-  level_2 = re.split(WS_RE, data_1.strip())
-  if len(level_2) > 1:
-    tag_name = level_2[0]
-    tag_info = " ".join(level_2[1:])
-  else:
-    tag_name = level_2[0]
-    tag_info = None
-  return Override(pkgname, tag_name, tag_info)
-
-
-def ApplyOverrides(error_tags, overrides):
-  """Filters out all the error tags that overrides apply to.
-
-  O(N * M), but N and M are always small.
-  """
-  tags_after_overrides = []
-  applied_overrides = set([])
-  provided_overrides = set(copy.copy(overrides))
-  for tag in error_tags:
-    override_applies = False
-    for override in overrides:
-      if override.DoesApply(tag):
-        override_applies = True
-        applied_overrides.add(override)
-    if not override_applies:
-      tags_after_overrides.append(tag)
-  unapplied_overrides = provided_overrides.difference(applied_overrides)
-  return tags_after_overrides, unapplied_overrides
-
-
 def GetIsalist():
   args = ["isalist"]
   isalist_proc = subprocess.Popen(args, stdout=subprocess.PIPE)
@@ -1417,6 +1297,6 @@
   for line in fd:
     if line.startswith("#"):
       continue
-    pkgname, tag_name, tag_info = ParseTagLine(line)
-    error_tags.append(CheckpkgTag(pkgname, tag_name, tag_info))
+    pkgname, tag_name, tag_info = tag.ParseTagLine(line)
+    error_tags.append(tag.CheckpkgTag(pkgname, tag_name, tag_info))
   return error_tags

Modified: csw/mgar/gar/v2/lib/python/checkpkg_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_test.py	2010-07-05 09:29:13 UTC (rev 10432)
+++ csw/mgar/gar/v2/lib/python/checkpkg_test.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -6,7 +6,7 @@
 import mox
 import difflib
 import checkpkg
-import opencsw
+import tag
 import testdata.dump_output_1 as dump_1
 import testdata.dump_output_2 as dump_2
 import testdata.dump_output_3 as dump_3
@@ -178,162 +178,6 @@
         checkpkg.ParseDumpOutput(dump_3.DATA_DUMP_OUTPUT))
 
 
-class CheckpkgTagsUnitTest(unittest.TestCase):
-
-  def test_1(self):
-    m = checkpkg.CheckpkgManager2("testname", "/tmp", ["CSWfoo"])
-    tags = {
-        "CSWfoo": [
-          checkpkg.CheckpkgTag("CSWfoo", "foo-tag", "foo-info"),
-        ],
-    }
-    screen_report, tags_report = m.FormatReports(tags, [], [])
-    expected = u'# Tags reported by testname module\nCSWfoo: foo-tag foo-info\n'
-    self.assertEqual(expected, tags_report)
-
-  def test_2(self):
-    m = checkpkg.CheckpkgManager2("testname", "/tmp", ["CSWfoo"])
-    tags = {
-        "CSWfoo": [
-          checkpkg.CheckpkgTag("CSWfoo", "foo-tag", "foo-info"),
-          checkpkg.CheckpkgTag("CSWfoo", "bar-tag", "bar-info"),
-          checkpkg.CheckpkgTag("CSWfoo", "baz-tag"),
-        ],
-    }
-    screen_report, tags_report = m.FormatReports(tags, [], [])
-    expected = (u'# Tags reported by testname module\n'
-                u'CSWfoo: foo-tag foo-info\n'
-                u'CSWfoo: bar-tag bar-info\n'
-                u'CSWfoo: baz-tag\n')
-    self.assertEqual(expected, tags_report)
-
-  def testParseTagLine1(self):
-    line = "foo-tag"
-    self.assertEquals((None, "foo-tag", None), checkpkg.ParseTagLine(line))
-
-  def testParseTagLine2(self):
-    line = "CSWfoo: foo-tag"
-    self.assertEquals(("CSWfoo", "foo-tag", None), checkpkg.ParseTagLine(line))
-
-  def testParseTagLine3(self):
-    line = "CSWfoo: foo-tag foo-info"
-    self.assertEquals(("CSWfoo", "foo-tag", "foo-info"),
-                      checkpkg.ParseTagLine(line))
-
-  def testParseTagLine4(self):
-    line = "CSWfoo: foo-tag foo-info1 foo-info2"
-    self.assertEquals(("CSWfoo", "foo-tag", "foo-info1 foo-info2"),
-                      checkpkg.ParseTagLine(line))
-
-  def testParseTagLine_WithUrl(self):
-    line = "CSWfoo: tag-with-an-url http://www.example.com/"
-    self.assertEquals(("CSWfoo", "tag-with-an-url", "http://www.example.com/"),
-                      checkpkg.ParseTagLine(line))
-
-
-class ParseOverrideLineUnitTest(unittest.TestCase):
-  
-  def setUp(self):
-    line1 = "CSWfoo: foo-override"
-    line2 = "CSWfoo: foo-override foo-info"
-    line3 = "CSWfoo: foo-override foo-info-1 foo-info-2"
-    line4 = ("CSWpmcommonsense: "
-             "pkginfo-description-not-starting-with-uppercase "
-             "common-sense: Some sane defaults for Perl programs")
-    self.o1 = checkpkg.ParseOverrideLine(line1)
-    self.o2 = checkpkg.ParseOverrideLine(line2)
-    self.o3 = checkpkg.ParseOverrideLine(line3)
-    self.o4 = checkpkg.ParseOverrideLine(line4)
-
-  def test_ParseOverridesLine1(self):
-    self.assertEqual("CSWfoo", self.o1.pkgname)
-
-  def test_ParseOverridesLine2(self):
-    self.assertEqual("foo-override", self.o1.tag_name)
-
-  def test_ParseOverridesLine3(self):
-    self.assertEqual(None, self.o1.tag_info)
-
-  def test_ParseOverridesLine4(self):
-    self.assertEqual("foo-info", self.o2.tag_info)
-
-  def test_ParseOverridesLine5(self):
-    self.assertEqual("CSWfoo", self.o3.pkgname)
-
-  def test_ParseOverridesLine6(self):
-    self.assertEqual("foo-override", self.o3.tag_name)
-
-  def test_ParseOverridesLine7(self):
-    self.assertEqual("foo-info-1 foo-info-2", self.o3.tag_info)
-
-  def test_ParseOverridesLine_4_1(self):
-    self.assertEqual("CSWpmcommonsense", self.o4.pkgname)
-
-  def test_ParseOverridesLine_4_2(self):
-    self.assertEqual(
-        "pkginfo-description-not-starting-with-uppercase",
-        self.o4.tag_name)
-
-  def test_ParseOverridesLine_4_3(self):
-    self.assertEqual(
-        "common-sense: Some sane defaults for Perl programs",
-        self.o4.tag_info)
-
-
-class ApplyOverridesUnitTest(unittest.TestCase):
-
-  # This would be better, more terse. But requires metaclasses.
-  DATA_1 = (
-      (None, 'tag1', 'info1', None, 'tag1', 'info1', None),
-  )
-
-  def test_1a(self):
-    """One tag, no overrides."""
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag")]
-    overrides = []
-    self.assertEqual((tags, set([])), checkpkg.ApplyOverrides(tags, overrides))
-
-  def test_1b(self):
-    """One override, matching by tag name only."""
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag")]
-    overrides = [checkpkg.Override(None, "foo-tag", None)]
-    self.assertEqual(([], set([])), checkpkg.ApplyOverrides(tags, overrides))
-
-  def test_1c(self):
-    """One override, matching by tag name only, no pkgname."""
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag")]
-    overrides = [checkpkg.Override(None, "foo-tag", None)]
-    self.assertEqual(([], set([])), checkpkg.ApplyOverrides(tags, overrides))
-
-  def test_2(self):
-    """One override, matching by tag name and tag info, no pkgname."""
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag")]
-    overrides = [checkpkg.Override(None, "foo-tag", None)]
-    self.assertEqual(([], set([])), checkpkg.ApplyOverrides(tags, overrides))
-
-  def test_3(self):
-    """One override, matching by tag name, mismatching tag info, no pkgname."""
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
-    overrides = [checkpkg.Override(None, "foo-tag", "tag-info-2")]
-    self.assertEqual((tags, set(overrides)), checkpkg.ApplyOverrides(tags, overrides))
-
-  def test_4(self):
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
-    overrides = [checkpkg.Override(None, "foo-tag", "tag-info-1")]
-    self.assertEqual(([], set([])), checkpkg.ApplyOverrides(tags, overrides))
-
-  def test_5(self):
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
-    overrides = [checkpkg.Override("CSWfoo", "foo-tag", "tag-info-1")]
-    self.assertEqual(([], set([])), checkpkg.ApplyOverrides(tags, overrides))
-
-  def test_6(self):
-    """Pkgname mismatch."""
-    tags = [checkpkg.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
-    overrides = [checkpkg.Override("CSWbar", "foo-tag", "tag-info-1")]
-    self.assertEqual((tags, set(overrides)), checkpkg.ApplyOverrides(tags, overrides))
-
-
 class SystemPkgmapUnitTest(unittest.TestCase):
 
   def testParsePkginfoLine(self):
@@ -484,5 +328,36 @@
     self.assertEqual(expected, re.match(checkpkg.PSTAMP_RE, pstamp).groupdict())
 
 
+class CheckpkgManager2UnitTest(unittest.TestCase):
+
+  def test_1(self):
+    m = checkpkg.CheckpkgManager2("testname", "/tmp", ["CSWfoo"])
+    tags = {
+        "CSWfoo": [
+          tag.CheckpkgTag("CSWfoo", "foo-tag", "foo-info"),
+        ],
+    }
+    screen_report, tags_report = m.FormatReports(tags, [], [])
+    expected = u'# Tags reported by testname module\nCSWfoo: foo-tag foo-info\n'
+    self.assertEqual(expected, tags_report)
+
+  def test_2(self):
+    m = checkpkg.CheckpkgManager2("testname", "/tmp", ["CSWfoo"])
+    tags = {
+        "CSWfoo": [
+          tag.CheckpkgTag("CSWfoo", "foo-tag", "foo-info"),
+          tag.CheckpkgTag("CSWfoo", "bar-tag", "bar-info"),
+          tag.CheckpkgTag("CSWfoo", "baz-tag"),
+        ],
+    }
+    screen_report, tags_report = m.FormatReports(tags, [], [])
+    expected = (u'# Tags reported by testname module\n'
+                u'CSWfoo: foo-tag foo-info\n'
+                u'CSWfoo: bar-tag bar-info\n'
+                u'CSWfoo: baz-tag\n')
+    self.assertEqual(expected, tags_report)
+
+
+
 if __name__ == '__main__':
   unittest.main()

Added: csw/mgar/gar/v2/lib/python/configuration.py
===================================================================
--- csw/mgar/gar/v2/lib/python/configuration.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/configuration.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -0,0 +1,7 @@
+# $Id$
+# coding=utf-8
+
+import re
+
+WS_RE = re.compile(r"\s+")
+


Property changes on: csw/mgar/gar/v2/lib/python/configuration.py
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: csw/mgar/gar/v2/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw.py	2010-07-05 09:29:13 UTC (rev 10432)
+++ csw/mgar/gar/v2/lib/python/opencsw.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -27,7 +27,8 @@
 import subprocess
 import tempfile
 import urllib2
-import checkpkg
+import overrides
+import configuration as c
 from Cheetah import Template
 
 ARCH_SPARC = "sparc"
@@ -44,7 +45,6 @@
 REVISION_ADDED = "revision number added"
 PKG_URL_TMPL = "http://www.opencsw.org/packages/%s"
 CATALOG_URL = "http://mirror.opencsw.org/opencsw/current/i386/5.10/catalog"
-WS_RE = re.compile(r"\s+")
 BIN_MIMETYPES = (
     'application/x-executable',
     'application/x-sharedlib',
@@ -678,7 +678,7 @@
     A bit hacky.  Looks for the first word of the NAME field in the package.
     """
     pkginfo = self.GetParsedPkginfo()
-    words = re.split(WS_RE, pkginfo["NAME"])
+    words = re.split(c.WS_RE, pkginfo["NAME"])
     return words[0]
 
   def GetParsedPkginfo(self):
@@ -785,7 +785,7 @@
     # It needs to be a list because there might be duplicates and it's
     # necessary to carry that information.
     for line in fd:
-      fields = re.split(WS_RE, line)
+      fields = re.split(c.WS_RE, line)
       if fields[0] == "P":
         pkgname = fields[1]
         pkg_desc = " ".join(fields[1:])
@@ -897,15 +897,15 @@
       return None
 
   def _ParseOverridesStream(self, stream):
-    overrides = []
+    override_list = []
     for line in stream:
       if line.startswith("#"):
         continue
-      overrides.append(checkpkg.ParseOverrideLine(line))
-    return overrides
+      override_list.append(overrides.ParseOverrideLine(line))
+    return override_list
 
   def GetOverrides(self):
-    """Returns overrides, a list of checkpkg.Override instances."""
+    """Returns overrides, a list of overrides.Override instances."""
     stream = self._GetOverridesStream()
     if stream:
       return self._ParseOverridesStream(stream)

Added: csw/mgar/gar/v2/lib/python/overrides.py
===================================================================
--- csw/mgar/gar/v2/lib/python/overrides.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/overrides.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -0,0 +1,73 @@
+# $Id$
+# coding=utf-8
+
+import copy
+import re
+import configuration as c
+
+def ParseOverrideLine(line):
+  level_1 = line.split(":")
+  if len(level_1) > 1:
+    pkgname = level_1[0]
+    data_1 = ":".join(level_1[1:])
+  else:
+    pkgname = None
+    data_1 = level_1[0]
+  level_2 = re.split(c.WS_RE, data_1.strip())
+  if len(level_2) > 1:
+    tag_name = level_2[0]
+    tag_info = " ".join(level_2[1:])
+  else:
+    tag_name = level_2[0]
+    tag_info = None
+  return Override(pkgname, tag_name, tag_info)
+
+
+class Override(object):
+  """Represents an override of a certain checkpkg tag.
+
+  It's similar to checkpkg.CheckpkgTag, but serves a different purpose.
+  """
+
+  def __init__(self, pkgname, tag_name, tag_info):
+    self.pkgname = pkgname
+    self.tag_name = tag_name
+    self.tag_info = tag_info
+
+  def __repr__(self):
+    return (u"Override(%s, %s, %s)"
+            % (repr(self.pkgname), repr(self.tag_name), repr(self.tag_info)))
+
+  def DoesApply(self, tag):
+    """Figures out if this override applies to the given tag."""
+    basket_a = {}
+    basket_b = {}
+    if self.pkgname:
+      basket_a["pkgname"] = self.pkgname
+      basket_b["pkgname"] = tag.pkgname
+    if self.tag_info:
+      basket_a["tag_info"] = self.tag_info
+      basket_b["tag_info"] = tag.tag_info
+    basket_a["tag_name"] = self.tag_name
+    basket_b["tag_name"] = tag.tag_name
+    return basket_a == basket_b
+
+
+def ApplyOverrides(error_tags, overrides):
+  """Filters out all the error tags that overrides apply to.
+
+  O(N * M), but N and M are always small.
+  """
+  tags_after_overrides = []
+  applied_overrides = set([])
+  provided_overrides = set(copy.copy(overrides))
+  for tag in error_tags:
+    override_applies = False
+    for override in overrides:
+      if override.DoesApply(tag):
+        override_applies = True
+        applied_overrides.add(override)
+    if not override_applies:
+      tags_after_overrides.append(tag)
+  unapplied_overrides = provided_overrides.difference(applied_overrides)
+  return tags_after_overrides, unapplied_overrides


Property changes on: csw/mgar/gar/v2/lib/python/overrides.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: csw/mgar/gar/v2/lib/python/overrides_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/overrides_test.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/overrides_test.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -0,0 +1,113 @@
+# $Id$
+# coding=utf-8
+
+import unittest
+import overrides
+import re
+import tag
+
+class ParseOverrideLineUnitTest(unittest.TestCase):
+
+  def setUp(self):
+    line1 = "CSWfoo: foo-override"
+    line2 = "CSWfoo: foo-override foo-info"
+    line3 = "CSWfoo: foo-override foo-info-1 foo-info-2"
+    line4 = ("CSWpmcommonsense: "
+             "pkginfo-description-not-starting-with-uppercase "
+             "common-sense: Some sane defaults for Perl programs")
+    self.o1 = overrides.ParseOverrideLine(line1)
+    self.o2 = overrides.ParseOverrideLine(line2)
+    self.o3 = overrides.ParseOverrideLine(line3)
+    self.o4 = overrides.ParseOverrideLine(line4)
+
+  def test_ParseOverridesLine1(self):
+    self.assertEqual("CSWfoo", self.o1.pkgname)
+
+  def test_ParseOverridesLine2(self):
+    self.assertEqual("foo-override", self.o1.tag_name)
+
+  def test_ParseOverridesLine3(self):
+    self.assertEqual(None, self.o1.tag_info)
+
+  def test_ParseOverridesLine4(self):
+    self.assertEqual("foo-info", self.o2.tag_info)
+
+  def test_ParseOverridesLine5(self):
+    self.assertEqual("CSWfoo", self.o3.pkgname)
+
+  def test_ParseOverridesLine6(self):
+    self.assertEqual("foo-override", self.o3.tag_name)
+
+  def test_ParseOverridesLine7(self):
+    self.assertEqual("foo-info-1 foo-info-2", self.o3.tag_info)
+
+  def test_ParseOverridesLine_4_1(self):
+    self.assertEqual("CSWpmcommonsense", self.o4.pkgname)
+
+  def test_ParseOverridesLine_4_2(self):
+    self.assertEqual(
+        "pkginfo-description-not-starting-with-uppercase",
+        self.o4.tag_name)
+
+  def test_ParseOverridesLine_4_3(self):
+    self.assertEqual(
+        "common-sense: Some sane defaults for Perl programs",
+        self.o4.tag_info)
+
+
+class ApplyOverridesUnitTest(unittest.TestCase):
+
+  # This would be better, more terse. But requires metaclasses.
+  DATA_1 = (
+      (None, 'tag1', 'info1', None, 'tag1', 'info1', None),
+  )
+
+  def test_1a(self):
+    """One tag, no overrides."""
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag")]
+    oo = []
+    self.assertEqual((tags, set([])), overrides.ApplyOverrides(tags, oo))
+
+  def test_1b(self):
+    """One override, matching by tag name only."""
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag")]
+    oo = [overrides.Override(None, "foo-tag", None)]
+    self.assertEqual(([], set([])), overrides.ApplyOverrides(tags, oo))
+
+  def test_1c(self):
+    """One override, matching by tag name only, no pkgname."""
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag")]
+    oo = [overrides.Override(None, "foo-tag", None)]
+    self.assertEqual(([], set([])), overrides.ApplyOverrides(tags, oo))
+
+  def test_2(self):
+    """One override, matching by tag name and tag info, no pkgname."""
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag")]
+    oo = [overrides.Override(None, "foo-tag", None)]
+    self.assertEqual(([], set([])), overrides.ApplyOverrides(tags, oo))
+
+  def test_3(self):
+    """One override, matching by tag name, mismatching tag info, no pkgname."""
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
+    oo = [overrides.Override(None, "foo-tag", "tag-info-2")]
+    self.assertEqual((tags, set(oo)), overrides.ApplyOverrides(tags, oo))
+
+  def test_4(self):
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
+    oo = [overrides.Override(None, "foo-tag", "tag-info-1")]
+    self.assertEqual(([], set([])), overrides.ApplyOverrides(tags, oo))
+
+  def test_5(self):
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
+    oo = [overrides.Override("CSWfoo", "foo-tag", "tag-info-1")]
+    self.assertEqual(([], set([])), overrides.ApplyOverrides(tags, oo))
+
+  def test_6(self):
+    """Pkgname mismatch."""
+    tags = [tag.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
+    oo = [overrides.Override("CSWbar", "foo-tag", "tag-info-1")]
+    self.assertEqual((tags, set(oo)), overrides.ApplyOverrides(tags, oo))
+
+
+if __name__ == '__main__':
+  unittest.main()


Property changes on: csw/mgar/gar/v2/lib/python/overrides_test.py
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: csw/mgar/gar/v2/lib/python/package_checks.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks.py	2010-07-05 09:29:13 UTC (rev 10432)
+++ csw/mgar/gar/v2/lib/python/package_checks.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -19,6 +19,7 @@
 import pprint
 import textwrap
 import dependency_checks as depchecks
+import configuration as c
 from Cheetah import Template
 
 PATHS_ALLOWED_ONLY_IN = {
@@ -214,7 +215,7 @@
 
 
 def CheckVendorURL(pkg_data, error_mgr, logger, messenger):
-  vendorurl = opencsw.WS_RE.split(pkg_data["pkginfo"]["VENDOR"])[0]
+  vendorurl = c.WS_RE.split(pkg_data["pkginfo"]["VENDOR"])[0]
   if not re.match(VENDORURL_RE, vendorurl):
     error_mgr.ReportError("pkginfo-bad-vendorurl", vendorurl,
                           "Solution: add VENDOR_URL to GAR Recipe")
@@ -376,7 +377,7 @@
   pkgmap = pkg_data["pkgmap"]
   if "CLASSES" not in pkginfo:
     return
-  pkginfo_classes = set(re.split(opencsw.WS_RE, pkginfo["CLASSES"]))
+  pkginfo_classes = set(re.split(c.WS_RE, pkginfo["CLASSES"]))
   pkgmap_classes = set()
   for entry in pkgmap:
     if entry["class"]:  # might be None

Modified: csw/mgar/gar/v2/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_test.py	2010-07-05 09:29:13 UTC (rev 10432)
+++ csw/mgar/gar/v2/lib/python/package_checks_test.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -719,7 +719,7 @@
         'mime_type': 'application/x-sharedlib; charset=binary',
         'path': 'opt/csw/lib/sparcv9/foo/subdir/libfoo.so.1'}]
     self.error_mgr_mock.ReportError(
-        'binary-wrong-wrong-placement',
+        'binary-disallowed-placement',
         'file=opt/csw/lib/sparcv9/foo/subdir/libfoo.so.1 '
         'arch_id=2 arch_name=sparcv8 bad_path=sparcv9')
 

Added: csw/mgar/gar/v2/lib/python/tag.py
===================================================================
--- csw/mgar/gar/v2/lib/python/tag.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/tag.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -0,0 +1,57 @@
+# $Id$
+# coding=utf-8
+
+import re
+import configuration as c
+
+class CheckpkgTag(object):
+  """Represents a tag to be written to the checkpkg tag file."""
+
+  def __init__(self, pkgname, tag_name, tag_info=None, severity=None, msg=None):
+    self.pkgname = pkgname
+    self.tag_name = tag_name
+    self.tag_info = tag_info
+    self.severity = severity
+    self.msg = msg
+
+  def __repr__(self):
+    return (u"CheckpkgTag(%s, %s, %s)"
+            % (repr(self.pkgname),
+               repr(self.tag_name),
+               repr(self.tag_info)))
+
+  def ToGarSyntax(self):
+    """Presents the error tag using GAR syntax."""
+    msg_lines = []
+    if self.msg:
+      msg_lines.extend(textwrap(self.msg, 70,
+                                initial_indent="# ",
+                                subsequent_indent="# "))
+    if self.tag_info:
+      tag_postfix = "|%s" % self.tag_info.replace(" ", "|")
+    else:
+      tag_postfix = ""
+    msg_lines.append(u"CHECKPKG_OVERRIDES_%s += %s%s"
+                     % (self.pkgname, self.tag_name, tag_postfix))
+    return "\n".join(msg_lines)
+
+
+def ParseTagLine(line):
+  """Parses a line from the tag.${module} file.
+
+  Returns a triplet of pkgname, tagname, tag_info.
+  """
+  level_1 = line.strip().split(":")
+  if len(level_1) > 1:
+    data_1 = ":".join(level_1[1:])
+    pkgname = level_1[0]
+  else:
+    data_1 = level_1[0]
+    pkgname = None
+  level_2 = re.split(c.WS_RE, data_1.strip())
+  tag_name = level_2[0]
+  if len(level_2) > 1:
+    tag_info = " ".join(level_2[1:])
+  else:
+    tag_info = None
+  return (pkgname, tag_name, tag_info)


Property changes on: csw/mgar/gar/v2/lib/python/tag.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: csw/mgar/gar/v2/lib/python/tag_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/tag_test.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/tag_test.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -0,0 +1,50 @@
+# $Id$
+# coding=utf-8
+
+import unittest
+import tag
+
+
+class CheckpkgTagUnitTest(unittest.TestCase):
+
+  def testToGarSyntaxNoParam(self):
+    t = tag.CheckpkgTag("CSWfoo", "bar")
+    self.assertEquals(u'CHECKPKG_OVERRIDES_CSWfoo += bar', t.ToGarSyntax())
+
+  def testToGarSyntaxWithParam(self):
+    t = tag.CheckpkgTag("CSWfoo", "bar", "parameter")
+    self.assertEquals(u'CHECKPKG_OVERRIDES_CSWfoo += bar|parameter', t.ToGarSyntax())
+
+  def testToGarSyntaxWithParamWithSpacees(self):
+    t = tag.CheckpkgTag("CSWfoo", "bar", "a b c")
+    self.assertEquals(u'CHECKPKG_OVERRIDES_CSWfoo += bar|a|b|c', t.ToGarSyntax())
+
+
+class ParseTagLineUnitTest(unittest.TestCase):
+
+  def testParseTagLine1(self):
+    line = "foo-tag"
+    self.assertEquals((None, "foo-tag", None), tag.ParseTagLine(line))
+
+  def testParseTagLine2(self):
+    line = "CSWfoo: foo-tag"
+    self.assertEquals(("CSWfoo", "foo-tag", None), tag.ParseTagLine(line))
+
+  def testParseTagLine3(self):
+    line = "CSWfoo: foo-tag foo-info"
+    self.assertEquals(("CSWfoo", "foo-tag", "foo-info"),
+                      tag.ParseTagLine(line))
+
+  def testParseTagLine4(self):
+    line = "CSWfoo: foo-tag foo-info1 foo-info2"
+    self.assertEquals(("CSWfoo", "foo-tag", "foo-info1 foo-info2"),
+                      tag.ParseTagLine(line))
+
+  def testParseTagLine_WithUrl(self):
+    line = "CSWfoo: tag-with-an-url http://www.example.com/"
+    self.assertEquals(("CSWfoo", "tag-with-an-url", "http://www.example.com/"),
+                      tag.ParseTagLine(line))
+
+
+if __name__ == '__main__':
+  unittest.main()


Property changes on: csw/mgar/gar/v2/lib/python/tag_test.py
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: csw/mgar/gar/v2/tests/run_tests.py
===================================================================
--- csw/mgar/gar/v2/tests/run_tests.py	2010-07-05 09:29:13 UTC (rev 10432)
+++ csw/mgar/gar/v2/tests/run_tests.py	2010-07-05 10:13:27 UTC (rev 10433)
@@ -14,6 +14,7 @@
 from example_test            import *
 from opencsw_test            import *
 from overrides_test          import *
+from tag_test                import *
 from package_checks_test     import *
 
 if __name__ == '__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