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

« back to all changes in this revision

Viewing changes to bin/ivle-makeuser

  • Committer: Matt Giuca
  • Date: 2009-04-23 07:51:29 UTC
  • Revision ID: matt.giuca@gmail.com-20090423075129-94mf4vlwllpew0xn
ivle.svn: Added revision_is_dir (like os.path.isdir for revision history).
ivle.fileservice_lib.listing: Refactored such that the SVN revision is found
    in the top-level handler, and passed down into the individual handlers.
    This is done so that the revision information can be used to make the
    decisions (which will be required to fix the revision history browsing).
    This doesn't yet change the behaviour.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import os
32
32
import getopt
33
33
 
34
 
import ivle.makeuser
 
34
if os.getuid() != 0:
 
35
    print "Must run %s as root." % os.path.basename(sys.argv[0])
 
36
    sys.exit(1)
 
37
 
 
38
from ivle.database import get_store, User
 
39
from ivle.pulldown_subj import enrol_user
35
40
 
36
41
# Requireds and optionals will be used to display the usage message
37
42
# AND do argument processing
38
43
# The names here must correspond to the fields in the database.
39
 
requireds = ["login", "fullname", "rolenm"]
 
44
requireds = ["login", "fullname"]
40
45
optionals = [
41
46
    ('p', 'password', "Cleartext password for this user"),
42
47
    ('n', 'nick', "Display name (defaults to <fullname>)"),
54
59
        print t + (' ' * max(28 - len(t), 2)) + desc
55
60
    sys.exit(1)
56
61
 
57
 
if os.getuid() != 0:
58
 
    print "Must run %s as root." % os.path.basename(sys.argv[0])
59
 
    sys.exit(1)
60
 
 
61
62
shorts = ''.join([o[0] + ":" for o in optionals])
62
63
longs = [o[1] + "=" for o in optionals]
63
64
opts, args = getopt.gnu_getopt(sys.argv[1:], shorts, longs)
66
67
# Get the dictionary of fields from opts and args
67
68
user = {}
68
69
for i in range(0, len(requireds)):
69
 
    user[requireds[i]] = args[i]
 
70
    user[requireds[i]] = unicode(args[i])
70
71
for short, long, _ in optionals:
71
72
    try:
72
 
        user[long] = opts['-' + short]
 
73
        user[long] = unicode(opts['-' + short])
73
74
    except KeyError:
74
75
        try:
75
 
            user[long] = opts['--' + long]
 
76
            user[long] = unicode(opts['--' + long])
76
77
        except KeyError:
77
78
            pass
78
79
login = user['login']
79
80
if 'nick' not in user:
80
81
    user['nick'] = user['fullname']
81
82
 
 
83
store = get_store()
 
84
 
82
85
try:
83
86
    # Make the user's database entry
84
 
    ivle.makeuser.make_user_db(**user)
 
87
    userobj = User(**user)
 
88
    store.add(userobj)
 
89
    enrol_user(store, userobj)
 
90
    store.commit()
85
91
except Exception, message:
86
92
    print "Error: " + str(message)
87
93
    sys.exit(1)