diff options
author | Hanoh Haim <hhaim@cisco.com> | 2015-06-24 14:03:29 +0300 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2015-06-24 14:03:29 +0300 |
commit | 8b52a31ed2c299b759f330c4f976b9c70f5765f4 (patch) | |
tree | 9d6da5438b5b56b1d2d57e6c13494b4e65d000e7 /scripts/automation/trex_control_plane/doc/docs_utilities.py |
first version
Diffstat (limited to 'scripts/automation/trex_control_plane/doc/docs_utilities.py')
-rwxr-xr-x | scripts/automation/trex_control_plane/doc/docs_utilities.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/doc/docs_utilities.py b/scripts/automation/trex_control_plane/doc/docs_utilities.py new file mode 100755 index 00000000..e80d765f --- /dev/null +++ b/scripts/automation/trex_control_plane/doc/docs_utilities.py @@ -0,0 +1,37 @@ +#!/router/bin/python + +from texttable import Texttable +import yaml + + +def handle_data_items(field_yaml_dict): + data_items = field_yaml_dict['data'] + return [ [json_key, meaning['type'], meaning['exp'] ] + for json_key,meaning in data_items.items() ] + + +def json_dict_to_txt_table(dict_yaml_file): + + # table = Texttable(max_width=120) + with open(dict_yaml_file, 'r') as f: + yaml_stream = yaml.load(f) + + for main_field, sub_key in yaml_stream.items(): + print main_field + ' field' '\n' + '~'*len(main_field+' field') + '\n' + + field_data_rows = handle_data_items(sub_key) + table = Texttable(max_width=120) + table.set_cols_align(["l", "c", "l"]) + table.set_cols_valign(["t", "m", "m"]) + # create table's header + table.add_rows([["Sub-key", "Type", "Meaning"]]) + table.add_rows(field_data_rows, header=False) + + + print table.draw() + "\n" + + + + + +json_dict_to_txt_table("json_dictionary.yaml")
\ No newline at end of file |