diff options
Diffstat (limited to 'src/converter/schematic_converters/lib/PythonLib/libParser.py')
-rw-r--r-- | src/converter/schematic_converters/lib/PythonLib/libParser.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/converter/schematic_converters/lib/PythonLib/libParser.py b/src/converter/schematic_converters/lib/PythonLib/libParser.py new file mode 100644 index 00000000..c94bd7d5 --- /dev/null +++ b/src/converter/schematic_converters/lib/PythonLib/libParser.py @@ -0,0 +1,80 @@ +#The MIT License (MIT) + +#PSpice to Oscad Schematic Converter +#This code is written by Suryavamshi Tenneti, FOSSEE, IIT Bombay +#The code is modified by Sumanto Kar and Gloria Nandihal, FOSSEE, IIT Bombay + + +import sys +import os +from attribute import * +from component_instance import * +from component import * +from design import * +from wire import * +from header import * +from misc import * + + +libDescr = 'EESchema-LIBRARY Version 4.7 Date: \n#encoding utf-8\n' + +nameAppend = '_PSPICE' +REMOVEDCOMPONENTS = ['TITLEBLK', 'PARAM', 'readme', 'VIEWPOINT', 'LIB', 'copyright', 'WATCH1', 'VECTOR', 'NODESET1'] + +for fcounter in range(1, len(sys.argv[1:])+1): + input_file = open(sys.argv[fcounter], 'r+') + fbasename = os.path.basename(sys.argv[fcounter]) + flname = fbasename[:fbasename.find('.')] + '.lib' + flib = open(flname, 'w+') #Write .lib header: + print('Library file name: ',flname) + + flib.write(libDescr) + + line = skipTo(input_file,'*symbol') + print('Parser',line) + ''' + while(line != '' and '*symbol' not in line): + line = input_file.readline().strip() + print(line) + ''' + + while(line != '__ERROR__'): + #print(input_file.tell()) + #print('Compo line',line) + d = line.find(' ') + cnametmp = line[d+1:] + #print('cnametmp',cnametmp) + d = cnametmp.find(' ') + if d == -1: + cname = cnametmp + else: + cname = cnametmp[0:d] + + #print('cname->',cname) + + fileTMP = open(sys.argv[fcounter]) + c = Component(fileTMP, cname) + #print(c.ref) + fixComp(c) + #print('After fixComp',cname, 'ref=', c.ref) + + write = True + + for i in range(len(REMOVEDCOMPONENTS)): #Don't let these components be saved. + if cname == REMOVEDCOMPONENTS[i]: + write = False + break + #print('write->', write) + #print('line->', line) + if write: + c.type_ = c.type_ + nameAppend + c.print(flib) + + '''line = input_file.readline().strip() + while(line != '' and '*symbol' not in line): + line = input_file.readline().strip() + print(line) + ''' + line = skipTo(input_file, '*symbol') + flib.write('#\n#End Library\n') + flib.close() |