~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-addexercise

Modified ivle-addexercise. It will now (once more) attempt to add every
file given, even if a previous exercise fails to add.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
"""Script to upload an exercise file into the database"""
22
22
 
23
 
import os, sys, traceback
 
23
import os, sys
24
24
import xml.dom.minidom as minidom
25
25
 
26
 
from ivle.config import Config
27
26
from ivle.database import Exercise, TestSuite, TestCase, TestSuiteVar, TestCasePart, get_store
28
27
 
29
28
class XMLMalformedError(Exception):
62
61
    cases = []
63
62
    case_num = 0
64
63
    for case_node in suite_node.getElementsByTagName('function'):
 
64
        case_num += 1
65
65
        cases.append(add_test_case(case_node, case_num, store))
66
 
        case_num += 1
67
66
 
68
67
    ## ALLOWED TAGS ##
69
68
    # stdin     - Stdin for the suite - Unique - Text inside element
176
175
xmlfile = sys.argv[1]
177
176
 
178
177
def add_exercise(xmlfile):
179
 
    # Skip existing ones.
180
 
    if store.find(Exercise, id=unicode(xmlfile)).count():
181
 
        return
182
 
 
183
 
    print "Adding exercise", xmlfile
184
178
    try:
185
179
        filedom = minidom.parse(xmlfile)
186
180
    except IOError, e:
221
215
        elif child.tagName == 'desc':
222
216
            description = getTextData(child)
223
217
 
 
218
    if solution is None:
 
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!")
 
222
 
 
223
    store = get_store()
224
224
    new_exercise = Exercise()
225
225
    new_exercise.id = unicode(xmlfile)
226
226
    new_exercise.name = exercisename
238
238
 
239
239
    store.add(new_exercise)
240
240
    store.commit()
241
 
 
242
 
store = get_store(Config())
243
 
 
 
241
    
244
242
xmlfiles = sys.argv[1:]
245
243
for xmlfile in xmlfiles:
 
244
    print "Adding exercise", xmlfile
246
245
    try:
247
246
        add_exercise(xmlfile)
248
247
    except Exception, e:
249
248
        print "ERROR: Could not add file", xmlfile
 
249
        print e.stacktrace()