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

« back to all changes in this revision

Viewing changes to bin/ivle-enrolallusers

  • Committer: me at id
  • Date: 2009-01-15 06:11:02 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1163
www/app/{subjects,tutorial}: Use the new Storm API to get enrolled subjects.

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
 
37
import ivle.db
38
38
import ivle.database
39
39
import ivle.pulldown_subj
40
40
 
55
55
    print >> sys.stderr, "%s must be run as root" % sys.argv[0]
56
56
    sys.exit(1)
57
57
 
58
 
config = ivle.config.Config()
59
 
store = ivle.database.get_store(config)
60
 
 
 
58
store = ivle.database.get_store()
61
59
if options.user is None:
62
60
    users = store.find(ivle.database.User).order_by(ivle.database.User.login)
63
61
else:
72
70
    logging.error("Year must be numeric")
73
71
    sys.exit(1)
74
72
 
75
 
options.year = None if options.year is None else unicode(options.year)
76
 
 
77
73
for user in users:
78
74
    try:
79
75
        # Get all subjects this user is enrolled in, and add them to the DB if
80
76
        # they match one of our local subject codes
81
 
        res = ivle.pulldown_subj.enrol_user(config, store, user, options.year)
 
77
        res = ivle.pulldown_subj.enrol_user(user.login, options.year)
82
78
        logging.info("Enrolled user %s in %d subject%s." % (user.login, res,
83
79
                        '' if res == 1 else 's'))
84
80
    except Exception, message:
85
81
        logging.warning(str(message))
86
82
        continue
87
83
    
88
 
store.commit()
89
84
logging.info("enrolment completed successfully")