Commit 753a9935 authored by Kirill Smelkov's avatar Kirill Smelkov

software/ors-amarisoft: render-templates: Rework --delete to be precise

Soon we are going to make rf_mode a runtime parameter and so there
won't be TDD and FDD in software names anymore.

Prepare to that and make --delete to remove the exact set of files that
render-template actually generates instead of becoming a noop after "runtime
rf_mode" restructuring.
parent 2149bc2d
...@@ -8,17 +8,6 @@ parser = argparse.ArgumentParser() ...@@ -8,17 +8,6 @@ parser = argparse.ArgumentParser()
parser.add_argument('-d', '--delete', action='store_true') parser.add_argument('-d', '--delete', action='store_true')
args = parser.parse_args() args = parser.parse_args()
if args.delete:
directory = os.path.dirname(os.path.realpath(__file__))
test_directory = os.path.join(directory, 'test')
for f in os.listdir(directory):
if 'tdd' in f or 'fdd' in f:
os.remove(os.path.join(directory, f))
for f in os.listdir(test_directory):
if 'testTDD' in f or 'testFDD' in f:
os.remove(os.path.join(test_directory, f))
exit()
global_context = { global_context = {
'generated_file_message': "This file was generated using a jinja2 template and the render-templates script, don't modify directly." 'generated_file_message': "This file was generated using a jinja2 template and the render-templates script, don't modify directly."
} }
...@@ -91,19 +80,24 @@ with open('software.jinja2.cfg', 'r') as f: ...@@ -91,19 +80,24 @@ with open('software.jinja2.cfg', 'r') as f:
with open('test/test.jinja2.py', 'r') as f: with open('test/test.jinja2.py', 'r') as f:
test_template = Template(f.read()) test_template = Template(f.read())
# emit updates file @ path with data on regular run and deletes it on --delete.
def emit(path, data):
data += '\n'
if args.delete:
os.remove(path)
else:
with open(path, 'w+') as f:
f.write(data)
for software in software_list: for software in software_list:
with open('software-{}.cfg.json'.format(software['software_name']), emit('software-{}.cfg.json'.format(software['software_name']),
'w+') as f: software_json_template.render(**software, **global_context))
f.write(software_json_template.render(**software, **global_context) + '\n') emit('test/test{}.py'.format(software['software_name'].upper()),
with open('test/test{}.py'.format(software['software_name'].upper()), test_template.render(**software, **global_context))
'w+') as f: emit('software-{}.cfg'.format(software['software_name']),
f.write(test_template.render(**software, **global_context) + '\n') software_template.render(**software, **global_context))
with open('software-{}.cfg'.format(software['software_name']),
'w+') as f:
f.write(software_template.render(**software, **global_context) + '\n')
for software_type in ['enb', 'gnb', 'ue-lte', 'ue-nr']: for software_type in ['enb', 'gnb', 'ue-lte', 'ue-nr']:
with open('instance-{}-{}-input-schema.json'.format( emit('instance-{}-{}-input-schema.json'.format(
software['software_name'], software['software_name'],
software_type), software_type),
'w+') as f: instance_json_template_map[software_type].render(**software, **global_context))
f.write(instance_json_template_map[software_type].render(**software, **global_context) + '\n')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment