Mercurial > treepkg > treepkg
comparison 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 |
comparison
equal
deleted
inserted
replaced
460:10d4cbffcc07 | 461:454967511f5c |
---|---|
12 import tempfile | 12 import tempfile |
13 import shutil | 13 import shutil |
14 import fnmatch | 14 import fnmatch |
15 import pwd | 15 import pwd |
16 import os.path | 16 import os.path |
17 | |
17 try: | 18 try: |
18 from hashlib import md5 as new_md5 | 19 from hashlib import md5 as new_md5 |
19 except ImportError: | 20 except ImportError: |
20 # fall back to md5 for Python versions before 2.5 | 21 # fall back to md5 for Python versions before 2.5 |
21 from md5 import new as new_md5 | 22 from md5 import new as new_md5 |
23 | |
22 import run | 24 import run |
25 from cmdexpand import cmdexpand | |
23 | 26 |
24 | 27 |
25 def import_dotted_name(dotted_name): | 28 def import_dotted_name(dotted_name): |
26 module = __import__(dotted_name) | 29 module = __import__(dotted_name) |
27 for name in dotted_name.split(".")[1:]: | 30 for name in dotted_name.split(".")[1:]: |
185 Applies os.path.expanduser and os.path.expandvars to filename | 188 Applies os.path.expanduser and os.path.expandvars to filename |
186 """ | 189 """ |
187 return os.path.expandvars(os.path.expanduser(filename)) | 190 return os.path.expandvars(os.path.expanduser(filename)) |
188 | 191 |
189 | 192 |
193 def compress_all_logs(reference_log, cmd="gzip -9 $logfile"): | |
194 """ | |
195 Takes the path of a reference log file and compresses all | |
196 files in same folder with the cmd command. | |
197 """ | |
198 if reference_log and os.path.exists(reference_log): | |
199 log_dir = os.path.dirname(reference_log) | |
200 for log_file in [os.path.join(log_dir, f) | |
201 for f in os.listdir(log_dir)]: | |
202 if os.path.isfile(log_file): | |
203 run.call(cmdexpand(cmd, logfile=log_file)) |