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

« back to all changes in this revision

Viewing changes to bin/ivle-enrolallusers

  • Committer: William Grant
  • Date: 2010-02-17 08:37:22 UTC
  • Revision ID: grantw@unimelb.edu.au-20100217083722-ji4v6fbztngy0p3s
Add UI to edit/delete enrolments.

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