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

« back to all changes in this revision

Viewing changes to makeuser.py

  • Committer: mattgiuca
  • Date: 2008-02-05 01:41:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:409
Moved www/conf and www/common to a new directory lib. This separates the "web"
part of IVLE from what is becoming less web oriented (at least from Apache's
standpoint).
Modified setup.py to install this lib directory correctly and write conf in
the right place. Also adds the lib directory to ivle.pth.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
# Script to create a new user. This can also be done through the
24
24
# administration interface.
25
 
# This script wraps common.makeuser.
26
 
# It also creates a unix account which common.makeuser does not.
27
 
# (This script may not be appropriate for production on a multi-node
28
 
# environment).
29
25
 
30
26
import sys
31
27
import os
32
28
import os.path
33
 
import getopt
34
 
import random
35
29
# Import modules from the website is tricky since they're in the www
36
30
# directory.
37
31
sys.path.append(os.path.join(os.getcwd(), 'www'))
38
32
import conf
39
 
import common.makeuser, common.db
40
 
 
41
 
# Requireds and optionals will be used to display the usage message
42
 
# AND do argument processing
43
 
# The names here must correspond to the fields in the database.
44
 
requireds = ["login", "fullname", "rolenm"]
45
 
optionals = [
46
 
    ('p', 'password', "Cleartext password for this user"),
47
 
    ('n', 'nick', "Display name (defaults to <fullname>)"),
48
 
    ('e', 'email', "Email address"),
49
 
    ('s', 'studentid', "Student ID")
50
 
]
51
 
 
52
 
if len(sys.argv) <= 3:
53
 
    # Nicely format the usage message using the optionals
54
 
    print ("Usage: python makeuser.py [OPTIONS] %s\n    OPTIONS"
55
 
        % ' '.join(['<%s>' % x for x in requireds]))
56
 
    for short, long, desc in optionals:
57
 
        t = "        -%s | --%s" % (short, long)
58
 
        print t + (' ' * max(28 - len(t), 2)) + desc
59
 
    sys.exit(1)
60
 
 
61
 
if os.getuid() != 0:
62
 
    print "Must run makeuser.py as root."
63
 
    sys.exit(1)
64
 
 
65
 
shorts = ''.join([o[0] + ":" for o in optionals])
66
 
longs = [o[1] + "=" for o in optionals]
67
 
opts, args = getopt.gnu_getopt(sys.argv[1:], shorts, longs)
68
 
opts = dict(opts)
69
 
 
70
 
# Get the dictionary of fields from opts and args
71
 
user = {}
72
 
for i in range(0, len(requireds)):
73
 
    user[requireds[i]] = args[i]
74
 
for short, long, _ in optionals:
75
 
    try:
76
 
        user[long] = opts['-' + short]
77
 
    except KeyError:
78
 
        try:
79
 
            user[long] = opts['--' + long]
80
 
        except KeyError:
81
 
            pass
82
 
login = user['login']
83
 
if 'nick' not in user:
84
 
    user['nick'] = user['fullname']
 
33
import common.makeuser
 
34
 
 
35
if len(sys.argv) <= 6:
 
36
    print "Usage: python makeuser.py <username> <password> <nick> " \
 
37
        "<fullname> <rolenm> <studentid>"
 
38
    sys.exit()
 
39
 
 
40
username = sys.argv[1]
 
41
password = sys.argv[2]
 
42
nick = sys.argv[3]
 
43
fullname = sys.argv[4]
 
44
rolenm = sys.argv[5]
 
45
studentid = sys.argv[6]
85
46
 
86
47
try:
87
 
    # Make the user's database entry
88
 
    common.makeuser.make_user_db(**user)
 
48
    common.makeuser.makeuser(username, password, nick, fullname, rolenm,
 
49
        studentid)
89
50
except Exception, message:
90
51
    print "Error: " + str(message)
91
52
    sys.exit(1)
92
53
 
93
 
print "Successfully created user %s (%s)." % (login, user['fullname'])
 
54
print "Successfully created user %s (%s)." % (username, fullname)