Mercurial > treepkg > treepkg
diff treepkg/util.py @ 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 | 61e72399914c |
children | 058856954e2d |
line wrap: on
line diff
--- 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))