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

« back to all changes in this revision

Viewing changes to makeuser.py

  • Committer: drtomc
  • Date: 2008-03-04 02:16:52 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:638
makeuser: add a command line option to allow a uid to be specified.
    If not given, consult /etc/passwd. If not there, generate a random one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
requireds = ["login", "fullname", "rolenm"]
45
45
optionals = [
46
46
    ('p', 'password', "Cleartext password for this user"),
 
47
    ('u', 'unixid', "Numeric unix user id"),
47
48
    ('n', 'nick', "Display name (defaults to <fullname>)"),
48
49
    ('e', 'email', "Email address"),
49
50
    ('s', 'studentid', "Student ID")
83
84
if 'nick' not in user:
84
85
    user['nick'] = user['fullname']
85
86
 
 
87
# Resolve the user's username into a UID
 
88
if 'unixid' not in user:
 
89
    try:
 
90
        (_,_,uid,_,_,_,_) = pwd.getpwnam(login)
 
91
        user['unixid'] = uid
 
92
    except KeyError:
 
93
        user['unixid'] = random.randrange(5000,10000)
 
94
 
86
95
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
96
    # Make the user's database entry
100
97
    common.makeuser.make_user_db(**user)
101
98
except Exception, message: