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

« back to all changes in this revision

Viewing changes to www/common/makeuser.py

  • Committer: mattgiuca
  • Date: 2008-02-04 00:10:25 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:395
Tutorial: split subjects directory into subjects and problems.
    Subjects now contains only subject XML and worksheet XML files.
    Problems are in a separate directory hierarchy.
Setup / Conf: Added new option "problems_base". This is used by tutorial to
    find the problem sheets.
In sample, moved problems to a "problems" directory. Setup installer correctly
    installs all the problems in this directory to the correct sample place.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
# Module: MakeUser
19
19
# Author: Matt Giuca
20
 
# Date:   9/1/2008
21
 
 
22
 
# Allows creation of users. This sets up the user's jail and home directory
23
 
# within the jail.
 
20
# Date:   1/2/2008
 
21
 
 
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
 
27
# * Unix user account
 
28
 
 
29
# TODO: Sanitize login name and other fields.
24
30
 
25
31
import os
26
32
import shutil
27
33
 
28
34
import conf
29
 
 
30
 
def makeuser(username):
 
35
import db
 
36
 
 
37
def makeuser(username, password, nick, fullname, rolenm, studentid):
 
38
    """Creates a new user on a pre-installed system.
 
39
    Sets up the following:
 
40
    * User's jail and home directory within the jail.
 
41
    * Subversion repository
 
42
    * Check out Subversion workspace into jail
 
43
    * Database details for user
 
44
    * Unix user account
 
45
    """
 
46
    homedir = make_jail(username)
 
47
    make_user_db(username, password, nick, fullname, rolenm, studentid)
 
48
    # TODO: -p password (need to use crypt)
 
49
    if os.system("useradd -d %s '%s'" % (homedir, username)) != 0:
 
50
        raise Exception("Failed to add Unix user account")
 
51
 
 
52
def make_jail(username):
31
53
    """Creates a new user's jail space, in the jail directory as configured in
32
54
    conf.py.
33
55
 
35
57
    contains all the files for a sample student jail. It creates the student's
36
58
    directory in the jail root, by making a hard-link copy of every file in the
37
59
    template directory, recursively.
 
60
 
 
61
    Returns the path to the user's home directory.
38
62
    """
39
63
    templatedir = os.path.join(conf.jail_base, 'template')
40
64
    if not os.path.isdir(templatedir):
49
73
    linktree(templatedir, userdir)
50
74
 
51
75
    # Set up the user's home directory
52
 
    os.mkdir(os.path.join(userdir, 'home', username))
 
76
    homedir = os.path.join(userdir, 'home', username)
 
77
    os.mkdir(homedir)
 
78
    return homedir
53
79
 
54
80
def linktree(src, dst):
55
81
    """Recursively hard-link a directory tree using os.link().
89
115
        errors.extend((src, dst, str(why)))
90
116
    if errors:
91
117
        raise Exception, errors
 
118
 
 
119
def make_user_db(login, password, nick, fullname, rolenm, studentid):
 
120
    """Creates a user's entry in the database, filling in all the fields."""
 
121
    dbconn = db.DB()
 
122
    dbconn.create_user(login, password, nick, fullname, rolenm, studentid)
 
123
    dbconn.close()