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

« back to all changes in this revision

Viewing changes to makeuser.py

  • Committer: mattgiuca
  • Date: 2008-02-19 00:54:28 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:500
db: get_user and get_users now return User objects instead of dictionaries.
    This is the major part of replacing dicts with User objects, as it
    propagates upwards.

Propagated User objects up through the following modules:
    listusers.py, dispatch.login, authenticate, userservice, forumutil
All of these now treat users as an object rather than a dict.

To save on the size of the changes so far, login still individually copies
fields over to the session (so the session does not yet store a user object;
that is the second part of this refactor).

WOO!! Revision 500 :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    ('p', 'password', "Cleartext password for this user"),
47
47
    ('n', 'nick', "Display name (defaults to <fullname>)"),
48
48
    ('e', 'email', "Email address"),
49
 
    ('s', 'studentid', "Student ID"),
 
49
    ('s', 'studentid', "Student ID")
50
50
]
51
51
 
52
52
if len(sys.argv) <= 3:
68
68
opts = dict(opts)
69
69
 
70
70
# Get the dictionary of fields from opts and args
71
 
dict = {}
 
71
user = {}
72
72
for i in range(0, len(requireds)):
73
 
    dict[requireds[i]] = args[i]
 
73
    user[requireds[i]] = args[i]
74
74
for short, long, _ in optionals:
75
75
    try:
76
 
        dict[long] = opts['-' + short]
 
76
        user[long] = opts['-' + short]
77
77
    except KeyError:
78
78
        try:
79
 
            dict[long] = opts['--' + long]
 
79
            user[long] = opts['--' + long]
80
80
        except KeyError:
81
81
            pass
82
 
login = dict['login']
83
 
if 'nick' not in dict:
84
 
    dict['nick'] = dict['fullname']
 
82
login = user['login']
 
83
if 'nick' not in user:
 
84
    user['nick'] = user['fullname']
85
85
 
86
86
try:
87
87
    # Resolve the user's username into a UID
95
95
            (_,_,uid,_,_,_,_) = pwd.getpwnam(login)
96
96
        except KeyError:
97
97
            raise Exception("Failed to add Unix user account")
98
 
    dict['unixid'] = uid
 
98
    user['unixid'] = uid
99
99
    # Make the user's jail
100
100
    common.makeuser.make_jail(login, uid)
101
101
    # Make the user's database entry
102
 
    common.makeuser.make_user_db(**dict)
 
102
    common.makeuser.make_user_db(**user)
103
103
except Exception, message:
104
104
    print "Error: " + str(message)
105
105
    sys.exit(1)
106
106
 
107
 
print "Successfully created user %s (%s)." % (login, dict['fullname'])
 
107
print "Successfully created user %s (%s)." % (login, user['fullname'])