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

« back to all changes in this revision

Viewing changes to bin/ivle-cloneworksheets

  • Committer: David Coles
  • Date: 2010-08-30 03:26:13 UTC
  • Revision ID: coles.david@gmail.com-20100830032613-d14vng0jkelniu3l
python-console: Fix globals broken with new JSON library.

simplejson always returns unicode strings. cJSON would return ordinary strings 
if possible. cPickle.loads() only accepts strings. At present we use pickle 
version 0 so they should all works as ASCII strings. Higher versions of pickle 
are not plain ASCII and are likely to break this and so this should be fixed 
at some point.

Also replaced unconditional exception with one that catches Pickle errors. Not 
sure the best way to report failures of these functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    sys.exit(1)
31
31
 
32
32
if len(sys.argv) != 7:
33
 
    print >> sys.stderr, "usage: %s <oldsubjectcode> <oldyear> <oldsemester> "\
34
 
                         "<newsubjectcode> <newyear> <newsemester>" \
 
33
    print >> sys.stderr, "usage: %s <oldsubjectcode> <oldyear> <oldsemestercode> "\
 
34
                         "<newsubjectcode> <newyear> <newsemestercode>" \
35
35
                         % os.path.basename(sys.argv[0])
36
36
    sys.exit()
37
37
 
40
40
src = store.find(Offering,
41
41
                 Subject.code == unicode(sys.argv[1]),
42
42
                 Semester.year == unicode(sys.argv[2]),
43
 
                 Semester.semester == unicode(sys.argv[3]),
 
43
                 Semester.code == unicode(sys.argv[3]),
44
44
                 Offering.subject_id == Subject.id,
45
45
                 Offering.semester_id == Semester.id).one()
46
46
 
47
47
dst = store.find(Offering,
48
48
                 Subject.code == unicode(sys.argv[4]),
49
49
                 Semester.year == unicode(sys.argv[5]),
50
 
                 Semester.semester == unicode(sys.argv[6]),
 
50
                 Semester.code == unicode(sys.argv[6]),
51
51
                 Offering.subject_id == Subject.id,
52
52
                 Offering.semester_id == Semester.id).one()
53
53
 
54
54
if dst.worksheets.count() > 0:
55
55
    die('%r already has worksheets - doing nothing' % dst)
56
56
 
57
 
for oldws in src.worksheets:
58
 
    newws = Worksheet()
59
 
    newws.seq_no = oldws.seq_no
60
 
    newws.identifier = oldws.identifier
61
 
    newws.name = oldws.name
62
 
    newws.assessable = oldws.assessable
63
 
    newws.data = oldws.data
64
 
    newws.format = oldws.format
65
 
    newws.offering = dst
66
 
    store.add(newws)
67
 
    ivle.worksheet.utils.update_exerciselist(newws)
 
57
dst.clone_worksheets(src)
68
58
 
69
59
print >> sys.stderr, 'copied %d worksheets from %r to %r' \
70
60
                     % (dst.worksheets.count(), src, dst)