-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_stencil.py
More file actions
executable file
·76 lines (47 loc) · 1.25 KB
/
run_stencil.py
File metadata and controls
executable file
·76 lines (47 loc) · 1.25 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
#!/usr/bin/python -tt
import sys,getopt
import commands
import logging
logger = logging.getLogger('stencil')
hdlr = logging.StreamHandler(sys.stdout)
#hdlr = logging.FileHandler('stencil.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO) #logging.DEBUG
def Usage():
print " Usage: %s [--help] " % sys.argv[0]
def Run(cmd):
logger.info("** Running: %s" % cmd)
(status,output) = commands.getstatusoutput(cmd)
if status > 0:
logger.error(cmd)
logger.error(output)
sys.exit(2)
return output
def main(argv):
# make sure command line arguments are valid
try:
options, args = getopt.getopt(
argv,
'hv',
[
'help',
'verbose'
])
except getopt.GetoptError:
logging.fatal("Bad options!")
help()
sys.exit(2)
# handle command line arugments
for opt, arg in options:
if opt in ('-h', '--help'):
Usage()
sys.exit(2)
elif opt in ('-v', '--verbose'):
logger.setLevel(logging.DEBUG)
###################################
# main code starts here
###################################
if __name__ == "__main__":
main(sys.argv[1:])