From 9f329268d661049b1132e3f054f00ee381bc04a9 Mon Sep 17 00:00:00 2001 From: Marko Mecina <marko.mecina@univie.ac.at> Date: Thu, 5 Aug 2021 14:48:35 +0200 Subject: [PATCH] add converter from specification CSV to JSON --- Tst/spec_to_json.py | 81 +++++++++++++++++++++++++++++++++++++ Tst/tst_template_empty.json | 38 +++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100755 Tst/spec_to_json.py create mode 100644 Tst/tst_template_empty.json diff --git a/Tst/spec_to_json.py b/Tst/spec_to_json.py new file mode 100755 index 0000000..bf33d3f --- /dev/null +++ b/Tst/spec_to_json.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import json +import sys + +sys.path.append('../Ccs') +import ccs_function_lib as cfl + + +def run(specfile, gen_cmd): + tmp = json.load(open('tst_template_empty.json', 'r')) + jspec = tmp.copy() + specs = open(specfile, 'r').read().split('\n') + + name, descr, *_ = specs[1].split('|') + + jspec['_name'] = name + jspec['_description'] = descr + jspec['_version'] = '' + + steps = jspec['sequences'][0]['steps'] + step_temp = steps[0].copy() + steps = [] + + for step in specs[4:]: + + if step.count('|') != 3: + continue + + n, descr, ver, _ = step.split('|') + + if not n.lower().startswith(('step', 'comment')): + continue + + if n.lower() == 'comment': + step = steps[-1] + step['_step_comment'] = descr + continue + + step_temp['_step_number'] = n.replace('Step ', '') + '.0' + step_temp['_primary_counter'] = int(n.replace('Step ', '')) + step_temp['_description'] = descr + step_temp['_verification_description'] = ver + + if gen_cmd and ('TC(' in descr): + try: + i = descr.index('TC(') + 3 + j = descr.index(')', i) + st, sst = map(int, descr[i:j].split(',')) + cmd = cfl.get_tc_descr_from_stsst(st, sst) + if len(cmd) > 1: + for c in cmd: + if c in descr: + _cmd = c + break + _cmd = cmd[0] + else: + _cmd = cmd[0] + cmdtxt = cfl.make_tc_template(_cmd, add_parcfg=True) + except Exception as err: + print(err) + else: + cmdtxt = '' + + step_temp['_command_code'] = cmdtxt + + steps.append(step_temp.copy()) + + jspec['sequences'][0]['steps'] = steps + json.dump(jspec, open(specfile + '.json', 'w'), indent=4) + + +if __name__ == "__main__": + if '--nocmd' in sys.argv: + gen_cmd = False + sys.argv.remove('--nocmd') + else: + gen_cmd = True + + specfile = sys.argv[1] + run(specfile, gen_cmd) diff --git a/Tst/tst_template_empty.json b/Tst/tst_template_empty.json new file mode 100644 index 0000000..5f9b979 --- /dev/null +++ b/Tst/tst_template_empty.json @@ -0,0 +1,38 @@ +{ + "_comment": "", + "_description": "", + "_name": "", + "_postcon_code": "", + "_postcon_descr": "", + "_postcon_name": "", + "_precon_code": "", + "_precon_descr": "", + "_precon_name": "", + "_primary_counter_locked": false, + "_version": "", + "sequences": [ + { + "_description": "", + "_name": "", + "_primary_counter_locked": false, + "_sequence": 0, + "_version": "", + "steps": [ + { + "_command_code": "", + "_description": "", + "_is_active": true, + "_primary_counter": 1, + "_secondary_counter": 0, + "_start_sequence": null, + "_step_comment": "", + "_step_number": "1.0", + "_stop_sequence": null, + "_verification_code": "", + "_verification_description": "", + "_verified_item": [] + } + ] + } + ] +} \ No newline at end of file -- GitLab