1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/env python3
"""
# TOP2049 Open Source programming suite
#
# Commandline utility
#
# Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
import re
import sys
import os
def substitute(input, oldSocket, newSocket):
input = re.sub(r'(^\s*packages).*', lambda m:'{} = (("DIP10", ""), ),'.format(m.group(1)), input)
input = re.sub(r'(^\s*chipPackage).*', lambda m:'{} = "DIP10",'.format(m.group(1)), input)
input = re.sub(r'(^\s*chipPinVCC).*', lambda m:'{} = 9,'.format(m.group(1)), input)
input = re.sub(r'(^\s*chipPinsVPP).*', lambda m:'{} = 10,'.format(m.group(1)), input)
input = re.sub(r'(^\s*chipPinGND).*', lambda m:'{} = 8,'.format(m.group(1)), input)
input = re.sub(r'(^\s*runtimeID).*', lambda m:'{} = (0xDE05, 0x01),'.format(m.group(1)), input)
input = re.sub(r'(^\s*description).+"(.*)".*', lambda m:'{} = "{} - ICD",'.format(m.group(1), m.group(2)), input)
input = re.sub(r'(^\s*bitfile).*', lambda m:'{} = "microchip01sip6",'.format(m.group(1)), input)
input = re.sub("{}".format(oldSocket), "{}".format(newSocket), input)
input = re.sub("{}".format(oldSocket.upper()), "{}".format(newSocket.upper()), input)
return input
def makeSip():
inputFileName = '__init__.py'
fin = open(inputFileName)
dMCU = {}
for line in fin:
matchObj = re.match(r'.*(pic[0-9]+l?f\w+)(sip[0-9a]+).*', line)
if matchObj:
continue
matchObj = re.match(r'.*(pic[0-9]+l?f\w+)(dip[0-9a]+).*', line)
if not matchObj:
print("{} did not match".format(line))
continue
# print('matched {} - {}'.format(matchObj.group(1), matchObj.group(2)))
dMCU.setdefault(matchObj.group(1), matchObj.group(2))
fin.close()
for item in dMCU.items():
fin = open("{}{}.py".format(item[0], item[1]))
fout = open("{}sip6.py".format(item[0]), 'w')
fout.write("#\n")
fout.write("# THIS FILE WAS AUTOGENERATED BY makeSip6.py\n")
fout.write("# Do not edit this file manually. All changes will be lost.\n")
fout.write("#\n\n")
for line in fin:
fout.write(substitute(line, "{}".format(item[1]), "sip6"))
fout.close()
fin.close()
def main(argv):
makeSip()
if __name__ == "__main__":
exit(main(sys.argv))
|