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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Wed Feb 17 12:14:39 CET 2010


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

Log Message:
-----------
mGAR v2-checkpkg-stats: cPickle serialization is much faster than yaml

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

Modified: csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py	2010-02-17 10:00:50 UTC (rev 8614)
+++ csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py	2010-02-17 11:14:39 UTC (rev 8615)
@@ -4,6 +4,7 @@
 # Python.
 
 import copy
+import cPickle
 import errno
 import itertools
 import logging
@@ -894,6 +895,7 @@
     stats_path = self.GetStatsPath()
     self.MakeStatsDir()
     dir_pkg = self.GetDirFormatPkg()
+    logging.info("Collecting package statistics.")
     self.DumpObject(dir_pkg.GetAllFilenames(), "all_filenames")
     self.DumpObject(self.GetBasicStats(), "basic_stats")
     self.DumpObject(dir_pkg.ListBinaries(), "binaries")
@@ -904,31 +906,51 @@
     self.DumpObject(dir_pkg.GetParsedPkginfo(), "pkginfo")
     self.DumpObject(dir_pkg.GetPkgmap().entries, "pkgmap")
     self.DumpObject(self.GetLddMinusRlines(), "ldd_dash_r")
+    logging.debug("Statistics collected.")
 
+  def GetAllStats(self):
+    if self.StatsExist():
+      self.all_stats = self.ReadSavedStats()
+    else:
+      self.CollectStats()
+    return self.all_stats
+
   def DumpObject(self, obj, name):
+    """Saves an object.
+
+    TODO(maciej): Implement pickling with cPickle.
+    """
     stats_path = self.GetStatsPath()
+    # yaml
     out_file_name = os.path.join(stats_path, "%s.yml" % name)
     logging.debug("DumpObject(): writing %s", repr(out_file_name))
     f = open(out_file_name, "w")
     f.write(yaml.safe_dump(obj))
     f.close()
+    # pickle
+    out_file_name_pickle = os.path.join(stats_path, "%s.pickle" % name)
+    f = open(out_file_name_pickle, "wb")
+    cPickle.dump(obj, f)
+    f.close()
     self.all_stats[name] = obj
 
-  def GetAllStats(self):
-    if self.StatsExist():
-      self.all_stats = self.ReadSavedStats()
-    else:
-      self.CollectStats()
-    return self.all_stats
-
   def ReadObject(self, name):
+    """Reads an object."""
     stats_path = self.GetStatsPath()
     in_file_name = os.path.join(stats_path, "%s.yml" % name)
-    logging.debug("ReadObject(): reading %s", repr(in_file_name))
-    f = open(in_file_name, "r")
-    obj = yaml.safe_load(f)
-    f.close()
-    logging.debug("ReadObject(): finished reading %s", repr(in_file_name))
+    in_file_name_pickle = os.path.join(stats_path, "%s.pickle" % name)
+    if os.path.exists(in_file_name_pickle):
+      logging.debug("ReadObject(): reading %s", repr(in_file_name_pickle))
+      f = open(in_file_name_pickle, "r")
+      obj = cPickle.load(f)
+      f.close()
+      logging.debug("ReadObject(): finished reading %s", repr(in_file_name_pickle))
+    else:
+      logging.debug("ReadObject(): reading %s", repr(in_file_name))
+      f = open(in_file_name, "r")
+      obj = yaml.safe_load(f)
+      f.close()
+      logging.debug("ReadObject(): finished reading %s", repr(in_file_name))
     return obj
 
   def ReadSavedStats(self):

Modified: csw/mgar/gar/v2-checkpkg-stats/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/lib/python/opencsw.py	2010-02-17 10:00:50 UTC (rev 8614)
+++ csw/mgar/gar/v2-checkpkg-stats/lib/python/opencsw.py	2010-02-17 11:14:39 UTC (rev 8615)
@@ -440,7 +440,7 @@
       args = [os.path.join(os.path.dirname(__file__),
                            "..", "..", "bin", "custom-pkgtrans"),
               gunzipped_path, self.GetWorkDir(), pkgname]
-      print "transforming", args
+      logging.info("transforming: %s", args)
       unused_retcode = self.ShellCommand(args, quiet=(not self.debug))
       dirs = self.GetDirs()
       if len(dirs) != 1:


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