-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakegvp.py
More file actions
140 lines (108 loc) · 3.83 KB
/
makegvp.py
File metadata and controls
140 lines (108 loc) · 3.83 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python
import sys
import os
import re
import io
import argparse
# Just for the OSHPark abbreviations for now:
fileending=".gvp"
inputfilename="NONAME"
path="/you/need/to/declare/a/path"
colordict = [ \
["GBL", 1, "12850 38550 12850"], \
["GTL", 1, "12850 38550 12850"], \
["BCR", 1, "56540 41120 15420"], \
["GBS", 1, "48830 43690 64226"], \
["GTS", 1, "48830 43690 64226"], \
["TCR", 1, "56540 41120 15420"], \
["GBO", 1, "61287 61285 35400"], \
["GTO", 1, "65535 65024 56842"], \
["GKO", 2, "0 48830 48830"], \
["XLN", 2, "0 0 0"] \
]
header="(gerbv-file-version! \"2.0A\")\n"
layer=11
verbose=0
def parseOptions():
"""
Reads the user's command-line input for determining what to call the
file and the directory path location.
"""
if (sys.argv[0] == ""):
print("WARNING: you need to provide a filename for the output file.")
sys.exit()
parser=argparse.ArgumentParser(description='''makegvp.py; a python script that takes the Gerber files in a given directory and creates a default gerbv document layout, with a standard color palette for each layer.
''')
parser.add_argument("-n", "--name", action='store', \
dest="filestub", default="NONAME",
help="provide a filename stub for each Gerber layer", metavar="FILE")
parser.add_argument("-p", "--path", action='store', \
dest="path", default="/Users/",
help="provide a file path for the directory where the \
Gerber files are found", metavar="PATH" )
arguments = parser.parse_args()
args = vars(arguments)
print("Looks like the input filename argument is: %s" % str(args['filestub']))
print("And the input path argument is: %s" % str(args['path']))
return (args)
def fileCheck(path, filestub, suffix ):
"""Check for path/file.suffix and return True if it is there."""
fpath = str("%s/%s.%s" % (path, filestub, suffix) )
try:
if (os.path.isfile(fpath) is True):
return True
except:
print("Error when testing for file %s. Halting" % fpath )
sys.exit()
return False
def makeFooter(namestub, path, verbose):
"""Print the footer."""
linestring=str("(define-layer! -1 \
(cons 'filename \"%s/\")\
(cons 'visible #f)\
(cons 'color #(0 0 0)))\n" % path )
linestring+=str("(set-render-type! 3)\n")
return linestring
def oneLine (key, color, layer, namestub,verbose):
"""Print a basic line with some layer variations."""
linestring=str("(define-layer! %d (cons 'filename \"%s.%s\")\
(cons 'visible #t)(cons 'color #(%s))" %
( layer, namestub , key , color) )
if (key is not "XLN"):
linestring += ")\n"
else:
linestring += "(cons 'attribs (list (list 'autodetect 'Boolean 1) \
(list 'zero_supression 'Enum 0) \
(list 'units 'Enum 0) \
(list 'digits 'Integer 4))))\n"
return linestring
# End of function descriptions
# parse arguments:
print("Parsing arguments.")
arguments = parseOptions()
inputfilename = arguments['filestub']
#inputfilename = re.sub(' ','_', inputfilename)
inputfilename = re.sub('\"','', inputfilename)
print("Output file name will be:\n%s.gvp" % inputfilename)
path = arguments['path']
path = re.sub('\/$','', path)
# Main loop starts here:
f=open(str("%s/%s.gvp" % (path, inputfilename) ), 'w')
f.write(header)
for k in range(0,len(colordict)):
if (fileCheck(path, inputfilename, colordict[k][0] ) is True) :
pass
else:
layer=layer-1
continue
for i in range(0,colordict[k][1]):
thisline = oneLine(colordict[k][0], colordict[k][2],
layer, inputfilename, verbose)
f.write(thisline)
layer=layer-1
if (layer<0):
layer==0
linestring=makeFooter(inputfilename, path, verbose)
f.write(linestring)
f.close()
#<EOF>