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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sat May 8 08:43:45 CEST 2010


Revision: 9835
          http://gar.svn.sourceforge.net/gar/?rev=9835&view=rev
Author:   wahwah
Date:     2010-05-08 06:43:45 +0000 (Sat, 08 May 2010)

Log Message:
-----------
mGAR v2: checkpkg, prep work for multiple system pkgmaps.

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

Modified: csw/mgar/gar/v2/bin/checkpkg
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg	2010-05-08 06:42:31 UTC (rev 9834)
+++ csw/mgar/gar/v2/bin/checkpkg	2010-05-08 06:43:45 UTC (rev 9835)
@@ -58,10 +58,6 @@
 readonly selfpath="$0"
 readonly selfargs="$@"
 
-# always print out a warning message. (to stderr)
-# exit script, if quit_on_warn set
-
-
 cleanup(){
 	if [[ -d "$EXTRACTDIR" ]] ; then
 		rm -rf $EXTRACTDIR
@@ -82,13 +78,6 @@
 	rm $SETINF*
     fi
 }
-warnmsg(){
-	print WARNING: $* >/dev/fd/2
-	if [[ "$quit_on_warn" != "" ]] ; then
-		cleanup
-		exit 1
-	fi
-}
 
 # Print error message, and quit program.
 errmsg(){
@@ -117,9 +106,13 @@
 display_help=0
 SKIP_STATS_COLLECTION=0
 MD5_SUMS_CATALOG_FILE=""
+INSTALL_CONTENTS_FILES="/var/sadm/install/contents"
 
-while getopts hsdNM:o: opt; do
+while getopts hsdNM:o:c: opt; do
 	case "${opt}" in
+	  c)
+	    INSTALL_CONTENTS_FILES="${INSTALL_CONTENTS_FILES} ${OPTARG}"
+	    ;;
 	  s)
       SAVE_TAGS=1
       ;;
@@ -129,9 +122,6 @@
     d)
       DEBUG=1
       ;;
-    e)
-      quit_on_warn=1
-      ;;
     h)
       display_help=1
       ;;
@@ -148,15 +138,22 @@
 done
 shift $(( $OPTIND -1 ))
 
-readonly SAVE_TAGS SAVED_TAGS_FILE MD5_SUMS_CATALOG_FILE
+readonly INSTALL_CONTENTS_FILES
+readonly MD5_SUMS_CATALOG_FILE
+readonly SAVED_TAGS_FILE
+readonly SAVE_TAGS
+readonly SKIP_STATS_COLLECTION
 
 if [[ "${display_help}" -eq 1 ]] ; then
-	print 'Usage: checkpkg [options] pkg1 [pkg2 ....]'
-	print 'Options:'
-	print '   -s  save error tags on disk'
-	print '   -d  display debug messages'
-	print '   -e  exit on warnings (soon to be obsolete)'
-	exit 0
+  print 'Usage: checkpkg [options] pkg1 [pkg2 ....]'
+  print 'Options:'
+  print '   -c <file>  use an additional install/contents file'
+  print '   -s         save error tags on disk'
+  print '   -o <file>  save tag output to file'
+  print '   -d         display debug messages'
+  print '   -N         skip statistics collection'
+  print '   -M <file>  use package md5sums from a catalog file'
+  exit 0
 fi
 
 if [[ "${SAVE_TAGS}" -eq 1 ]]; then

Modified: csw/mgar/gar/v2/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg.py	2010-05-08 06:42:31 UTC (rev 9834)
+++ csw/mgar/gar/v2/lib/python/checkpkg.py	2010-05-08 06:43:45 UTC (rev 9835)
@@ -113,7 +113,7 @@
 #end if
 #if $messages
 #for $msg in $messages
-$textwrap.fill($msg, 78, initial_indent="# ", subsequent_indent="# ")
+$textwrap.fill($msg, 78, initial_indent=" * ", subsequent_indent="   ")
 #end for
 #end if
 #if $gar_lines
@@ -206,7 +206,7 @@
   CHECKPKG_DIR = ".checkpkg"
   SQLITE3_DBNAME_TMPL = "var-sadm-install-contents-cache-%s"
 
-  def __init__(self):
+  def __init__(self, system_pkgmap_files=None):
     """There is no need to re-parse it each time.
 
     Read it slowly the first time and cache it for later."""
@@ -218,6 +218,10 @@
     self.file_mtime = None
     self.cache_mtime = None
     self.initialized = False
+    if not system_pkgmap_files:
+      self.system_pkgmap_files = [SYSTEM_PKGMAP]
+    else:
+      self.system_pkgmap_files = system_pkgmap_files
 
   def _LazyInitializeDatabase(self):
     if not self.initialized:
@@ -236,7 +240,7 @@
         self.PurgeDatabase()
         self.PopulateDatabase()
     else:
-      print "Building a cache of %s." % SYSTEM_PKGMAP
+      print "Building a cache of %s." % self.system_pkgmap_files
       print "The cache will be kept in %s." % self.db_path
       if not os.path.exists(self.checkpkg_dir):
         logging.debug("Creating %s", self.checkpkg_dir)
@@ -279,15 +283,24 @@
     egrep -v 'SUNWbcp|SUNWowbcp|SUNWucb' /var/sadm/install/contents |
         fgrep -f $EXTRACTDIR/liblist >$EXTRACTDIR/shortcatalog
     """
-    contents_length = os.stat(SYSTEM_PKGMAP).st_size
+    for pkgmap_path in self.system_pkgmap_files:
+      self._ProcessSystemPkgmap(pkgmap_path)
+    self._CreateDbIndex()
+    self.PopulatePackagesTable()
+    self.SetDatabaseMtime()
+    self.SetDatabaseSchemaVersion()
+    self.conn.commit()
+
+  def _ProcessSystemPkgmap(self, pkgmap_path):
+    contents_length = os.stat(pkgmap_path).st_size
     estimated_lines = contents_length / INSTALL_CONTENTS_AVG_LINE_LENGTH
-    system_pkgmap_fd = open(SYSTEM_PKGMAP, "r")
+    system_pkgmap_fd = open(pkgmap_path, "r")
     stop_re = re.compile("(%s)" % "|".join(self.STOP_PKGS))
     # Creating a data structure:
     # soname - {<path1>: <line1>, <path2>: <line2>, ...}
     logging.debug("Building sqlite3 cache db of the %s file",
-                  SYSTEM_PKGMAP)
-    print "Processing %s" % SYSTEM_PKGMAP
+                  pkgmap_path)
+    print "Processing %s" % pkgmap_path
     c = self.conn.cursor()
     count = itertools.count()
     sql = "INSERT INTO systempkgmap (basename, path, line) VALUES (?, ?, ?);"
@@ -304,13 +317,12 @@
       pkgmap_entry_dir, pkgmap_entry_base_name = os.path.split(pkgmap_entry_path)
       c.execute(sql, (pkgmap_entry_base_name, pkgmap_entry_dir, line.strip()))
     print "\rAll lines of %s were processed." % SYSTEM_PKGMAP
+
+  def _CreateDbIndex(self):
     print "Creating the main database index."
     sql = "CREATE INDEX basename_idx ON systempkgmap(basename);"
+    c = self.conn.cursor()
     c.execute(sql)
-    self.PopulatePackagesTable()
-    self.SetDatabaseMtime()
-    self.SetDatabaseSchemaVersion()
-    self.conn.commit()
 
   def _ParsePkginfoLine(self, line):
     fields = re.split(WS_RE, line)


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