From d7addebc1bf8c5be1af8f001d0f8286176ae111a Mon Sep 17 00:00:00 2001 From: Mario Hock Date: Thu, 21 Aug 2014 14:53:52 +0200 Subject: [PATCH] cnl_ls: --environment --- cnl_library.py | 3 +++ cnlls.py | 9 ++++----- summary.py | 22 +++++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cnl_library.py b/cnl_library.py index 1427e21..d365460 100755 --- a/cnl_library.py +++ b/cnl_library.py @@ -216,6 +216,9 @@ class CNLParser: def get_hostname(self): return self.get_sysinfo()["hostname"] + def get_environment(self): + return self.header["General"]["Environment"] + ## MAIN ## diff --git a/cnlls.py b/cnlls.py index 89b157c..1e639c2 100755 --- a/cnlls.py +++ b/cnlls.py @@ -77,14 +77,14 @@ def show_summary(left_file, right_file=None): ## BRANCH: No match -> fallback to show_brief() if ( not right_file ): log = LogAnalyzer(left_file) - log.visualize_brief() + log.visualize_brief(args.environment) ## BRANCH: Match -> Display both next to each other. else: log_left = LogAnalyzer(left_file) log_right = LogAnalyzer(right_file) - show_match(log_left, log_right) + show_match(log_left, log_right, args.environment) def show(left_file, right_file, long=False, summary=False): @@ -107,9 +107,8 @@ if __name__ == "__main__": parser.add_argument("files", nargs='*') parser.add_argument("-l", "--long", action="store_true") parser.add_argument("-s", "--summary", action="store_true") - - ## TODO -e, --environment - # Specify which env-fields should be added to the comment + parser.add_argument("-e", "--environment", action='append', metavar="ENV", + help="Environment variable that should be displayed. (May be set multiple times.)") args = parser.parse_args() diff --git a/summary.py b/summary.py index c263f1b..0b0e35b 100755 --- a/summary.py +++ b/summary.py @@ -5,7 +5,7 @@ import time import os from itertools import zip_longest -from cnl_library import CNLParser +from cnl_library import CNLParser, pretty_json from split_text import split_proprtionally ## some "constants"/preferences @@ -35,7 +35,7 @@ def print_in_two_columns(format_str, left_col, right_col): -def show_match(left_file, right_file): +def show_match(left_file, right_file, env=None): """ Displays a brief summary of two CNL-file next to each other. @@ -43,8 +43,8 @@ def show_match(left_file, right_file): (e.g. sender and receiver). """ - left_head, left_rates = left_file.as_column() - right_head, right_rates = right_file.as_column() + left_head, left_rates = left_file.as_column(env) + right_head, right_rates = right_file.as_column(env) ## Head print_in_two_columns("{:<50} {}", left_head, right_head) @@ -173,7 +173,7 @@ class LogAnalyzer: - def as_column(self): + def as_column(self, env=None): ## TODO change name? ## Head @@ -187,6 +187,14 @@ class LogAnalyzer: for comment in comments: head.append(comment.strip()[:48]) + if ( env ): + env_head = self.cnl_file.get_environment() + for e in env: + head.append( '{}: {}'.format(e, pretty_json(env_head[e])) ) + + + head.append("Duration: {}s".format(round(self.experiment_duration)) ) + ## Transmission rates @@ -208,8 +216,8 @@ class LogAnalyzer: - def visualize_brief(self): - head, rates = self.as_column() + def visualize_brief(self, env=None): + head, rates = self.as_column(env) print_in_two_columns("{:<50} {}", head, rates ) -- GitLab