-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSuite_input.py
73 lines (56 loc) · 2.17 KB
/
TestSuite_input.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
#/usr/bin/python
import sys, getopt
#Basically we have to read a config file and write namelists accordingly
###############################################################################
def Locate_cfg( argv, ifile, ofile ):
inputfile = 'default.cfg'
outputfile = 'default.log'
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print 'test.py -i <inputfile> -o <outputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -i <inputfile> -o <outputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
ifile.append( inputfile )
ofile.append( outputfile )
###############################################################################
def Configfile_interpreter( ifile, cfg ):
# Declare mutable object => lines read from config file
lines = []
# Reads all the lines in the config file specified at CLI
lines = tuple( open(ifile[0], 'r' ))
# Loop over all of these read lines
for ll in range( len(lines) ):
# Create a string from each line
lstr = str(lines[ll])
# nullify case sensitivity in that string
lstr = lstr.lower()
# if it is meant to be interpreted - interpret based on what
# it starts with. See configfile example format
# check if the string is a comment
if not lstr.startswith('#'):
# Mode
if lstr.startswith( "mode" ):
cfield = lines[ll].strip().split()
cfg.mode.append(cfield[1])
# Name
if lstr.startswith( "name" ):
cfield = lines[ll].strip().split()
cstr = ""
for istr in range( 1,len(cfield) ):
cstr = cstr + cfield[istr]
cfg.name.append(cstr)
# Path
if lstr.startswith( "path" ):
cfield = lines[ll].strip().split()
cfg.path.append(cfield[1])
# End IF not comment line
# End Loop over read lines[]
###############################################################################