-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
98 lines (82 loc) · 2.63 KB
/
main.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# This program converts a sch kicad schematic description file into latex source code that can be compiled using the package circuitikz
# The proper kicad library must be used to obtain good results
#
#author: Vladimir Cravero - [email protected]
# Generic imports
#!/usr/bin/env python
import sys
# This file contains all the supported devices classes
from devices import *
# This file contains all the constants needed around
from const import *
"""Begin of main program"""
print "This is schToTek v{0}\nOpening files...".format(VERSION)
# Opening the files:
try:
f_in = open(INPUT_FILE_NAME, "r")
except IOError as e:
print "IO Error opening the input file({0}): {1}\n".format(e.errno, e.strerror)
sys.exit(-1)
except:
print "Unexpected error({0}): {1}\n", sys.exc_info()[0]
sys.exit(-1)
try:
f_out = open(OUT_FILE_NAME, "w")
except IOError as e:
print "IO Error opening the output file({0}): {1}\n".format(e.errno, e.strerror)
sys.exit(-1)
except:
print "Unexpected error({0}): {1}\n", sys.exc_info()[0]
sys.exit(-1)
try:
f_header = open(TEK_HEADER_FILE_NAME, "r")
except IOError as e:
print "IO Error opening the input file({0}): {1}\n".format(e.errno, e.strerror)
sys.exit(-1)
except:
print "Unexpected error({0}): {1}\n", sys.exc_info()[0]
sys.exit(-1)
# Writing the header
# WARNING: out will be erased at this point!
for line in f_header:
f_out.write(line)
f_header.close()
print "Done. Starting parser..."
lines_parsed = 0
wires_count = 0
components_count = 0
junctions_count = 0
# Parser
c_id = 0
for line in f_in:
lines_parsed += 1
if WIRE in line:
line = f_in.next()
lines_parsed += 1
wires_count +=1
f_out.write(Wire(line).to_tek())
elif JUNCTION in line:
f_out.write(Junction(line).to_tek())
junctions_count += 1
elif NO_CONNECT in line:
f_out.write(NoConnect(line).to_tek())
elif COMPONENT in line:
components_count += 1
component_block = ""
while END_COMPONENT not in line:
component_block = component_block + line
line = f_in.next()
lines_parsed += 1
component_block = component_block + line
c = Component(component_block, c_id)
c.parse()
f_out.write(c.to_tek())
c_id += 1
#appending the footer
f_out.write(TEK_FOOTER)
print "Done. Closing files..."
# Don't forget to close all the files
f_in.close()
f_out.close()
print "Read {0} lines".format(lines_parsed)
print "Parsed:\n{0} wire segments,\n{1} junctions,\n{2} components".format(wires_count, junctions_count, components_count)