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

« back to all changes in this revision

Viewing changes to bin/ivle-addexercise

  • Committer: Matt Giuca
  • Date: 2009-03-24 03:14:44 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090324031444-dbpn1bj6dr4zh4sx
Added auto-generated (and hand-modified) Sphinx files (conf, Makefile and
    index).
    Our IVLE documentation will be stored as Sphinx files.
    make html to generate the documentation.

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
 
23
import os, sys, traceback
24
24
import xml.dom.minidom as minidom
25
25
 
26
26
from ivle.database import Exercise, TestSuite, TestCase, TestSuiteVar, TestCasePart, get_store
61
61
    cases = []
62
62
    case_num = 0
63
63
    for case_node in suite_node.getElementsByTagName('function'):
 
64
        cases.append(add_test_case(case_node, case_num, store))
64
65
        case_num += 1
65
 
        cases.append(add_test_case(case_node, case_num, store))
66
66
 
67
67
    ## ALLOWED TAGS ##
68
68
    # stdin     - Stdin for the suite - Unique - Text inside element
152
152
            filename = child_node.getAttribute('name')
153
153
            if filename == "":
154
154
                raise XMLMalformedException('file tag must have names')
155
 
            parts.append(add_part(store, element_type, test_type, data,
 
155
            parts.append(add_part(store, part_type, test_type, data,
156
156
                                        filename))
157
157
            
158
158
        elif child_node.tagName in allowed_parts:
175
175
xmlfile = sys.argv[1]
176
176
 
177
177
def add_exercise(xmlfile):
 
178
    store = get_store()
 
179
 
 
180
    # Skip existing ones.
 
181
    if store.find(Exercise, id=unicode(xmlfile)).count():
 
182
        return
 
183
 
 
184
    print "Adding exercise", xmlfile
178
185
    try:
179
186
        filedom = minidom.parse(xmlfile)
180
187
    except IOError, e:
215
222
        elif child.tagName == 'desc':
216
223
            description = getTextData(child)
217
224
 
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
225
    new_exercise = Exercise()
225
226
    new_exercise.id = unicode(xmlfile)
226
227
    new_exercise.name = exercisename
241
242
    
242
243
xmlfiles = sys.argv[1:]
243
244
for xmlfile in xmlfiles:
244
 
    print "Adding exercise", xmlfile
245
 
    #try:
246
 
    add_exercise(xmlfile)
247
 
    #except Exception, e:
248
 
    #    print "ERROR: Could not add file", xmlfile
249
 
    #    print e.stacktrace()
 
245
    try:
 
246
        add_exercise(xmlfile)
 
247
    except Exception, e:
 
248
        print "ERROR: Could not add file", xmlfile