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