-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQucsStudioConv.py
71 lines (61 loc) · 1.72 KB
/
QucsStudioConv.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
import sys
def quitprogram():
print("Usage: <input_file.sch> -v <output_version> -o <output_file_name>")
quit()
def checkHeader(head):
version = 0
try:
head.find("QucsStudio")
for x in head:
try:
version = int(x)
break;
except:
pass
print("Found QucsStudio %d.x file!" % (version))
except:
print("Invalid QucsStudio file!")
quitprogram()
if(len(sys.argv)<6):
quitprogram()
else:
#Open the desired file
try:
f = open(sys.argv[1], 'r')
except:
print("File not found!")
quitprogram()
#check the header
header = f.readline()
checkHeader(header)
#check version
try:
int(sys.argv[3][0]) #test if the version has integer part
except:
print("Invalid version format!")
quitprogram()
#check output name
for i in sys.argv[5]:
if(i == "."):
print("Invalid output name! Please remove the \".\" and/or extension")
quitprogram()
#generate the temp file
try:
f1 = open(sys.argv[5]+".sch",'w')
print("Creating Qucs %s file" %(sys.argv[3]))
except:
print("Cant create file %s" %(sys.argv[5]))
quit()
#change the header & version
f1.write("<Qucs Schematic %s>\n" %(sys.argv[3]))
#add the < and >
for line in f:
if not ('<') in line:
f1.write("<")
if not ('>') in line:
f1.write(line.replace('\n', '>\n'))
else:
f1.write(line)
f.close()
f1.close()
print("Done!\nFile: %s.sch saved!" % (sys.argv[5]))