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

« back to all changes in this revision

Viewing changes to bin/ivle-enrol

ivle-buildjail: Remove some too-new rsync options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import os
26
26
import sys
27
27
 
28
 
from ivle.database import get_store, Subject, Semester, Offering, User
 
28
from ivle.database import get_store, Subject, Semester, Offering, User, \
 
29
                          AlreadyEnrolledError
29
30
 
30
31
def die(error):
31
32
    print >> sys.stderr, '%s: %s' % (os.path.basename(sys.argv[0]), error)
32
33
    sys.exit(1)
33
34
 
34
 
if len(sys.argv) not in (5, 6):
35
 
    print >> sys.stderr, '''usage: %s <login> <subjectcode> <year> <semester> [role]
36
 
 
37
 
'role' should be one of student (the default), tutor or lecturer.
38
 
If an enrolment already exists, it will be reactivated and its role set.''' \
 
35
if len(sys.argv) != 5:
 
36
    print >> sys.stderr, "usage: %s <login> <subjectcode> <year> <semester>" \
39
37
                         % os.path.basename(sys.argv[0])
40
38
    sys.exit()
41
39
 
54
52
if not offering:
55
53
    die("subject offering not found")
56
54
 
57
 
role = unicode(sys.argv[5]) if len(sys.argv) == 6 else u'student'
58
 
 
 
55
if not offering.semester.active:
 
56
    die("cannot enrol - semester inactive")
 
57
    
59
58
try:
60
 
    offering.enrol(user, role)
 
59
    offering.enrol(user)
61
60
except AlreadyEnrolledError:
62
61
    die("already enrolled")
63
62