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

« back to all changes in this revision

Viewing changes to bin/ivle-enrolallusers

  • Committer: Matt Giuca
  • Date: 2009-02-24 04:44:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1119.
  • Revision ID: matt.giuca@gmail.com-20090224044400-m9mm2ngpt2d2jyv0
title.svg: Changed background colour to blue (for testing purposes)
    - this is the same as the actual background of the site.
    And moved the letters "IVLE" so they are evenly distributed, and appear
    behind the words they stand for.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import optparse
35
35
import logging
36
36
 
37
 
import ivle.config
38
37
import ivle.database
39
38
import ivle.pulldown_subj
40
39
 
42
41
p.add_option('--user', '-u', metavar="<login>",
43
42
             help="Just perform enrolment for user <login>")
44
43
p.add_option('--verbose', '-v', action='store_true')
 
44
p.add_option('--year', '-y', metavar="<year>",
 
45
             help="If specified, year to make enrolments for (default: "
 
46
                  "current year)")
45
47
options, arguments = p.parse_args()
46
48
 
47
49
if options.verbose:
52
54
    print >> sys.stderr, "%s must be run as root" % sys.argv[0]
53
55
    sys.exit(1)
54
56
 
55
 
config = ivle.config.Config()
56
 
store = ivle.database.get_store(config)
57
 
 
 
57
store = ivle.database.get_store()
58
58
if options.user is None:
59
59
    users = store.find(ivle.database.User).order_by(ivle.database.User.login)
60
60
else:
65
65
else:
66
66
    logging.info("enrolment started for user %s" % options.user)
67
67
 
 
68
if options.year is not None and not options.year.isdigit():
 
69
    logging.error("Year must be numeric")
 
70
    sys.exit(1)
 
71
 
 
72
options.year = unicode(options.year)
 
73
 
68
74
for user in users:
69
75
    try:
70
76
        # Get all subjects this user is enrolled in, and add them to the DB if
71
77
        # they match one of our local subject codes
72
 
        res = ivle.pulldown_subj.enrol_user(config, store, user)
 
78
        res = ivle.pulldown_subj.enrol_user(store, user, options.year)
73
79
        logging.info("Enrolled user %s in %d subject%s." % (user.login, res,
74
80
                        '' if res == 1 else 's'))
75
81
    except Exception, message: