changeset 461:454967511f5c

commit compress all logs patch from Sascha Teichmann
author Bjoern Ricks <bricks@intevation.de>
date Mon, 30 Aug 2010 13:32:31 +0000
parents 10d4cbffcc07
children 058856954e2d
files test/test_util.py treepkg/builder.py treepkg/sbuilder.py treepkg/util.py
diffstat 4 files changed, 40 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/test/test_util.py	Fri Aug 27 09:50:04 2010 +0000
+++ b/test/test_util.py	Mon Aug 30 13:32:31 2010 +0000
@@ -9,12 +9,13 @@
 
 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):
@@ -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)
--- a/treepkg/builder.py	Fri Aug 27 09:50:04 2010 +0000
+++ b/treepkg/builder.py	Mon Aug 30 13:32:31 2010 +0000
@@ -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:
--- a/treepkg/sbuilder.py	Fri Aug 27 09:50:04 2010 +0000
+++ b/treepkg/sbuilder.py	Mon Aug 30 13:32:31 2010 +0000
@@ -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):
--- a/treepkg/util.py	Fri Aug 27 09:50:04 2010 +0000
+++ b/treepkg/util.py	Mon Aug 30 13:32:31 2010 +0000
@@ -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))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)