vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / utils / rename-ifdefs.py
bloba70a950243f6bb0b2bb507d1768e6f53c9e0ac6d
1 #!/usr/bin/python
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
5 # in the future.
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.
12 import os
13 import re
15 RENAMES = [
16 'ACC',
17 'GYRO',
18 'BARO',
19 'MAG',
20 'LED_STRIP',
21 'SPEKTRUM_BIND',
22 'SERIAL_RX',
23 'BLACKBOX',
24 'GPS',
25 'GPS_PROTO_UBLOX',
26 'TELEMETRY',
27 'TELEMETRY_LTM',
28 'TELEMETRY_FRSKY',
29 'CMS',
30 'GPS_PROTO_UBLOX_NEO7PLUS',
31 'TELEMETRY_HOTT',
32 'TELEMETRY_IBUS',
33 'TELEMETRY_MAVLINK',
34 'TELEMETRY_SMARTPORT',
35 'TELEMETRY_CRSF',
36 'PITOT',
37 'OSD',
38 'NAV',
39 'ASYNC_GYRO_PROCESSING',
40 'BOOTLOG',
41 'STATS',
42 'FIXED_WING_LANDING',
43 'VTX_CONTROL',
44 'VTX_SMARTAUDIO',
45 'VTX_TRAMP',
46 'VTX_RTC6705',
47 'VTX_COMMON',
50 NEW_NAMES = {
51 'FIXED_WING_LANDING': 'NAV_FIXED_WING_LANDING',
54 REPLS = [
55 '(define ){0}(\W|$)',
56 '(undef ){0}(\W|$)',
57 '(ifdef ){0}(\W|$)',
58 '(defined\\(){0}(\\)(\W|$))',
59 '(condition: ){0}(\W|$)',
63 def replace_in_files(root):
64 def visit(arg, dirname, names):
65 for n in names:
66 p = os.path.join(dirname, n)
67 if os.path.isfile(p):
68 with open(p) as f:
69 data = f.read()
70 new_data = data
71 for name in RENAMES:
72 new_name = NEW_NAMES.get(name, 'USE_' + name)
73 repl = '\\1' + new_name + '\\2'
74 for r in REPLS:
75 pattern = r.format(name)
76 new_data = re.sub(pattern, repl, new_data)
77 if new_data != data:
78 with open(p, 'w') as f:
79 f.write(new_data)
82 os.path.walk(root, visit, None)
85 replace_in_files('src')