-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathOmsiUtility.py
80 lines (72 loc) · 2.15 KB
/
OmsiUtility.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
#Utility tools for the application
from OmsiQuestion import *
import pdb
import shlex
#Will return an array of OMSIQuestion objects
def ParseQuestions(filename):
with open(filename,'r') as f:
foundDescription = False
firstQuestion = False
question = ""
questions = []
line = f.readline()
while line:
if 'DESCRIPTION' in line:
foundDescription = True
line = f.readline()
while line and 'DESCRIPTION' not in line and 'QUESTION' not in line:
question += line
line = f.readline()
q = OmsiQuestion(question,0)
questions.append(q)
question = ""
elif 'QUESTION' in line:
firstQuestion = True
filetype = '.txt'
flags = ""
words = shlex.split(line)
compileProgram = "n"
compiler = ""
runProgram = "n"
runCmd = ""
for i in range(len(words)):
if words[i] == '-ext':
if i+1 >= len(words):
print("Error! Unexpected end of arguments...")
else:
print(("Setting type to {0}".format(words[i+1])))
filetype = words[i+1]
i+= 1
if words[i] == '-flags':
if i+1 >= len(words):
print("Error! Unexpected end of arguments...")
else:
fl = words[i+1]
print(("Setting flags to {0}".format(fl)))
flags = fl
if words[i] == '-com': #check if question can be compiled
if i+1 >= len(words):
print("Error! Unexpected end of arguments...")
else:
com = words[i+1]
print(("Setting compiler option to {0}".format(com)))
compileProgram = 'y'
compiler = com
if words[i] == '-run': #check if question can be run
if i+1 >= len(words):
print("Error! Unexpected end of arguments...")
else:
runCmd = words[i+1]
runProgram = 'y'
print(("Setting run-command option to {0}".format(runCmd)))
runCmd = runCmd
line = f.readline()
while line and 'DESCRIPTION' not in line and 'QUESTION' not in line:
question += line
line = f.readline()
q = OmsiQuestion(question,len(questions),filetype,flags, compileProgram, compiler, runProgram, runCmd)
questions.append(q)
question = ""
else:
line = f.readline()
return questions