Python2 is end-of-life [1] since the 1st of January 2020. Some distributions (most notably: Debian and its derivatives) will stop providing a `python` executable in order to encourage users to specify the interpreter language of local scripts explicitly. Users of such environments will be forced to work around this in one of these ways: * create a virtual environment or * manipulate the shebangs of the scripts or * install the python2 package (as long as it is provided by distributions) All currently maintained distribution releases provide python3. In the near future distributions will need to remove python2, since it is not maintained anymore. PEP-394 [2] recommends to reference a specific python version (python2 or python3), if the script is not expected to run in a virtual environment. Closes: #1265 [1] https://www.python.org/dev/peps/pep-0373/#update-april-2014 [2] https://www.python.org/dev/peps/pep-0394/#for-python-script-publishers Amended-by: Karl Palsson <karlp@tweak.net.au> * moved lpc43xx scripts to explicitly call python2, they have not been ported, and are effectively unmaintained, but switching them to python3 unconditionally would be unhelpful.
37 lines
1.1 KiB
Python
Executable File
37 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python2
|
|
|
|
import sys
|
|
import yaml
|
|
import csv
|
|
from collections import OrderedDict
|
|
|
|
def convert_file(fname):
|
|
reader = csv.reader(open(fname, 'r'))
|
|
|
|
registers = OrderedDict()
|
|
for register_name, lsb, width, field_name, description, reset_value, access in reader:
|
|
if register_name not in registers:
|
|
registers[register_name] = {
|
|
'fields': OrderedDict(),
|
|
}
|
|
|
|
register = registers[register_name]
|
|
fields = register['fields']
|
|
if field_name in fields:
|
|
raise RuntimeError('Duplicate field name "%s" in register "%s"' %
|
|
field_name, register_name)
|
|
else:
|
|
fields[field_name] = {
|
|
'lsb': int(lsb),
|
|
'width': int(width),
|
|
'description': description,
|
|
'reset_value': reset_value,
|
|
'access': access,
|
|
}
|
|
|
|
with open(fname.replace('.csv', '.yaml'), 'w') as out_file:
|
|
yaml.dump(registers, out_file, default_flow_style=False)
|
|
|
|
for fname in sys.argv[1:]:
|
|
convert_file(fname)
|