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

« back to all changes in this revision

Viewing changes to makeuser.py

  • Committer: mattgiuca
  • Date: 2008-07-07 12:01:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:820
lib: Added new package pulldown_subj, a collection of modules designed to
    pull student subject enrolments from the server.
    Note that the actual code to do this is not included (since that is
    specific to the organisation running IVLE) - just a pluggable interface
    and an example plugin module.
configure.py: Added new config option: subject_pulldown_modules, which allows
    you to specify which modules are plugged in here.
    (Actually that was added accidentally in a previous commit; but this
    revision fixes some comments).

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
97
    # Make the user's database entry
100
98
    common.makeuser.make_user_db(**user)
101
99
except Exception, message: