32
32
# TODO: When creating a new home directory, chown it to its owner
45
def make_svn_repo(login, throw_on_error=True):
46
"""Create a repository for the given user.
48
path = os.path.join(conf.svn_repo_path, login)
50
res = os.system("svnadmin create '%s'" % path)
51
if res != 0 and throw_on_error:
52
raise Exception("Cannot create repository for %s" % login)
53
except Exception, exc:
58
os.system("chown -R www-data:www-data %s" % path)
62
def rebuild_svn_config():
63
"""Build the complete SVN configuration file.
66
res = conn.query("SELECT login, rolenm FROM login;").dictresult()
70
if role not in groups:
72
groups[role].append(r['login'])
73
f = open(conf.svn_conf + ".new", "w")
74
f.write("# IVLE SVN Repositories Configuration\n")
75
f.write("# Auto-generated on %s\n" % time.asctime())
78
for (g,ls) in groups.iteritems():
79
f.write("%s = %s\n" % (g, ",".join(ls)))
83
f.write("[%s:/]\n" % login)
84
f.write("%s = rw\n" % login)
85
#f.write("@tutor = r\n")
86
#f.write("@lecturer = rw\n")
87
#f.write("@admin = rw\n")
90
os.rename(conf.svn_conf + ".new", conf.svn_conf)
92
def make_svn_config(login, throw_on_error=True):
93
"""Add an entry to the apache-svn config file for the given user.
94
Assumes the given user is either a guest or a student.
96
f = open(conf.svn_conf, "a")
97
f.write("[%s:/]\n" % login)
98
f.write("%s = rw\n" % login)
99
#f.write("@tutor = r\n")
100
#f.write("@lecturer = rw\n")
101
#f.write("@admin = rw\n")
105
def make_svn_auth(login, throw_on_error=True):
106
"""Setup svn authentication for the given user.
107
FIXME: create local.auth entry
109
passwd = md5.new(uuid.uuid4().bytes).digest().encode('hex')
110
if os.path.exists(conf.svn_auth_ivle):
115
db.DB().update_user(login, svn_pass=passwd)
117
res = os.system("htpasswd -%smb %s %s %s" % (create,
120
if res != 0 and throw_on_error:
121
raise Exception("Unable to create ivle-auth for %s" % login)
42
125
def make_jail(username, uid, force=True):
43
126
"""Creates a new user's jail space, in the jail directory as configured in
166
249
raise Exception, errors
168
def make_user_db(login, uid, password, nick, fullname, rolenm, studentid,
251
def make_user_db(throw_on_error = True, **kwargs):
170
252
"""Creates a user's entry in the database, filling in all the fields.
171
If force is False, throws an exception if the user already exists.
172
If True, overwrites the user's entry in the DB.
253
All arguments must be keyword args. They are the fields in the table.
254
However, instead of supplying a "passhash", you must supply a
255
"password" argument, which will be hashed internally.
256
Also do not supply a state. All users are created in the "no_agreement"
258
Throws an exception if the user already exists.
176
# Delete user if it exists
178
dbconn.delete_user(login)
181
dbconn.create_user(login, uid, password, nick, fullname, rolenm, studentid)
261
dbconn.create_user(**kwargs)
264
if kwargs['password']:
265
if os.path.exists(conf.svn_auth_local):
269
res = os.system("htpasswd -%smb %s %s %s" % (create,
273
if res != 0 and throw_on_error:
274
raise Exception("Unable to create local-auth for %s" % kwargs['login'])