2018-01-25 14:46:50 -08:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
def read_dbc(filename):
|
|
|
|
with open(os.path.join(dir_name, filename), 'r') as file_in:
|
|
|
|
return file_in.read()
|
|
|
|
|
2018-01-25 14:46:50 -08:00
|
|
|
cur_path = os.path.dirname(os.path.realpath(__file__))
|
2018-01-26 11:47:55 -08:00
|
|
|
generator_path = os.path.join(cur_path, '../')
|
2018-01-25 14:46:50 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
include_pattern = r'CM_ "IMPORT (.*?)"'
|
|
|
|
|
|
|
|
for dir_name, _, filenames in os.walk(cur_path):
|
|
|
|
if dir_name == cur_path:
|
|
|
|
continue
|
|
|
|
|
|
|
|
print dir_name
|
|
|
|
|
|
|
|
for filename in filenames:
|
|
|
|
if filename.startswith('_'):
|
|
|
|
continue
|
2018-01-25 14:46:50 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
print filename
|
|
|
|
dbc_file_in = read_dbc(filename)
|
2018-01-25 14:46:50 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
includes = re.findall(include_pattern, dbc_file_in)
|
|
|
|
|
|
|
|
output_filename = filename.replace('.dbc', '_generated.dbc')
|
2018-01-25 14:46:50 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
with open(os.path.join(generator_path, output_filename), 'a') as dbc_file_out:
|
|
|
|
dbc_file_out.write('CM_ "AUTOGENERATED FILE, DO NOT EDIT"\n')
|
2018-03-09 05:21:37 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
for include_filename in reversed(includes):
|
2018-01-25 14:46:50 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
include_file_header = '\n\nCM_ "Imported file %s starts here"\n' % include_filename
|
|
|
|
dbc_file_out.write(include_file_header)
|
2018-01-25 14:46:50 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
include_file = read_dbc(include_filename)
|
|
|
|
dbc_file_out.write(include_file)
|
2018-01-26 11:47:55 -08:00
|
|
|
|
2018-06-05 05:22:06 -07:00
|
|
|
dbc_file_out.write('\nCM_ "%s starts here"\n' % filename)
|
|
|
|
dbc_file_out.write(dbc_file_in)
|