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

« back to all changes in this revision

Viewing changes to makeuser.py

  • Committer: dcoles
  • Date: 2008-07-03 04:20:54 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:803
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should 
allow us to get in there and tidy up each module much easier. Also removed 
updatejails since this functionality seems to be duplicated with remakeuser.py 
and remakealluser.py scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import os.path
33
33
import pwd
34
34
import getopt
 
35
import random
35
36
# Import modules from the website is tricky since they're in the www
36
37
# directory.
37
38
sys.path.append(os.path.join(os.getcwd(), 'www'))
44
45
requireds = ["login", "fullname", "rolenm"]
45
46
optionals = [
46
47
    ('p', 'password', "Cleartext password for this user"),
 
48
    ('u', 'unixid', "Numeric unix user id"),
47
49
    ('n', 'nick', "Display name (defaults to <fullname>)"),
48
50
    ('e', 'email', "Email address"),
49
51
    ('s', 'studentid', "Student ID")
83
85
if 'nick' not in user:
84
86
    user['nick'] = user['fullname']
85
87
 
 
88
# Resolve the user's username into a UID
 
89
if 'unixid' not in user:
 
90
    try:
 
91
        (_,_,uid,_,_,_,_) = pwd.getpwnam(login)
 
92
        user['unixid'] = uid
 
93
    except KeyError:
 
94
        user['unixid'] = random.randrange(5000,10000)
 
95
 
86
96
try:
87
 
    # Resolve the user's username into a UID
88
 
    # Create the user if it does not exist
89
 
    try:
90
 
        (_,_,uid,_,_,_,_) = pwd.getpwnam(login)
91
 
    except KeyError:
92
 
        if os.system("useradd '%s'" % login) != 0:
93
 
            raise Exception("Failed to add Unix user account")
94
 
        try:
95
 
            (_,_,uid,_,_,_,_) = pwd.getpwnam(login)
96
 
        except KeyError:
97
 
            raise Exception("Failed to add Unix user account")
98
 
    user['unixid'] = uid
99
 
    # Make the user's jail
100
 
    common.makeuser.make_jail(login, uid)
101
97
    # Make the user's database entry
102
98
    common.makeuser.make_user_db(**user)
103
99
except Exception, message: