From 7cb4fe0944b839f28dfd96a88a772cd6a8b58019 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 2 Nov 2023 17:16:25 -0600 Subject: reorganized project files (part 1) (just moved files, didn't change the contents yet, and nothing will work without updating #includes and build scripts and stuff) --- bin/models.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 bin/models.py (limited to 'bin/models.py') diff --git a/bin/models.py b/bin/models.py new file mode 100755 index 0000000..1985352 --- /dev/null +++ b/bin/models.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python + +import os +import re + +def main(args): + """models.py: scan build targets to generate the MODELS file + """ + + models = [] + + # load all cfg-*.h files + paths = os.listdir('.') + for p in paths: + if p.startswith('cfg-') and p.endswith('.h'): + m = load_cfg(p) + models.append(m) + + # sort by model number + foo = [(m.num, m.name, m) for m in models] + foo.sort() + models = [x[-1] for x in foo] + + fmt = '%s\t%-30s\t%s' + print(fmt % ('Model', 'Name', 'MCU')) + print(fmt % ('-----', '----', '---')) + for m in models: + print(fmt % (m.num, m.name, m.attiny)) + + print('\nDuplicates:') + for i, m in enumerate(models): + for m2 in models[i+1:]: + #if (m.num == m2.num) and (m is not m2): + if m.num == m2.num: + print('%s\t%s, %s' % (m.num, m.name, m2.name)) + + print('\nMissing:') + for m in models: + if not m.num: + print(m.name) + + +class Empty: + pass + + +def load_cfg(path): + m = Empty() + m.name, m.num, m.attiny = '', '', 'attiny85' + + m.name = path.replace('cfg-', '').replace('.h', '') + + num_pat = re.compile(r'#define\s+MODEL_NUMBER\s+"(\d+)"') + mcu_pat = re.compile(r'ATTINY:\s+(\d+)') + # TODO? use C preprocessor to generate more complete file to scan + with open(path) as fp: + for line in fp: + found = num_pat.search(line) + if found: + m.num = found.group(1) + found = mcu_pat.search(line) + if found: + m.attiny = 'attiny' + found.group(1) + + return m + + +if __name__ == "__main__": + import sys + main(sys.argv[1:]) + -- cgit v1.2.3