2
# IVLE - Informatics Virtual Learning Environment
3
# Copyright (C) 2007-2008 The University of Melbourne
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
# Program: EnrolAllUsers
23
# Script to add enrolments for all users on the system.
24
# Pulls from the configured subject pulldown module the subjects each student
25
# is enrolled in, and adds enrolments to the database.
26
# Does not remove any enrolments.
28
# Requires root to run.
38
import ivle.pulldown_subj
40
p = optparse.OptionParser()
41
p.add_option('--user', '-u', metavar="<login>",
42
help="Just perform enrolment for user <login>")
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: "
47
options, arguments = p.parse_args()
50
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
54
print >> sys.stderr, "%s must be run as root" % sys.argv[0]
57
store = ivle.database.get_store()
58
if options.user is None:
59
users = store.find(ivle.database.User).order_by(ivle.database.User.login)
61
users = [ivle.database.User.get_by_login(store, options.user)]
63
if options.user is None:
64
logging.info("enrolment started")
66
logging.info("enrolment started for user %s" % options.user)
68
if options.year is not None and not options.year.isdigit():
69
logging.error("Year must be numeric")
72
options.year = unicode(options.year)
76
# Get all subjects this user is enrolled in, and add them to the DB if
77
# they match one of our local subject codes
78
res = ivle.pulldown_subj.enrol_user(store, user, options.year)
79
logging.info("Enrolled user %s in %d subject%s." % (user.login, res,
80
'' if res == 1 else 's'))
81
except Exception, message:
82
logging.warning(str(message))
86
logging.info("enrolment completed successfully")