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

« back to all changes in this revision

Viewing changes to www/common/makeuser.py

  • Committer: mattgiuca
  • Date: 2008-01-23 00:14:53 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:269
browser: Added publish functionality to JavaScript client side.
Added "published" icon.

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:   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.
 
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.
30
24
 
31
25
import os
32
26
import shutil
33
27
 
34
28
import conf
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):
 
29
 
 
30
def makeuser(username):
53
31
    """Creates a new user's jail space, in the jail directory as configured in
54
32
    conf.py.
55
33
 
57
35
    contains all the files for a sample student jail. It creates the student's
58
36
    directory in the jail root, by making a hard-link copy of every file in the
59
37
    template directory, recursively.
60
 
 
61
 
    Returns the path to the user's home directory.
62
38
    """
63
39
    templatedir = os.path.join(conf.jail_base, 'template')
64
40
    if not os.path.isdir(templatedir):
73
49
    linktree(templatedir, userdir)
74
50
 
75
51
    # Set up the user's home directory
76
 
    homedir = os.path.join(userdir, 'home', username)
77
 
    os.mkdir(homedir)
78
 
    return homedir
 
52
    os.mkdir(os.path.join(userdir, 'home', username))
79
53
 
80
54
def linktree(src, dst):
81
55
    """Recursively hard-link a directory tree using os.link().
115
89
        errors.extend((src, dst, str(why)))
116
90
    if errors:
117
91
        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()