vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / utils / scan_target_headers.py
blob4f8473fa51d4b33c1e4dd3fcfcd76cb10012f668
1 #!/usr/bin/env python3
3 """
4 This file is part of Cleanflight.
6 Cleanflight is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Cleanflight is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 """
20 import os
21 import operator
22 import glob
24 if __name__ == '__main__':
25 path = os.path.join(os.path.dirname(__file__), '..',
26 'main', 'target', '*', 'target.h')
27 files = glob.glob(path)
28 defines = {}
30 for file in files:
31 target = os.path.basename(os.path.dirname(file))
32 with open(file, 'r') as handle:
33 for line in handle:
34 line = line.strip()
35 if line.startswith('#define'):
36 try:
37 line = line.replace('\t', ' ')
38 define = line.split(' ')[1].strip()
39 if define not in defines:
40 defines[define] = []
41 defines[define].append(target)
42 except IndexError:
43 pass
45 counts = {k: len(v) for k, v in defines.items()}
47 for define, count in sorted(counts.items(), key=operator.itemgetter(1)):
48 print("{}\t{}\t{}".format(define, count, ', '.join(sorted(defines[define]))))