@@ -9,7 +9,7 @@ def read_dbc(filename):
9
9
cur_path = os .path .dirname (os .path .realpath (__file__ ))
10
10
generator_path = os .path .join (cur_path , '../' )
11
11
12
- include_pattern = r'CM_ "IMPORT (.*?)"'
12
+ include_pattern = re . compile ( r'CM_ "IMPORT (.*?)"' )
13
13
14
14
for dir_name , _ , filenames in os .walk (cur_path ):
15
15
if dir_name == cur_path :
@@ -24,11 +24,15 @@ def read_dbc(filename):
24
24
print filename
25
25
dbc_file_in = read_dbc (filename )
26
26
27
- includes = re .findall (include_pattern , dbc_file_in )
27
+ includes = include_pattern .findall (dbc_file_in )
28
28
29
29
output_filename = filename .replace ('.dbc' , '_generated.dbc' )
30
-
31
- with open (os .path .join (generator_path , output_filename ), 'w' ) as dbc_file_out :
30
+ output_file_location = os .path .join (generator_path , output_filename )
31
+
32
+ if os .isfile (output_file_location ):
33
+ os .remove (output_file_location )
34
+
35
+ with open (output_file_location , 'a' ) as dbc_file_out :
32
36
dbc_file_out .write ('CM_ "AUTOGENERATED FILE, DO NOT EDIT"\n ' )
33
37
34
38
for include_filename in reversed (includes ):
@@ -40,4 +44,6 @@ def read_dbc(filename):
40
44
dbc_file_out .write (include_file )
41
45
42
46
dbc_file_out .write ('\n CM_ "%s starts here"\n ' % filename )
43
- dbc_file_out .write (dbc_file_in )
47
+
48
+ core_dbc = include_pattern .sub ('' , dbc_file_in )
49
+ dbc_file_out .write (core_dbc )
0 commit comments