aboutsummaryrefslogtreecommitdiff
path: root/bin/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/models.py')
-rwxr-xr-xbin/models.py62
1 files changed, 35 insertions, 27 deletions
diff --git a/bin/models.py b/bin/models.py
index 1985352..8e54d1c 100755
--- a/bin/models.py
+++ b/bin/models.py
@@ -10,33 +10,37 @@ def main(args):
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)
+ for p, dirs, files in os.walk('hw'):
+ for d in dirs:
+ if '/' not in p: # skip top-level brand dirs
+ continue
+ #print('... %s' % d)
+ m = load_model(os.path.join(p, d))
+ if m.mcu and m.model:
+ models.append(m)
# sort by model number
- foo = [(m.num, m.name, m) for m in models]
+ foo = [(m.model, m.name, m) for m in models]
foo.sort()
models = [x[-1] for x in foo]
+ print('Models: %i\n' % len(models))
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(fmt % (m.model, m.name, m.mcu))
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))
+ #if (m.model == m2.model) and (m is not m2):
+ if m.model == m2.model:
+ print('%s\t%s, %s' % (m.model, m.name, m2.name))
print('\nMissing:')
for m in models:
- if not m.num:
+ if not m.model:
print(m.name)
@@ -44,27 +48,31 @@ class Empty:
pass
-def load_cfg(path):
+def load_model(path):
+ #print('load_model(%s)' % 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)
+ m.name, m.model, m.mcu = '', '', '???'
+
+ m.name = path.replace('hw/','').replace('/', '-')
+ m.mcu = inherit(path, 'arch')
+ m.model = inherit(path, 'model')
return m
+def inherit(path, field):
+ #print('inherit(%s, %s)' % (path, field))
+ check = os.path.join(path, field)
+ if os.path.exists(check):
+ line = open(check).readline().strip()
+ return line
+ else:
+ parent = os.path.join(*os.path.split(path)[:-1])
+ if parent:
+ return inherit(parent, field)
+ return None
+
+
if __name__ == "__main__":
import sys
main(sys.argv[1:])