diff options
Diffstat (limited to 'src/converter')
-rw-r--r-- | src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py | 16 | ||||
-rw-r--r-- | src/converter/libConverter.py | 6 | ||||
-rw-r--r-- | src/converter/schematic_converters/lib/PythonLib/libParser.py | 108 |
3 files changed, 72 insertions, 58 deletions
diff --git a/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py b/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py index 177fa469..bf1a1eac 100644 --- a/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py +++ b/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py @@ -33,17 +33,23 @@ def find_all(a_str, sub): yield start
start += len(sub) # use start += 1 to find overlapping matches
-directory = sys.argv[1]
-# out_file = sys.argv[2]
+# Always go 1 level up from the given path
+directory = os.path.abspath(os.path.join(sys.argv[1], ".."))
if directory=="." : directory = os.getcwd()
+if not os.path.isdir(directory):
+ print(f"ERROR: '{directory}' is not a valid directory.")
+ sys.exit(1)
+
+# out_file = sys.argv[2]
+
dir = os.listdir(directory)
comp = []
for component in dir:
if (component[-4:]==".asy") : comp.append(component)
-indir = directory.split("\\")
-out_file = directory + "\LTspice_" + indir[len(indir)-1] + ".lib"
-print("Output Lib File: ",out_file)
+base_name = os.path.basename(os.path.normpath(directory)) # Get last folder name
+out_file = os.path.join(directory, "LTspice_" + base_name + ".lib")
+print("Output Lib File: ", out_file)
outfl = codecs.open(out_file,"w");
outfl.write("EESchema-LIBRARY Version 2.3\n#encoding utf-8\n#\n")
diff --git a/src/converter/libConverter.py b/src/converter/libConverter.py index 4ac4d354..3c30f7d3 100644 --- a/src/converter/libConverter.py +++ b/src/converter/libConverter.py @@ -22,10 +22,12 @@ class PspiceLibConverter: # Construct the full path to libParser.py parser_path = os.path.join(script_dir, relative_parser_path) - print(parser_path) + print("Parser Path:",parser_path) # Prepare the command as a list - command = ["python3", "libParser.py", file_path] + output_dir = os.path.dirname(file_path) + + command = ["python3", "libparser.py", file_path, output_dir] print(f"Running command: {' '.join(command)} in directory: {parser_path}") try: diff --git a/src/converter/schematic_converters/lib/PythonLib/libParser.py b/src/converter/schematic_converters/lib/PythonLib/libParser.py index c94bd7d5..364ecedc 100644 --- a/src/converter/schematic_converters/lib/PythonLib/libParser.py +++ b/src/converter/schematic_converters/lib/PythonLib/libParser.py @@ -21,60 +21,66 @@ 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) +input_file_path = sys.argv[1] +output_dir = sys.argv[2] - flib.write(libDescr) +# Prepare input/output +input_file = open(input_file_path, 'r') +fbasename = os.path.basename(input_file_path) +flname = fbasename[:fbasename.find('.')] + '.lib' +flpath = os.path.join(output_dir, flname) +os.makedirs(output_dir, exist_ok=True) - line = skipTo(input_file,'*symbol') - print('Parser',line) - ''' +flib = open(flpath, 'w+') # Output .lib file + +print('Library file name: ', flname) + + +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(input_file_path) + 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) ''' - - 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() + line = skipTo(input_file, '*symbol') +flib.write('#\n#End Library\n') +flib.close() |