[csw-devel] SF.net SVN: gar:[8184] csw/mgar/gar/v2
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Tue Jan 26 16:16:58 CET 2010
Revision: 8184
http://gar.svn.sourceforge.net/gar/?rev=8184&view=rev
Author: wahwah
Date: 2010-01-26 15:16:53 +0000 (Tue, 26 Jan 2010)
Log Message:
-----------
mGAR v2: checkpkg, introduce abstractions to reduce the amount of boilerplate code per module.
Modified Paths:
--------------
csw/mgar/gar/v2/bin/checkpkg
csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py
csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-obsolete-deps.py
csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py
csw/mgar/gar/v2/lib/python/checkpkg.py
csw/mgar/gar/v2/lib/python/opencsw.py
Modified: csw/mgar/gar/v2/bin/checkpkg
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg 2010-01-26 10:44:58 UTC (rev 8183)
+++ csw/mgar/gar/v2/bin/checkpkg 2010-01-26 15:16:53 UTC (rev 8184)
@@ -599,11 +599,11 @@
echo
for log_file in ${log_files}; do
if [[ -s "${log_file}" ]]; then
- debugmsg "LOG START: ${log_file}"
- debugmsg
+ debugmsg ">> LOG START: ${log_file}"
cat "${log_file}"
- debugmsg
- debugmsg "LOG END: ${log_file}"
+ debugmsg "<< LOG END: ${log_file}"
+ else
+ debugmsg "-- LOG ${log_file} is empty"
fi
done
echo
Modified: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py 2010-01-26 10:44:58 UTC (rev 8183)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py 2010-01-26 15:16:53 UTC (rev 8184)
@@ -24,6 +24,7 @@
"..", "..", "lib", "python"]
sys.path.append(os.path.join(*path_list))
import checkpkg
+import opencsw
DUMP_BIN = "/usr/ccs/bin/dump"
@@ -164,7 +165,8 @@
dependent_pkgs = {}
for checker in checkers:
pkgname = checker.pkgname
- declared_dependencies = checker.GetDependencies()
+ dir_format_pkg = opencsw.DirectoryFormatPackage(checker.pkgpath)
+ declared_dependencies = dir_format_pkg.GetDependencies()
if options.debug:
sanitized_pkgname = pkgname.replace("-", "_")
data_file_name = "/var/tmp/checkpkg_test_data_%s.py" % sanitized_pkgname
Modified: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-obsolete-deps.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-obsolete-deps.py 2010-01-26 10:44:58 UTC (rev 8183)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-obsolete-deps.py 2010-01-26 15:16:53 UTC (rev 8184)
@@ -1,6 +1,9 @@
#!/opt/csw/bin/python2.6
# $Id$
+"""Makes sure that obsolete packages are not added as dependencies.
+"""
+
import logging
import os.path
import sys
@@ -24,27 +27,37 @@
},
}
+def CheckObsoleteDeps(pkg):
+ """Checks for obsolete dependencies."""
+ errors = []
+ deps = set(pkg.GetDependencies())
+ obsolete_pkg_deps = deps.intersection(set(OBSOLETE_DEPS))
+ if obsolete_pkg_deps:
+ for obsolete_pkg in obsolete_pkg_deps:
+ errors.append(
+ checkpkg.PackageError(
+ "Package %s should not depend on %s."
+ % (pkg.pkgname, obsolete_pkg)))
+ if "hint" in OBSOLETE_DEPS[obsolete_pkg]:
+ errors.append(
+ checkpkg.PackageError("Hint: %s" % OBSOLETE_DEPS[obsolete_pkg]["hint"]))
+ if "url" in OBSOLETE_DEPS[obsolete_pkg]:
+ errors.append(
+ checkpkg.PackageError("URL: %s" % OBSOLETE_DEPS[obsolete_pkg]["url"]))
+ return errors
+
+
def main():
options, args = checkpkg.GetOptions()
- ok = True
- for pkgname in args:
- pkgpath = os.path.join(options.extractdir, pkgname)
- checker = checkpkg.CheckpkgBase(options.extractdir, pkgname)
- deps = set(checker.GetDependencies())
- obsolete_pkg_deps = deps.intersection(set(OBSOLETE_DEPS))
- if obsolete_pkg_deps:
- ok = False
- for pkg in obsolete_pkg_deps:
- print ("ERROR: Package %s should not depend on %s."
- % (checker.pkgname, pkg))
- if "hint" in OBSOLETE_DEPS[pkg]:
- print "Hint:", OBSOLETE_DEPS[pkg]["hint"]
- if "url" in OBSOLETE_DEPS[pkg]:
- print "URL:", OBSOLETE_DEPS[pkg]["url"]
- if ok:
- sys.exit(0)
- else:
- sys.exit(1)
+ pkgnames = args
+ check_manager = checkpkg.CheckpkgManager("obsolete dependencies",
+ options.extractdir,
+ pkgnames,
+ options.debug)
+ check_manager.RegisterIndividualCheck(CheckObsoleteDeps)
+ exit_code, report = check_manager.Run()
+ print report.strip()
+ sys.exit(exit_code)
if __name__ == '__main__':
Modified: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py 2010-01-26 10:44:58 UTC (rev 8183)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py 2010-01-26 15:16:53 UTC (rev 8184)
@@ -18,16 +18,51 @@
sys.path.append(os.path.join(*path_list))
import checkpkg
+# Defining checking functions.
+
+def CheckIndividualPackage(pkg):
+ """Checks an individual package.
+
+ Gets a DirctoryFormatPackage as an argument, and returns a list of errors.
+
+ Errors should be a list of checkpkg.PackageError objects:
+
+ errors.append(checkpkg.PackageError("There's something wrong."))
+ """
+ errors = []
+ # Checking code for an individual package goes here.
+ return errors
+
+
+def CheckAsetOfPackages(pkgs):
+ """Checks a set of packages.
+
+ Sometimes individual checks aren't enough. If you need to write code which
+ needs to examine multiple packages at the same time, use this function.
+
+ Gets a list of packages.
+ """
+ errors = []
+ # Checking code goes here.
+ return errors
+
+
def main():
options, args = checkpkg.GetOptions()
- if not os.path.isdir(options.extractdir):
- raise checkpkg.PackageError("The extract base directory doesn't exist: %s" % options.extractdir)
- for pkgname in args:
- pkgpath = os.path.join(options.extractdir, pkgname)
- if not os.path.isdir(pkgpath):
- raise checkpkg.PackageError("The package directory doesn't exist: %s" % pkgpath)
- logging.debug("Dummy plugin says the package %s is extracted to %s",
- pkgname, options.extractdir)
+ pkgnames = args
+ # CheckpkgManager class abstracts away things such as the collection of
+ # results.
+ check_manager = checkpkg.CheckpkgManager("a template of a checkpkg module",
+ options.extractdir,
+ pkgnames,
+ options.debug)
+ # Registering previously defined checks.
+ check_manager.RegisterIndividualCheck(CheckIndividualPackage)
+ check_manager.RegisterSetCheck(CheckAsetOfPackages)
+ # Running the checks, reporting and exiting.
+ exit_code, report = check_manager.Run()
+ print report.strip()
+ sys.exit(exit_code)
if __name__ == '__main__':
Modified: csw/mgar/gar/v2/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg.py 2010-01-26 10:44:58 UTC (rev 8183)
+++ csw/mgar/gar/v2/lib/python/checkpkg.py 2010-01-26 15:16:53 UTC (rev 8184)
@@ -14,6 +14,7 @@
import subprocess
import StringIO
from Cheetah import Template
+import opencsw
SYSTEM_PKGMAP = "/var/sadm/install/contents"
WS_RE = re.compile(r"\s+")
@@ -66,6 +67,18 @@
#end if
"""
+ERROR_REPORT_TMPL = u"""#if $errors
+ERROR: One or more errors have been found by $name.
+#for $error in $errors
+$repr($error)
+#end for
+#else
+#if $debug
+OK: $name found no problems.
+#end if
+#end if
+"""
+
class Error(Exception):
pass
@@ -141,18 +154,8 @@
file_basenames.extend(files)
return file_basenames
- def GetDependencies(self):
- fd = open(os.path.join(self.pkgpath, "install", "depend"), "r")
- depends = {}
- for line in fd:
- fields = re.split(WS_RE, line)
- if fields[0] == "P":
- depends[fields[1]] = " ".join(fields[1:])
- fd.close()
- return depends
-
def FormatDepsReport(self, missing_deps, surplus_deps, orphan_sonames):
- """A intermediate version in which StringIO is used."""
+ """To be removed."""
namespace = {
"pkgname": self.pkgname,
"missing_deps": missing_deps,
@@ -567,3 +570,48 @@
binary_data[RUNPATH].append("/lib/$ISALIST")
binary_data[RUNPATH].append("/lib")
return binary_data
+
+
+class CheckpkgManager(object):
+ """Takes care of calling checking functions"""
+
+ def __init__(self, name, extractdir, pkgname_list, debug=False):
+ self.debug = debug
+ self.name = name
+ self.extractdir = extractdir
+ self.pkgname_list = pkgname_list
+ self.errors = []
+ self.individual_checks = []
+ self.set_checks = []
+ self.packages = []
+
+ def RegisterIndividualCheck(self, function):
+ self.individual_checks.append(function)
+
+ def RegisterSetCheck(self, function):
+ self.set_checks.append(function)
+
+ def Run(self):
+ """Runs all the checks
+
+ Returns a tuple of an exit code and a report.
+ """
+ packages = []
+ errors = []
+ for pkgname in self.pkgname_list:
+ pkg_path = os.path.join(self.extractdir, pkgname)
+ packages.append(opencsw.DirectoryFormatPackage(pkg_path))
+ for pkg in packages:
+ for function in self.individual_checks:
+ errors.extend(function(pkg))
+ # Set checks
+ for function in self.set_checks:
+ errors.extend(function(packages))
+ namespace = {
+ "name": self.name,
+ "errors": errors,
+ "debug": self.debug,
+ }
+ t = Template.Template(ERROR_REPORT_TMPL, searchList=[namespace])
+ exit_code = bool(errors)
+ return (exit_code, unicode(t))
Modified: csw/mgar/gar/v2/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw.py 2010-01-26 10:44:58 UTC (rev 8183)
+++ csw/mgar/gar/v2/lib/python/opencsw.py 2010-01-26 15:16:53 UTC (rev 8184)
@@ -35,6 +35,8 @@
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+")
+
ADMIN_FILE_CONTENT = """
basedir=default
runlevel=nocheck
@@ -52,6 +54,7 @@
keystore=/var/sadm/security
proxy=
"""
+
EMAIL_TMPL = """From: %(from)s
To: %(to)s
Cc: %(cc)s
@@ -616,6 +619,17 @@
pkginfo_name = "%s - %s" % (catalog_name, description)
self.SetPkginfoEntry("NAME", pkginfo_name)
+ def GetDependencies(self):
+ fd = open(os.path.join(self.directory, "install", "depend"), "r")
+ depends = {}
+ for line in fd:
+ fields = re.split(WS_RE, line)
+ if fields[0] == "P":
+ depends[fields[1]] = " ".join(fields[1:])
+ fd.close()
+ return depends
+
+
class Pkgmap(object):
def __init__(self, input, permissions=False,
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