4 generate_config.py - Generate specific configuration file for VPP from
8 ./generate_config.py <directory> <output-file-type>
10 where <directory> is a system directory containing generic config file(s)
11 (suffixed with *.config)
12 <output-file-type> is one of 'vat' or 'cli'
14 This script looks for *.config files in provided directory and for each
15 generates a specific configuration file based on output file type in form
16 '<filename>.cli' or '<filename>.vat' respectively.
24 def generate_config(file_name, mode):
27 param mode: one of 'vat' or 'cli'
30 f = open(file_name, 'r')
36 if line == '' or line[0] == '#':
39 kw = line[: line.index(' ')]
40 args = line[ line.index(' ') + 1:]
42 if kw not in cmd_mappings.mappings:
43 raise Exception('Conversion error at {}:{}:\n > {}\nKeyword not found:'
44 ' {}'.format(file_name, line_num, line, kw))
46 mapping = cmd_mappings.mappings[kw]
48 s = s + mapping.generate(mode, args) + '\n'
49 except Exception as e:
50 raise Exception('Conversion error at {}:{}:\n > {}'
51 .format(file_name, line_num, line))
57 if len(sys.argv) != 3:
58 print('Error: expected 2 arguments!')
61 dir_name = sys.argv[1]
62 config_type = sys.argv[2]
64 if config_type != 'vat' and config_type != 'cli':
65 print('Error: expected second parameter one of "vat" or "cli"!')
68 for f in glob.glob(dir_name + "/*.config"):
69 config = generate_config(f, config_type)
71 output_fname = f.replace('.config', '.' + config_type)
72 print('\n* Generated config from {}:'.format(f))
74 print ('* Saving to {}'.format(output_fname))
76 fout = open(output_fname, 'w')