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

« back to all changes in this revision

Viewing changes to bin/ivle-enrolallusers

  • Committer: Matt Giuca
  • Date: 2009-01-19 17:28:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119172859-htjq3rfpp0fhtpc9
ivle.worksheet: Added calculate_score. This is a nice clean Storm port of
    ivle.db.calculate_worksheet_score.
tutorial: Replaced use of ivle.db.calculate_worksheet_score with
    ivle.worksheet.calculate_score.
    Guess What!! Removed this module's dependency on ivle.db! Hooray!
    (Note: tutorialservice still depends on it).
bin/ivle-marks: Updated this script to use ivle.worksheet_calculate_score.
    Note that this DOES NOT execute properly -- it seems it didn't even
    before my changes (tries to call db.get_users). Not my fault; I'm
    committing and going to bed!
ivle.db: Removed calculate_worksheet_score.
    As this removes the dependency on get_problem_status, removed that too!
    Almost all the worksheet stuff is gone now!

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