173
173
return new_test_case
175
175
xmlfile = sys.argv[1]
177
filedom = minidom.parse(xmlfile)
179
sys.exit('ivle-addexercise: error opening file ' + xmlfile + ': ' + e[1])
182
for child in filedom.childNodes:
183
if child.nodeType == child.ELEMENT_NODE and child.tagName == 'exercise':
186
sys.exit('ivle-addexercise: error parsing XML: root node must be "exercise"')
188
exercisename = exercise.getAttribute('name')
189
rows = exercise.getAttribute('rows')
191
partial_solution = None
194
test_suite_nodes = []
195
for child in exercise.childNodes:
196
if child.nodeType != child.ELEMENT_NODE:
198
if child.tagName == 'solution':
199
if solution is not None:
200
sys.exit('ivle-addexercise: error parsing XML: multiple "solution" nodes')
201
solution = getTextData(child)
202
elif child.tagName == 'include':
203
if include_code is not None:
204
sys.exit('ivle-addexercise: error parsing XML: multiple "include" nodes')
205
include_code = getTextData(child)
206
elif child.tagName == 'partial':
207
if partial_solution is not None:
208
sys.exit('ivle-addexercise: error parsing XML: multiple "include" nodes')
209
partial_solution = getTextData(child)
210
elif child.tagName == 'case':
211
test_suite_nodes.append(child)
212
elif child.tagName == 'desc':
213
description = getTextData(child)
216
sys.exit("ivle-addexercise: error parsing XML: No solution given")
217
if len(test_suite_nodes) == 0:
218
sys.exit("ivle-addexercise: error parsing XML:")
221
new_exercise = Exercise()
222
new_exercise.id = unicode(xmlfile)
223
new_exercise.name = exercisename
224
new_exercise.num_rows = int(rows)
225
new_exercise.partial = partial_solution
226
new_exercise.solution = solution
227
new_exercise.include = include_code
228
new_exercise.description = description
229
new_exercise.partial = partial_solution
230
store.add(new_exercise)
232
for suite in test_suite_nodes:
233
new_exercise.test_suites.add(add_test_suite(suite, suite_num, store))
236
store.add(new_exercise)
177
def add_exercise(xmlfile):
179
filedom = minidom.parse(xmlfile)
181
raise Exception('ivle-addexercise: error opening file ' + xmlfile + ': ' + e[1])
183
for child in filedom.childNodes:
184
if child.nodeType == child.ELEMENT_NODE and child.tagName == 'exercise':
187
raise XMLMalformedError('ivle-addexercise: error parsing XML: root node must be "exercise"')
189
exercisename = exercise.getAttribute('name')
190
rows = exercise.getAttribute('rows')
194
partial_solution = None
197
test_suite_nodes = []
198
for child in exercise.childNodes:
199
if child.nodeType != child.ELEMENT_NODE:
201
if child.tagName == 'solution':
202
if solution is not None:
203
raise XMLMalformedError('ivle-addexercise: error parsing XML: multiple "solution" nodes')
204
solution = getTextData(child)
205
elif child.tagName == 'include':
206
if include_code is not None:
207
raise XMLMalformedError('ivle-addexercise: error parsing XML: multiple "include" nodes')
208
include_code = getTextData(child)
209
elif child.tagName == 'partial':
210
if partial_solution is not None:
211
raise XMLMalformedError('ivle-addexercise: error parsing XML: multiple "include" nodes')
212
partial_solution = getTextData(child)
213
elif child.tagName == 'case':
214
test_suite_nodes.append(child)
215
elif child.tagName == 'desc':
216
description = getTextData(child)
219
raise XMLMalformedError("ivle-addexercise: error parsing XML: No solution given")
220
if len(test_suite_nodes) == 0:
221
raise XMLMalformedError("ivle-addexercise: error parsing XML: No Tests Given!")
224
new_exercise = Exercise()
225
new_exercise.id = unicode(xmlfile)
226
new_exercise.name = exercisename
227
new_exercise.num_rows = int(rows)
228
new_exercise.partial = partial_solution
229
new_exercise.solution = solution
230
new_exercise.include = include_code
231
new_exercise.description = description
232
new_exercise.partial = partial_solution
233
store.add(new_exercise)
235
for suite in test_suite_nodes:
236
new_exercise.test_suites.add(add_test_suite(suite, suite_num, store))
239
store.add(new_exercise)
242
xmlfiles = sys.argv[1:]
243
for xmlfile in xmlfiles:
244
print "Adding exercise", xmlfile
246
add_exercise(xmlfile)
247
#except Exception, e:
248
# print "ERROR: Could not add file", xmlfile
249
# print e.stacktrace()