[csw-devel] SF.net SVN: gar:[20225] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Jan 27 17:51:02 CET 2013


Revision: 20225
          http://gar.svn.sourceforge.net/gar/?rev=20225&view=rev
Author:   wahwah
Date:     2013-01-27 16:48:36 +0000 (Sun, 27 Jan 2013)
Log Message:
-----------
checkpkg: Various cleanup

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg2.py
    csw/mgar/gar/v2/lib/python/inspective_package.py
    csw/mgar/gar/v2/lib/python/models.py
    csw/mgar/gar/v2/lib/python/package.py
    csw/mgar/gar/v2/lib/python/package_stats.py
    csw/mgar/gar/v2/lib/python/pkgdb.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg2.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg2.py	2013-01-27 16:05:22 UTC (rev 20224)
+++ csw/mgar/gar/v2/lib/python/checkpkg2.py	2013-01-27 16:48:36 UTC (rev 20225)
@@ -134,7 +134,7 @@
   tags_for_all_osrels = []
   try:
     sqo_catrel = models.CatalogRelease.selectBy(name=options.catrel).getOne()
-  except sqlobject.main.SQLObjectNotFound, e:
+  except sqlobject.main.SQLObjectNotFound as e:
     logging.fatal("Fetching from the db has failed: catrel=%s",
                   repr(str(options.catrel)))
     logging.fatal("Available catalog releases:")
@@ -173,7 +173,7 @@
     tags_for_all_osrels.extend(tags_after_overrides)
     if not options.quiet:
       if tags_after_overrides:
-        print textwrap.fill(BEFORE_OVERRIDES, 80)
+        print(textwrap.fill(BEFORE_OVERRIDES, 80))
         for checkpkg_tag in tags_after_overrides:
           print checkpkg_tag.ToGarSyntax()
         print textwrap.fill(AFTER_OVERRIDES, 80)

Modified: csw/mgar/gar/v2/lib/python/inspective_package.py
===================================================================
--- csw/mgar/gar/v2/lib/python/inspective_package.py	2013-01-27 16:05:22 UTC (rev 20224)
+++ csw/mgar/gar/v2/lib/python/inspective_package.py	2013-01-27 16:48:36 UTC (rev 20225)
@@ -724,10 +724,11 @@
     """Trying to run magic.file() a few times, not accepting None."""
     self._LazyInit()
     mime = None
+    logging.debug("GetFileMimeType(%r)", full_path)
     for i in xrange(10):
       mime = self.magic_cookie.file(full_path)
       if mime:
-        break;
+        break
       else:
         # Returned mime is null. Re-initializing the cookie and trying again.
         logging.error("magic_cookie.file(%s) returned None. Retrying.",

Modified: csw/mgar/gar/v2/lib/python/models.py
===================================================================
--- csw/mgar/gar/v2/lib/python/models.py	2013-01-27 16:05:22 UTC (rev 20224)
+++ csw/mgar/gar/v2/lib/python/models.py	2013-01-27 16:48:36 UTC (rev 20225)
@@ -229,7 +229,13 @@
         % (self.catalogname, self.version_string, self.arch.name))
 
   def GetUnicodeOrNone(self, s):
-    """Tries to decode UTF-8"""
+    """Tries to decode UTF-8.
+
+    If the object does not decode as UTF-8, it's forced to do so, while
+    ignoring any potential errors.
+
+    Returns: a unicode object or a None type.
+    """
     if s is None:
       return None
     if type(s) != unicode:

Modified: csw/mgar/gar/v2/lib/python/package.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package.py	2013-01-27 16:05:22 UTC (rev 20224)
+++ csw/mgar/gar/v2/lib/python/package.py	2013-01-27 16:48:36 UTC (rev 20225)
@@ -71,9 +71,8 @@
   def GetWorkDir(self):
     if not self.workdir:
       self.workdir = tempfile.mkdtemp(prefix="pkg_", dir="/var/tmp")
-      fd = open(os.path.join(self.workdir, "admin"), "w")
-      fd.write(ADMIN_FILE_CONTENT)
-      fd.close()
+      with open(os.path.join(self.workdir, "admin"), "w") as fd:
+        fd.write(ADMIN_FILE_CONTENT)
     return self.workdir
 
   def GetAdminFilePath(self):
@@ -137,6 +136,10 @@
     return self.stat
 
   def GetMtime(self):
+    """The mtime of the svr4 file.
+
+    Returns: a datetime.datetime object (not encodable with json!).
+    """
     if not self.mtime:
       s = self._Stat()
       t = time.gmtime(s.st_mtime)
@@ -144,8 +147,7 @@
     return self.mtime
 
   def GetSize(self):
-    s = self._Stat()
-    return s.st_size
+    return self._Stat().st_size
 
   def TransformToDir(self):
     """Transforms the file to the directory format.
@@ -465,7 +467,6 @@
     if not self.dir_pkg:
       self.dir_pkg = self.srv4.GetDirFormatPkg()
       logging.debug(repr(self.dir_pkg))
-      # subprocess.call(["tree", self.dir_pkg.directory])
 
   def Export(self, dest_dir):
     self.Transform()

Modified: csw/mgar/gar/v2/lib/python/package_stats.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_stats.py	2013-01-27 16:05:22 UTC (rev 20224)
+++ csw/mgar/gar/v2/lib/python/package_stats.py	2013-01-27 16:48:36 UTC (rev 20225)
@@ -36,19 +36,19 @@
 
 
 class Error(Exception):
-  pass
+  """Generic error."""
 
 
 class PackageError(Error):
-  pass
+  """Problem with the package file examined."""
 
 
 class DatabaseError(Error):
-  pass
+  """Problem with the database contents or schema."""
 
 
 class StdoutSyntaxError(Error):
-  pass
+  """A utility's output is bad, e.g. impossible to parse."""
 
 
 class PackageStatsMixin(object):
@@ -122,6 +122,10 @@
     return self.dir_format_pkg
 
   def GetMtime(self):
+    """Get svr4 file mtime value.
+
+    Returns: a datetime.datetime object.
+    """
     return self.srv4_pkg.GetMtime()
 
   def GetSize(self):
@@ -213,7 +217,8 @@
         "binaries_elf_info": dir_pkg.GetBinaryElfInfo(),
     }
     self.SaveStats(pkg_stats)
-    logging.debug("Statistics of %s have been collected.", repr(dir_pkg.pkgname))
+    logging.debug("Statistics of %s have been collected and saved in the db.",
+                  repr(dir_pkg.pkgname))
     return pkg_stats
 
   @classmethod
@@ -231,6 +236,7 @@
 
     Does not require an instance.
     """
+    logging.debug("SaveStats()")
     pkgname = pkg_stats["basic_stats"]["pkgname"]
     # Getting sqlobject representations.
     pkginst = cls.GetOrSetPkginst(pkgname)
@@ -371,11 +377,11 @@
         line_u = pkgmap_entry["line"].decode("utf-8")
         f_path, basename = os.path.split(
             pkgmap_entry["path"].decode('utf-8'))
-      except UnicodeDecodeError, e:
+      except UnicodeDecodeError as e:
         line_u = pkgmap_entry["line"].decode("latin1")
         f_path, basename = os.path.split(
             pkgmap_entry["path"].decode('latin1'))
-      except UnicodeEncodeError, e:
+      except UnicodeEncodeError as e:
         # the line was already in unicode
         line_u = pkgmap_entry['line']
         f_path, basename = os.path.split(pkgmap_entry["path"])
@@ -447,9 +453,11 @@
 
 
 def StatsListFromCatalog(file_name_list, catalog_file_name=None, debug=False):
-  packages = [inspective_package.InspectiveCswSrv4File(x, debug) for x in file_name_list]
+  packages = [inspective_package.InspectiveCswSrv4File(x, debug)
+              for x in file_name_list]
   if catalog_file_name:
-    catalog_obj = catalog.OpencswCatalog(open(catalog_file_name, "rb"))
+    with open(catalog_file_name, "rb") as fd:
+      catalog_obj = catalog.OpencswCatalog(fd)
     md5s_by_basename = catalog_obj.GetDataByBasename()
     for pkg in packages:
       basename = os.path.basename(pkg.pkg_path)
@@ -472,6 +480,7 @@
     self.debug = debug
 
   def CollectStatsFromFiles(self, file_list, catalog_file, force_unpack=False):
+    """Returns: A list of md5 sums of collected statistics."""
     args_display = file_list
     if len(args_display) > 5:
       args_display = args_display[:5] + ["...more..."]

Modified: csw/mgar/gar/v2/lib/python/pkgdb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkgdb.py	2013-01-27 16:05:22 UTC (rev 20224)
+++ csw/mgar/gar/v2/lib/python/pkgdb.py	2013-01-27 16:48:36 UTC (rev 20225)
@@ -215,7 +215,6 @@
       cat_entry_by_md5[catalog_entry["md5sum"]] = catalog_entry
       cat_entry_by_basename[catalog_entry["file_basename"]] = catalog_entry
     # - import all srv4 files that were not in the database so far
-    sqo_objects = set()
     entries_to_import = []
     logging.debug("Checking which srv4 files are already in the db.")
     for md5 in cat_entry_by_md5:
@@ -335,11 +334,11 @@
       sqo_osrel = m.OsRelease.selectBy(short_name=osrel).getOne()
       for arch in common_constants.PHYSICAL_ARCHITECTURES:
         if current_host_arch != arch:
-        	logging.warning(
-        	    "Cannot process packages for achitecture %r "
-        	    "because we're currently running on architecture %r.",
-        	    arch, current_host_arch)
-        	continue
+          logging.warning(
+              "Cannot process packages for achitecture %r "
+              "because we're currently running on architecture %r.",
+              arch, current_host_arch)
+          continue
         logging.info("    Architecture: %s", repr(arch))
         sqo_arch = m.Architecture.selectBy(name=arch).getOne()
         catalog_file = self.ComposeCatalogFilePath(base_dir, osrel, arch)

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