1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
1 |
#!/usr/bin/env python
|
2 |
# IVLE - Informatics Virtual Learning Environment
|
|
3 |
# Copyright (C) 2007-2008 The University of Melbourne
|
|
4 |
#
|
|
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.
|
|
9 |
#
|
|
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.
|
|
14 |
#
|
|
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
|
|
18 |
||
19 |
# Program: EnrolAllUsers
|
|
20 |
# Author: Matt Giuca
|
|
21 |
# Date: 15/7/2008
|
|
22 |
||
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.
|
|
27 |
#
|
|
28 |
# Requires root to run.
|
|
29 |
||
30 |
import sys |
|
31 |
import os |
|
32 |
import os.path |
|
33 |
import pwd |
|
34 |
import optparse |
|
35 |
import logging |
|
36 |
||
1201
by William Grant
ivle.database.get_store() now takes a configuration object. |
37 |
import ivle.config |
1080.1.22
by me at id
bin/ivle-{showenrolment,enrolallusers}: Don't use ivle.db.get_user(); use |
38 |
import ivle.database |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
39 |
import ivle.pulldown_subj |
40 |
||
41 |
p = optparse.OptionParser() |
|
42 |
p.add_option('--user', '-u', metavar="<login>", |
|
43 |
help="Just perform enrolment for user <login>") |
|
44 |
p.add_option('--verbose', '-v', action='store_true') |
|
45 |
options, arguments = p.parse_args() |
|
46 |
||
47 |
if options.verbose: |
|
48 |
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', |
|
49 |
level=logging.DEBUG) |
|
50 |
||
51 |
if os.getuid() != 0: |
|
52 |
print >> sys.stderr, "%s must be run as root" % sys.argv[0] |
|
53 |
sys.exit(1) |
|
54 |
||
1279
by William Grant
Drop ivle.conf usage from ivle.pulldown_subj. |
55 |
config = ivle.config.Config() |
56 |
store = ivle.database.get_store(config) |
|
57 |
||
1080.1.22
by me at id
bin/ivle-{showenrolment,enrolallusers}: Don't use ivle.db.get_user(); use |
58 |
if options.user is None: |
59 |
users = store.find(ivle.database.User).order_by(ivle.database.User.login) |
|
60 |
else: |
|
61 |
users = [ivle.database.User.get_by_login(store, options.user)] |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
62 |
|
63 |
if options.user is None: |
|
64 |
logging.info("enrolment started") |
|
65 |
else: |
|
66 |
logging.info("enrolment started for user %s" % options.user) |
|
67 |
||
68 |
for user in users: |
|
69 |
try: |
|
70 |
# Get all subjects this user is enrolled in, and add them to the DB if
|
|
71 |
# they match one of our local subject codes
|
|
1338
by William Grant
Move the year decision responsibility to each pulldown module, not the pulldown framework. |
72 |
res = ivle.pulldown_subj.enrol_user(config, store, user) |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
73 |
logging.info("Enrolled user %s in %d subject%s." % (user.login, res, |
74 |
'' if res == 1 else 's')) |
|
75 |
except Exception, message: |
|
76 |
logging.warning(str(message)) |
|
77 |
continue
|
|
78 |
||
1080.1.62
by William Grant
ivle.pulldown_subj: Use Storm, and kill ivle.db dependency. This means we use |
79 |
store.commit() |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
80 |
logging.info("enrolment completed successfully") |