diff options
| author | 2009-07-24 12:51:31 +0200 | |
|---|---|---|
| committer | 2009-07-24 12:51:31 +0200 | |
| commit | 039b7334e510ea2ee02847b73746cba214b89c7b (patch) | |
| tree | 391d1a4621cef8ef80cafef7e87bcce4d14584db | |
| parent | 67deff45f6d3c198aa482c5f15daa7bf155f347b (diff) | |
add generic do_and_log function
to reduce code duplication in other do_ functions
| -rwxr-xr-x | mini-dinstall | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/mini-dinstall b/mini-dinstall index 63a5471..6261934 100755 --- a/mini-dinstall +++ b/mini-dinstall @@ -156,31 +156,24 @@ for key, val in opts: elif key in ('-k', '--kill'): kill_mode = 1 -def do_mkdir(name): - if os.access(name, os.X_OK): - return +def do_and_log(msg, function, *args): try: - logger.info('Creating directory "%s"' % (name)) + logger.debug(msg) except: pass if not no_act: - os.mkdir(name) + function(*args) + +def do_mkdir(name): + if os.access(name, os.X_OK): + return + do_and_log('Creating directory "%s"' % (name), os.mkdir, name) def do_rename(source, target): - try: - logger.debug('Renaming "%s" to "%s"' % (source, target)) - except: - pass - if not no_act: - os.rename(source, target) + do_and_log('Renaming "%s" to "%s"' % (source, target), os.rename, source, target) def do_chmod(name, mode): - try: - logger.info('Changing mode of "%s" to %o' % (name, mode)) - except: - pass - if not no_act: - os.chmod(name, mode) + do_and_log('Changing mode of "%s" to %o' % (name, mode), os.chmod, name, mode) logger.setLevel(logging.DEBUG) stderr_handler = logging.StreamHandler(strm=sys.stderr) |
