1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
# Allows creation of users. This sets up the following:
23
# * User's jail and home directory within the jail.
24
# * Subversion repository (TODO)
25
# * Check out Subversion workspace into jail (TODO)
26
# * Database details for user (TODO)
27
# * Unix user account (TODO)
34
def makeuser(username):
35
"""Creates a new user's jail space, in the jail directory as configured in
38
This expects there to be a "template" directory within the jail root which
39
contains all the files for a sample student jail. It creates the student's
40
directory in the jail root, by making a hard-link copy of every file in the
41
template directory, recursively.
43
templatedir = os.path.join(conf.jail_base, 'template')
44
if not os.path.isdir(templatedir):
45
raise Exception("Template jail directory does not exist: " +
47
userdir = os.path.join(conf.jail_base, username)
48
if os.path.exists(userdir):
49
raise Exception("User's jail directory already exists: " +
52
# Hard-link (copy aliasing) the entire tree over
53
linktree(templatedir, userdir)
55
# Set up the user's home directory
56
os.mkdir(os.path.join(userdir, 'home', username))
58
def linktree(src, dst):
59
"""Recursively hard-link a directory tree using os.link().
61
The destination directory must not already exist.
62
If exception(s) occur, an Error is raised with a list of reasons.
64
Symlinks are preserved (in fact, hard links are created which point to the
67
Code heavily based upon shutil.copytree from Python 2.5 library.
69
names = os.listdir(src)
73
srcname = os.path.join(src, name)
74
dstname = os.path.join(dst, name)
76
if os.path.isdir(srcname):
77
linktree(srcname, dstname)
79
os.link(srcname, dstname)
80
# XXX What about devices, sockets etc.?
81
except (IOError, os.error), why:
82
errors.append((srcname, dstname, str(why)))
83
# catch the Error from the recursive copytree so that we can
84
# continue with other files
85
except Exception, err:
86
errors.append(err.args[0])
88
shutil.copystat(src, dst)
90
# can't copy file access times on Windows
93
errors.extend((src, dst, str(why)))
95
raise Exception, errors