[Treepkg-commits] r421 - in trunk: test treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 30 15:32:33 CEST 2010


Author: bricks
Date: 2010-08-30 15:32:31 +0200 (Mon, 30 Aug 2010)
New Revision: 421

Modified:
   trunk/test/test_util.py
   trunk/treepkg/builder.py
   trunk/treepkg/sbuilder.py
   trunk/treepkg/util.py
Log:
commit compress all logs patch from Sascha Teichmann


Modified: trunk/test/test_util.py
===================================================================
--- trunk/test/test_util.py	2010-08-27 09:50:04 UTC (rev 420)
+++ trunk/test/test_util.py	2010-08-30 13:32:31 UTC (rev 421)
@@ -9,14 +9,15 @@
 
 import os
 import unittest
+import shutil
 
 from filesupport import FileTestMixin
 
 from treepkg.util import replace_in_file, listdir_abs, md5sum, \
-                         remove_trailing_slashes, expand_filename
+                         remove_trailing_slashes, expand_filename, \
+                         compress_all_logs
 
 
-
 class TestReplaceInFile(unittest.TestCase, FileTestMixin):
 
     def runtest(self, orig_contents, expected_contents, pattern, replacement):
@@ -102,3 +103,19 @@
 
         self.assertEquals("/abc/def/", expand_filename(path))
 
+class TestCompressAllLogs(unittest.TestCase, FileTestMixin):
+
+    def test_compress_all_logs(self):
+        log_dir = self.create_test_specific_temp_dir()
+        try:
+            for i in range(15):
+                f = open(os.path.join(log_dir, "log_%d.txt" % i), "w")
+                print >> f, "World domination is right at hand!"
+                f.close()
+            ref_log = os.path.join(log_dir, "log_0.txt")
+            compress_all_logs(ref_log)
+            for i in range(15):
+                self.assertTrue(os.path.isfile(os.path.join(
+                                               log_dir, "log_%d.txt.gz" % i)))
+        finally:
+            shutil.rmtree(log_dir, ignore_errors=True)

Modified: trunk/treepkg/builder.py
===================================================================
--- trunk/treepkg/builder.py	2010-08-27 09:50:04 UTC (rev 420)
+++ trunk/treepkg/builder.py	2010-08-30 13:32:31 UTC (rev 421)
@@ -215,15 +215,11 @@
                      suppress_output=True,
                      extra_env=extra_env)
         except:
-            if logfile is not None and os.path.exists(logfile):
-                run.call(cmdexpand("gzip -9 $logfile", logfile=logfile))
+            util.compress_all_logs(logfile)
             raise
-        else:
-            if logfile is not None and os.path.exists(logfile):
-                run.call(cmdexpand("gzip -9 $logfile", logfile=logfile))
+
+        util.compress_all_logs(logfile)
  
-        if logfile is not None and os.path.exists(logfile):
-            run.call(cmdexpand("gzip -9 $logfile", logfile=logfile))
         # remove the source package files put into the binary directory
         # by pbuilder
         if binary_dir is not None:

Modified: trunk/treepkg/sbuilder.py
===================================================================
--- trunk/treepkg/sbuilder.py	2010-08-27 09:50:04 UTC (rev 420)
+++ trunk/treepkg/sbuilder.py	2010-08-30 13:32:31 UTC (rev 421)
@@ -139,9 +139,8 @@
                     if os.path.splitext(filename)[1] not in (".deb", ".changes"):
                         os.remove(os.path.join(binary_dir, filename))
         finally:
-            # compress logfile
-            if logfile is not None and os.path.exists(logfile):
-                run.call(cmdexpand("gzip -9 $logfile", logfile=logfile))
+            # compress logfiles
+            util.compress_all_logs(logfile)
             # remove all mounted directories
             self.umount_all()
 
@@ -185,6 +184,8 @@
         try:
             run.call(cmd, suppress_output=False)
         finally:
+            if logfile is not None:
+                logdir = os.path.dirname(logfile)
             self.umount_all()
 
     def login(self, bindmounts=(), save_after_login=False):

Modified: trunk/treepkg/util.py
===================================================================
--- trunk/treepkg/util.py	2010-08-27 09:50:04 UTC (rev 420)
+++ trunk/treepkg/util.py	2010-08-30 13:32:31 UTC (rev 421)
@@ -14,12 +14,15 @@
 import fnmatch
 import pwd
 import os.path
+
 try:
     from hashlib import md5 as new_md5
 except ImportError:
     # fall back to md5 for Python versions before 2.5
     from md5 import new as new_md5
+
 import run
+from cmdexpand import cmdexpand
 
 
 def import_dotted_name(dotted_name):
@@ -187,3 +190,14 @@
     return os.path.expandvars(os.path.expanduser(filename))
 
 
+def compress_all_logs(reference_log, cmd="gzip -9 $logfile"):
+    """
+    Takes the path of a reference log file and compresses all
+    files in same folder with the cmd command.
+    """
+    if reference_log and os.path.exists(reference_log):
+        log_dir = os.path.dirname(reference_log)
+        for log_file in [os.path.join(log_dir, f) 
+                         for f in os.listdir(log_dir)]:
+            if os.path.isfile(log_file):
+                run.call(cmdexpand(cmd, logfile=log_file))



More information about the Treepkg-commits mailing list