diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-05-29 11:34:06 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-05-29 11:34:42 +0200 |
commit | abd8e47f48de60a9ef07a5629e09dad5fb6945f5 (patch) | |
tree | 1ffcaa38a6a1daa66121ad4790c71b290ac44ae7 /bin | |
parent | bcf16599846f4fbce3b603231888b1aeb3aa3519 (diff) | |
download | tools-abd8e47f48de60a9ef07a5629e09dad5fb6945f5.tar.gz tools-abd8e47f48de60a9ef07a5629e09dad5fb6945f5.tar.bz2 tools-abd8e47f48de60a9ef07a5629e09dad5fb6945f5.zip |
Printer: refactoring the whole thing for better pylint result0.1.9
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/hostinfo | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/bin/hostinfo b/bin/hostinfo index 7fb1e9b..d24fdaf 100755 --- a/bin/hostinfo +++ b/bin/hostinfo @@ -19,9 +19,9 @@ def _get_data(path): stream = file(path, 'r') return yaml.load(stream) -def print_info(path, key=None, oneline=False, verbose=False, nospaces=False): +def print_info(path, key=None, flags=list()): data = _get_data(path) - p = printer.Printer(data, oneline, verbose, nospaces) + p = printer.Printer(data, flags) p.info(key) def print_keys(path): @@ -92,8 +92,8 @@ def main(): if 'HOSTINFO_PATH' in os.environ and os.environ['HOSTINFO_PATH'] != '': basepath = os.environ['HOSTINFO_PATH'] - file = oneline = keys = verbose = nospaces = help = \ - hosts = short = False + file = keys = help = hosts = short = False + flags = list() try: optlist, args = getopt.gnu_getopt(sys.argv, 'ofkvnh?p:ls', ['oneline', 'file', 'keys', 'verbose', @@ -104,14 +104,18 @@ def main(): opts[key] = value file = any([o in opts for o in ['--file', '-f']]) - oneline = any([o in opts for o in ['--oneline', '-o']]) keys = any([o in opts for o in ['--keys', '-k']]) - verbose = any([o in opts for o in ['--verbose', '-v']]) - nospaces = any([o in opts for o in ['--nospaces', '-n']]) help = any([o in opts for o in ['--help', '-h', '-?']]) hosts = any([o in opts for o in ['--hosts', '-l']]) short = any([o in opts for o in ['--short', '-s']]) + if any([o in opts for o in ['--verbose', '-v']]): + flags.append('verbose') + if any([o in opts for o in ['--oneline', '-o']]): + flags.append('oneline') + if any([o in opts for o in ['--nospaces', '-n']]): + flags.append('nospaces') + if any([o in opts for o in ['--path', '-p']]): basepath = [opts[o] for o in ['--path', '-p'] if o in opts][0] except getopt.GetoptError, e: @@ -143,7 +147,7 @@ def main(): if len(args) > 1: key = args[1] - print_info(path, key=key, oneline=oneline, verbose=verbose, nospaces=nospaces) + print_info(path, key=key, flags=flags) sys.exit(0) if __name__ == '__main__': |