28
from ivle.database import get_store, Subject, Semester, Offering, User, \
32
print >> sys.stderr, '%s: %s' % (os.path.basename(sys.argv[0]), error)
35
30
if len(sys.argv) != 5:
36
print >> sys.stderr, "usage: %s <login> <subjectcode> <year> <semester>" \
31
print >> sys.stderr, "usage: %s <login> <subjectcode> <semester> <year>" \
37
32
% os.path.basename(sys.argv[0])
42
user = User.get_by_login(store, sys.argv[1])
46
offering = store.find(Offering,
47
Subject.code == unicode(sys.argv[2]),
48
Semester.year == unicode(sys.argv[3]),
49
Semester.semester == unicode(sys.argv[4]),
50
Offering.subject_id == Subject.id,
51
Offering.semester_id == Semester.id).one()
53
die("subject offering not found")
55
if not offering.semester.active:
56
die("cannot enrol - semester inactive")
60
except AlreadyEnrolledError:
61
die("already enrolled")
35
if not ivle.db.DB().add_enrolment(*sys.argv[1:]):
36
print >> sys.stderr, "enrolment failed!"