3 # This script was used during the #define FEATURE -> #define USE_FEATURE
4 # migration. It's commited to the repo in case it will be useful again
6 # Conditional flags in the RENAMES list are renamed prepending USE_ to
7 # them unles a different renaming is found in the NEW_NAMES map.
9 # This script should be able to replace all ocurrences in all the source
10 # code for the project, including the settings.yaml file.
30 'GPS_PROTO_UBLOX_NEO7PLUS',
34 'TELEMETRY_SMARTPORT',
39 'ASYNC_GYRO_PROCESSING',
51 'FIXED_WING_LANDING': 'NAV_FIXED_WING_LANDING',
58 '(defined\\(){0}(\\)(\W|$))',
59 '(condition: ){0}(\W|$)',
63 def replace_in_files(root
):
64 def visit(arg
, dirname
, names
):
66 p
= os
.path
.join(dirname
, n
)
72 new_name
= NEW_NAMES
.get(name
, 'USE_' + name
)
73 repl
= '\\1' + new_name
+ '\\2'
75 pattern
= r
.format(name
)
76 new_data
= re
.sub(pattern
, repl
, new_data
)
78 with
open(p
, 'w') as f
:
82 os
.path
.walk(root
, visit
, None)
85 replace_in_files('src')