Files
hmmmm_avr_generic/manifest_src/gen_manifest_json.py

53 lines
1.6 KiB
Python

import sys
import csv
import json
import os
SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
def main():
if len(sys.argv) != 2:
print('provide manifest data directory')
return
manifest_dir = sys.argv[1]
with open(manifest_dir + '/dev_type', 'r') as f:
dev_type = f.read()
with open(manifest_dir + '/dev_variant', 'r') as f:
dev_variant = f.read()
try:
with open(SCRIPT_PATH + '/instructions.json', 'r') as f:
instructions = json.load(f)
except Exception as e:
print(f'unable to read instructions file: {e}')
instructions = []
mem_segments = []
out_manifest = {
'mem_segments': mem_segments,
'dev_type': dev_type,
'dev_variant': dev_variant,
'instructions': instructions
}
with open(manifest_dir + '/seg_data.csv', 'r', newline='') as csvfile:
reader = csv.DictReader(csvfile, delimiter=';')
for line in reader:
mem_segments.append(
{
'seg_id': int(line['seg_id']),
'name': line['name'],
'word_len': int(line['word_len']),
'default_size': int(line['default_size']),
'default_addr': int(line['default_addr']),
'is_executable': line['is_executable'] == '1'
}
)
with open(manifest_dir + '/MANIFEST.json', 'w') as f:
json.dump(out_manifest, f, indent=4)
if __name__ == '__main__':
main()