[csw-devel] SF.net SVN: gar:[8620] csw/mgar/gar/v2-checkpkg-stats

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Wed Feb 17 15:07:57 CET 2010


Revision: 8620
          http://gar.svn.sourceforge.net/gar/?rev=8620&view=rev
Author:   wahwah
Date:     2010-02-17 14:07:57 +0000 (Wed, 17 Feb 2010)

Log Message:
-----------
mGAR v2: Started implementing base checks. Moving check functions to a common module. Started a file with unit tests for the checks.

Modified Paths:
--------------
    csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg
    csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py
    csw/mgar/gar/v2-checkpkg-stats/tests/run_tests.py

Added Paths:
-----------
    csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-basic.py
    csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks.py
    csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks_test.py

Modified: csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg	2010-02-17 14:07:48 UTC (rev 8619)
+++ csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg	2010-02-17 14:07:57 UTC (rev 8620)
@@ -216,12 +216,6 @@
 basedir=`sed -n 's/^BASEDIR=//p' $TMPFILE`
 pkgarch=`sed -n 's/^ARCH=//p' $TMPFILE|head -1`
 
-case $software in
-     *[A-Z]*)
-	errmsg "$software must be all lowercase"
-	;;
-esac
-
 case `basename $f` in
 	${software}-${version}-*)
 		# file name looks okay

Added: csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-basic.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-basic.py	                        (rev 0)
+++ csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-basic.py	2010-02-17 14:07:57 UTC (rev 8620)
@@ -0,0 +1,44 @@
+#!/opt/csw/bin/python2.6
+# $Id: checkpkg-you-can-write-your-own.py 8571 2010-02-16 09:05:51Z wahwah $
+
+"""This is a dummy module. You can use it as a boilerplate for your own modules.
+
+Copy it and modify.
+"""
+
+import os.path
+import sys
+
+CHECKPKG_MODULE_NAME = "basic checks ported from Korn shell"
+
+# The following bit of code sets the correct path to Python libraries
+# distributed with GAR.
+path_list = [os.path.dirname(__file__),
+             "..", "..", "lib", "python"]
+sys.path.append(os.path.join(*path_list))
+import checkpkg
+import package_checks
+
+def main():
+  options, args = checkpkg.GetOptions()
+  md5sums = args
+  # CheckpkgManager class abstracts away things such as the collection of
+  # results.
+  check_manager = checkpkg.CheckpkgManager(CHECKPKG_MODULE_NAME,
+                                           options.stats_basedir,
+                                           md5sums,
+                                           options.debug)
+  # Registering functions defined above.
+  check_manager.RegisterIndividualCheck(package_checks.CatalognameLowercase)
+  check_manager.RegisterIndividualCheck(package_checks.FileNameSanity)
+  # Running the checks, reporting and exiting.
+  exit_code, screen_report, tags_report = check_manager.Run()
+  f = open(options.output, "w")
+  f.write(tags_report)
+  f.close()
+  print screen_report.strip()
+  sys.exit(exit_code)
+
+
+if __name__ == '__main__':
+  main()


Property changes on: csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-basic.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keyword
   + Id

Modified: csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py	2010-02-17 14:07:48 UTC (rev 8619)
+++ csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py	2010-02-17 14:07:57 UTC (rev 8620)
@@ -895,7 +895,7 @@
     stats_path = self.GetStatsPath()
     self.MakeStatsDir()
     dir_pkg = self.GetDirFormatPkg()
-    logging.info("Collecting package statistics.")
+    logging.info("Collecting %s package statistics.", repr(dir_pkg.pkgname))
     self.DumpObject(dir_pkg.GetAllFilenames(), "all_filenames")
     self.DumpObject(self.GetBasicStats(), "basic_stats")
     self.DumpObject(dir_pkg.ListBinaries(), "binaries")

Added: csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks.py	                        (rev 0)
+++ csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks.py	2010-02-17 14:07:57 UTC (rev 8620)
@@ -0,0 +1,32 @@
+# Defining the checking functions.  They come in two flavors: individual
+# package checks and set checks.
+
+import checkpkg
+import re
+
+def CatalognameLowercase(pkg_data, debug):
+  errors = []
+  # Here's how to report an error:
+  catalogname = pkg_data["basic_stats"]["catalogname"]
+  if catalogname != catalogname.lower():
+    errors.append(checkpkg.CheckpkgTag(
+      pkg_data["basic_stats"]["pkgname"],
+      "catalogname-not-lowercase"))
+  if not re.match(r"^\w+$", catalogname):
+    errors.append(checkpkg.CheckpkgTag(
+      pkg_data["basic_stats"]["pkgname"],
+      "catalogname-is-not-a-simple-word"))
+  return errors
+
+
+def FileNameSanity(pkg_data, debug):
+  errors = []
+  # Here's how to report an error:
+  basic_stats = pkg_data["basic_stats"]
+  revision_info = basic_stats["parsed_basename"]["revision_info"]
+  catalogname = pkg_data["basic_stats"]["catalogname"]
+  if "REV" not in revision_info:
+    errors.append(checkpkg.CheckpkgTag(
+      pkg_data["basic_stats"]["pkgname"],
+      "rev-tag-missing-in-filename"))
+  return errors


Property changes on: csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks.py
___________________________________________________________________
Added: svn:keyword
   + Id

Added: csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks_test.py	                        (rev 0)
+++ csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks_test.py	2010-02-17 14:07:57 UTC (rev 8620)
@@ -0,0 +1,55 @@
+#!/opt/csw/bin/python2.6
+# coding=utf-8
+# $Id$
+
+import unittest
+import package_checks as pc
+
+class PackageChecksUnitTest(unittest.TestCase):
+
+  def setUp(self):
+    self.pkg_data_1 = {
+    	  "basic_stats": {
+    	  	"pkgname": "CSWfoo"
+        }
+    }
+    self.pkg_data_2 = {
+        'basic_stats': {
+          'parsed_basename':
+              {'revision_info': {'REV': '2010.02.15'},
+               'catalogname': 'python_tk',
+               'full_version_string': '2.6.4,REV=2010.02.15',
+               'version': '2.6.4',
+               'version_info': {
+                 'minor version': '6',
+                 'major version': '2',
+                 'patchlevel': '4'}},
+          'pkgname': 'CSWpython-tk',
+          'stats_version': 1,
+          'pkg_basename': 'python_tk-2.6.4,REV=2010.02.15-SunOS5.8-sparc-CSW.pkg.gz',
+          'pkg_path': '/tmp/pkg_lL0HDH/python_tk-2.6.4,REV=2010.02.15-SunOS5.8-sparc-CSW.pkg.gz',
+          'catalogname': 'python_tk'}}
+
+  def testCatalogName_1(self):
+    self.pkg_data_1["basic_stats"]["catalogname"] = "Foo"
+    errors = pc.CatalognameLowercase(self.pkg_data_1, False)
+    self.failUnless(errors)
+
+  def testCatalogName_2(self):
+    self.pkg_data_1["basic_stats"]["catalogname"] = "foo"
+    errors = pc.CatalognameLowercase(self.pkg_data_1, False)
+    self.failIf(errors)
+
+  def testCatalogNameSpecialCharacters(self):
+    self.pkg_data_1["basic_stats"]["catalogname"] = "foo+abc&123"
+    errors = pc.CatalognameLowercase(self.pkg_data_1, False)
+    self.failUnless(errors)
+
+  def testFileNameSanity(self):
+    del(self.pkg_data_2["basic_stats"]["parsed_basename"]["revision_info"]["REV"])
+    errors = pc.FileNameSanity(self.pkg_data_2, False)
+    self.failUnless(errors)
+
+
+if __name__ == '__main__':
+  unittest.main()


Property changes on: csw/mgar/gar/v2-checkpkg-stats/lib/python/package_checks_test.py
___________________________________________________________________
Added: svn:keyword
   + Id

Modified: csw/mgar/gar/v2-checkpkg-stats/tests/run_tests.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/tests/run_tests.py	2010-02-17 14:07:48 UTC (rev 8619)
+++ csw/mgar/gar/v2-checkpkg-stats/tests/run_tests.py	2010-02-17 14:07:57 UTC (rev 8620)
@@ -10,9 +10,10 @@
 
 # To add more test files, create <name>.py file and add a corresponding line
 # here:
-from opencsw_test  import *
-from checkpkg_test import *
-from example_test  import *
+from opencsw_test        import *
+from checkpkg_test       import *
+from example_test        import *
+from package_checks_test import *
 
 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