From aed0238ba4b3cb74fcdf92336222600ebb169f38 Mon Sep 17 00:00:00 2001 From: Tomasz Buchert Date: Sat, 29 Aug 2015 23:02:16 +0200 Subject: [PATCH] another step --- debocker | 27 ++------------------------- src/debocker/log.py | 17 +++++++++++++++++ src/debocker/utils.py | 15 +++++++++++++-- 3 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 src/debocker/log.py diff --git a/debocker b/debocker index f93d40c..8544960 100755 --- a/debocker +++ b/debocker @@ -18,34 +18,11 @@ HERE = realpath(dirname(__file__)) sys.path.append(join(HERE, 'src')) from debocker.utils import cached_constant, cached_property, tmppath, \ - calculate_md5_and_size + calculate_md5_and_size, log_check_call, log_check_output +from debocker.log import log, LOW, fail __version__ = "0.2" -NONE, LOW = 0, 1 -VERBOSITY = NONE - -# USEFUL ROUTINES - -def fail(msg, *params): - raise click.ClickException(msg.format(*params)) - -def log(msg, v = 0): - if VERBOSITY == NONE: - if v == 0: - click.secho('LOG {}'.format(msg), fg = 'green') - else: - if v <= VERBOSITY: - click.secho('LOG[{}] {}'.format(v, msg), fg = 'green') - -def log_check_call(cmd, **kwds): - log('Run (check): {}'.format(cmd), LOW) - return check_call(cmd, **kwds) - -def log_check_output(cmd, **kwds): - log('Run (output): {}'.format(cmd), LOW) - return check_output(cmd, **kwds) - @cached_constant def find_bundle_files(): '''finds the location of bundle files''' diff --git a/src/debocker/log.py b/src/debocker/log.py new file mode 100644 index 0000000..aa18ba9 --- /dev/null +++ b/src/debocker/log.py @@ -0,0 +1,17 @@ +# logging (using click) + +import click + +NONE, LOW = 0, 1 +VERBOSITY = NONE + +def fail(msg, *params): + raise click.ClickException(msg.format(*params)) + +def log(msg, v = 0): + if VERBOSITY == NONE: + if v == 0: + click.secho('LOG {}'.format(msg), fg = 'green') + else: + if v <= VERBOSITY: + click.secho('LOG[{}] {}'.format(v, msg), fg = 'green') diff --git a/src/debocker/utils.py b/src/debocker/utils.py index a030976..76c1215 100644 --- a/src/debocker/utils.py +++ b/src/debocker/utils.py @@ -1,10 +1,13 @@ # utilities +import os +import hashlib from tempfile import TemporaryDirectory from datetime import datetime from os.path import join -import os -import hashlib +from subprocess import check_call, check_output + +from .log import log, LOW def cached_constant(f): cache = [] @@ -55,3 +58,11 @@ def calculate_md5_and_size(path): count += len(buff) md5.update(buff) return md5.hexdigest(), count + +def log_check_call(cmd, **kwds): + log('Run (check): {}'.format(cmd), LOW) + return check_call(cmd, **kwds) + +def log_check_output(cmd, **kwds): + log('Run (output): {}'.format(cmd), LOW) + return check_output(cmd, **kwds) -- 2.20.1