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

« back to all changes in this revision

Viewing changes to bin/ivle-makeuser

  • Committer: me at id
  • Date: 2009-01-15 05:53:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1161
bin/ivle-showenrolment: Switch to ivle.database.User.enrolments from
    ivle.db.get_enrolment, removing the dependency on ivle.db.

Show diffs side-by-side

added added

removed removed

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