SF.net SVN: gar:[23663] csw/mgar/gar/v2/lib

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue May 20 00:21:44 CEST 2014


Revision: 23663
          http://sourceforge.net/p/gar/code/23663
Author:   wahwah
Date:     2014-05-19 22:21:43 +0000 (Mon, 19 May 2014)
Log Message:
-----------
pkgdb: Improved logging

Using hierarchical loggers with "opencsw" as the root.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg_lib.py
    csw/mgar/gar/v2/lib/python/models.py
    csw/mgar/gar/v2/lib/python/relational_util.py
    csw/mgar/gar/v2/lib/web/releases_web.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2014-05-19 22:21:33 UTC (rev 23662)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2014-05-19 22:21:43 UTC (rev 23663)
@@ -884,7 +884,7 @@
           pkgname, self.osrel, self.arch, self.catrel, catalog, examined_files_by_pkg,
           rest_client=self.rest_client)
       for function in self.individual_checks:
-        logger = logging.getLogger("%s-%s" % (pkgname, function.__name__))
+        logger = logging.getLogger("opencsw.%s-%s" % (pkgname, function.__name__))
         logger.debug("Calling %s", function.__name__)
         function(pkg_data, check_interface, logger=logger, messenger=messenger)
         pbar.update(count.next())
@@ -908,7 +908,7 @@
     # Set checks
     logging.info("Tasting them all at once...")
     for function in self.set_checks:
-      logger = logging.getLogger(function.__name__)
+      logger = logging.getLogger("opencsw." + function.__name__)
       check_interface = SetCheckInterface(
           self.osrel, self.arch, self.catrel, catalog, examined_files_by_pkg,
           rest_client=self.rest_client)
@@ -951,12 +951,13 @@
   def __init__(self):
     super(Catalog, self).__init__()
     self.pkgs_by_path_cache = {}
+    self.logger = logging.getLogger('opencsw.checkpkg_lib.Catalog')
 
   def GetInstalledPackages(self, osrel, arch, catrel):
     sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad(
         osrel, arch, catrel)
-    logging.debug("GetInstalledPackages(%s, %s, %s)"
-                  % (osrel, arch, catrel))
+    self.logger.debug("GetInstalledPackages(%s, %s, %s)"
+                      % (osrel, arch, catrel))
 
     # Object defining a filter for our OS release, architecture and catalog
     # release.
@@ -1157,7 +1158,8 @@
 
   def AddSrv4ToCatalog(self, sqo_srv4, osrel, arch, catrel, who=None):
     """Registers a srv4 file in a catalog."""
-    logging.debug("AddSrv4ToCatalog(%s, %s, %s, %s, %s)",
+    self.logger.debug(
+        "AddSrv4ToCatalog(%s, %r, %r, %r, %r)",
         sqo_srv4, osrel, arch, catrel, who)
     if not who:
       who = 'unknown'
@@ -1204,8 +1206,9 @@
             m.Srv4FileInCatalog.q.catrel==sqo_catrel,
             m.Srv4FileInCatalog.q.srv4file==sqo_srv4))
     if res.count():
-      logging.debug("%s is already part of %s %s %s",
-                      sqo_srv4, osrel, arch, catrel)
+      self.logger.debug(
+          "%s is already part of %s %s %s, count=%d",
+          sqo_srv4, osrel, arch, catrel, res.count())
       # Our srv4 is already part of that catalog.
       return
     # SQL INSERT happens here.
@@ -1216,8 +1219,12 @@
         srv4file=sqo_srv4,
         created_by=who)
     # The package is now in the catalog.
+    self.logger.debug('The package %s was inserted into catalog %s %s %s: %s',
+                      sqo_srv4.basename, osrel, arch, catrel, pkg_in_cat)
 
   def RemoveSrv4(self, sqo_srv4, osrel, arch, catrel):
+    catspec = CatalogSpec(catrel, arch, osrel)
+    self.logger.debug('RemoveSrv4(), %s %s' % (sqo_srv4, catspec))
     sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad(
         osrel, arch, catrel)
     try:
@@ -1229,8 +1236,10 @@
             m.Srv4FileInCatalog.q.osrel==sqo_osrel,
             m.Srv4FileInCatalog.q.catrel==sqo_catrel,
             m.Srv4FileInCatalog.q.srv4file==sqo_srv4)).getOne()
+      self.logger.debug('Package %s should be now gone from %s.' % (sqo_srv4, catspec))
       # Files belonging to this package should not be removed from the catalog
       # as the package might be still present in another catalog.
       sqo_srv4_in_cat.destroySelf()
     except sqlobject.main.SQLObjectNotFound as e:
-      logging.warning(e)
+      self.logger.debug('The object went away when we were trying to delete it.')
+      self.logger.warning(e)

Modified: csw/mgar/gar/v2/lib/python/models.py
===================================================================
--- csw/mgar/gar/v2/lib/python/models.py	2014-05-19 22:21:33 UTC (rev 23662)
+++ csw/mgar/gar/v2/lib/python/models.py	2014-05-19 22:21:43 UTC (rev 23663)
@@ -10,6 +10,7 @@
 import sqlobject
 from sqlobject import sqlbuilder
 
+logger = logging.getLogger('opencsw.models')
 
 def SanitizeDatetime(d):
   if isinstance(d, datetime.datetime):
@@ -243,6 +244,12 @@
   def __init__(self, *args, **kwargs):
     super(Srv4FileStats, self).__init__(*args, **kwargs)
 
+  def __unicode__(self):
+    return u'%s/%s, %s' % (self.pkginst.pkgname, self.catalogname, self.md5_sum)
+
+  def __str__(self):
+    return str(unicode(self))
+
   def DeleteAllDependentObjects(self):
     self.RemoveCatalogAssignments()
     self.RemoveAllCswFiles()
@@ -292,7 +299,7 @@
             CheckpkgErrorTag.q.catrel==catrel))
 
   def RemoveCheckpkgResults(self, os_rel, arch, catrel):
-    logging.debug("%s: RemoveCheckpkgResults(%s, %s, %s)",
+    logger.debug("%s: RemoveCheckpkgResults(%s, %s, %s)",
                   self, os_rel, arch, catrel)
     sqlobject.sqlhub.processConnection.query(
         sqlobject.sqlhub.processConnection.sqlrepr(sqlbuilder.Delete(
@@ -304,22 +311,19 @@
             CheckpkgErrorTag.q.catrel==catrel))))
 
   def RemoveAllCheckpkgResults(self):
-    logging.debug("%s: RemoveAllCheckpkgResults()", self)
+    logger.debug("%s: RemoveAllCheckpkgResults()", self)
     sqlobject.sqlhub.processConnection.query(
         sqlobject.sqlhub.processConnection.sqlrepr(sqlbuilder.Delete(
           CheckpkgErrorTag.sqlmeta.table,
           CheckpkgErrorTag.q.srv4_file==self)))
 
   def RemoveOverrides(self):
-    logging.debug("%s: RemoveOverrides()", self)
+    logger.debug("%s: RemoveOverrides()", self)
     sqlobject.sqlhub.processConnection.query(
         sqlobject.sqlhub.processConnection.sqlrepr(sqlbuilder.Delete(
           CheckpkgOverride.sqlmeta.table,
           CheckpkgOverride.q.srv4_file==self)))
 
-  def __unicode__(self):
-    return (u"%s" % (self.basename))
-
   def GetUnicodeOrNone(self, s):
     """Tries to decode UTF-8.
 

Modified: csw/mgar/gar/v2/lib/python/relational_util.py
===================================================================
--- csw/mgar/gar/v2/lib/python/relational_util.py	2014-05-19 22:21:33 UTC (rev 23662)
+++ csw/mgar/gar/v2/lib/python/relational_util.py	2014-05-19 22:21:43 UTC (rev 23663)
@@ -28,13 +28,14 @@
 
 
 PACKAGE_STATS_VERSION = 13L
+logger = logging.getLogger('opencsw.relationalutil')
 
 
 def GetOrSetPkginst(pkgname):
   try:
     pkginst = models.Pkginst.selectBy(pkgname=pkgname).getOne()
   except sqlobject.main.SQLObjectNotFound as exc:
-    logging.debug('pkginst %s not found (%r), making a new one'
+    logger.debug('pkginst %s not found (%r), making a new one'
                   % (pkgname, exc))
     pkginst = models.Pkginst(pkgname=pkgname)
   return pkginst
@@ -72,7 +73,7 @@
     msg = ('%r is not a valid OS release name. Look into %s metadata. '
            'Probably a problem with the file name: %r'
            % (os_rel_name, md5_sum, pkg_stats["basic_stats"]["pkg_basename"]))
-    logging.warning(msg)
+    logger.warning(msg)
     # This is probably a package with a file name like
     # 'mod_dav-1.0.3-sparc-CSW.pkg.gz'. We have to deal with it somehow,
     # so we'll assume it's a Solaris 8 package.
@@ -82,7 +83,7 @@
   try:
     maintainer = models.Maintainer.selectBy(email=maint_email).getOne()
   except sqlobject.main.SQLObjectNotFound as exc:
-    logging.debug(exc)
+    logger.debug(exc)
     # Try to get the maintainer name.
     maint_name = None
     vendor_str = pkg_stats["pkginfo"]["VENDOR"]
@@ -102,8 +103,8 @@
     db_pkg_stats = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
     db_pkg_stats.DeleteAllDependentObjects()
   except sqlobject.main.SQLObjectNotFound:
-    logging.debug('Package %s present in the rel db, proceeding with insert.',
-                  parsed_basename)
+    logger.debug('Package %s not present in the relational db, '
+                 'proceeding with insert.', parsed_basename)
 
   register = True
   bundle = pkg_stats['pkginfo'].get("OPENCSW_BUNDLE", None)

Modified: csw/mgar/gar/v2/lib/web/releases_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/releases_web.py	2014-05-19 22:21:33 UTC (rev 23662)
+++ csw/mgar/gar/v2/lib/web/releases_web.py	2014-05-19 22:21:43 UTC (rev 23663)
@@ -62,6 +62,17 @@
 ])
 
 
+applogger = logging.getLogger('opencsw')
+applogger.setLevel(logging.DEBUG)
+log_handler = logging.FileHandler(filename=LOG_FILE_TMPL)
+log_handler.setLevel(logging.DEBUG)
+log_formatter = logging.Formatter(
+    '%(process)d %(levelname)s %(asctime)s '
+    '%(filename)s:%(lineno)d %(funcName)s: %(message)s')
+log_handler.setFormatter(log_formatter)
+applogger.addHandler(log_handler)
+
+
 class Index(object):
 
   def GET(self):
@@ -526,16 +537,6 @@
 
 # web.webapi.internalerror = web.debugerror
 
-applogger = logging.getLogger('releases-web')
-applogger.setLevel(logging.DEBUG)
-log_handler = logging.FileHandler(filename=LOG_FILE_TMPL)
-log_handler.setLevel(logging.DEBUG)
-log_formatter = logging.Formatter(
-    '%(process)d %(levelname)s %(asctime)s '
-    '%(filename)s:%(lineno)d %(funcName)s: %(message)s')
-log_handler.setFormatter(log_formatter)
-applogger.addHandler(log_handler)
-
 app = web.application(urls, globals())
 
 def app_wrapper(app):

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