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

« back to all changes in this revision

Viewing changes to makeuser.py

  • Committer: mattgiuca
  • Date: 2008-02-24 22:09:16 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:553
Added new app: Settings (UI for userservice).
    (Added app dir, media dir with empty JS file, icon).
apps/__init__.py: Added error message.
dispatch/__init__.py: Added error message.
dispatch/html.py: Added link to Settings at the top
    (a special app).
    Fixed HTML icons (correct size link).
    Catch keyerror on icon which would otherwise be thrown all
    the way up on certain errors.

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