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

« back to all changes in this revision

Viewing changes to lib/common/makeuser.py

  • Committer: mattgiuca
  • Date: 2008-05-11 05:11:09 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:754
listusers.py: Added options processing (now accepts -h and -n).
    If -n is given, just prints out a list of usernames, rather than
    all the user details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
import conf
43
43
import db
44
44
 
45
 
def make_svn_repo(login):
 
45
def make_svn_repo(login, throw_on_error=True):
46
46
    """Create a repository for the given user.
47
47
    """
48
48
    path = os.path.join(conf.svn_repo_path, login)
49
 
    res = os.system("svnadmin create '%s'" % path)
50
 
    if res != 0:
51
 
        raise Exception("Cannot create repository for %s" % login)
 
49
    try:
 
50
        res = os.system("svnadmin create '%s'" % path)
 
51
        if res != 0 and throw_on_error:
 
52
            raise Exception("Cannot create repository for %s" % login)
 
53
    except Exception, exc:
 
54
        print repr(exc)
 
55
        if throw_on_error:
 
56
            raise
 
57
    try:
 
58
        os.system("chown -R www-data:www-data %s" % path)
 
59
    except Exception:
 
60
        pass
52
61
 
53
62
def rebuild_svn_config():
54
63
    """Build the complete SVN configuration file.
73
82
        login = r['login']
74
83
        f.write("[%s:/]\n" % login)
75
84
        f.write("%s = rw\n" % login)
76
 
        f.write("@tutor = r\n")
77
 
        f.write("@lecturer = rw\n")
78
 
        f.write("@admin = rw\n")
 
85
        #f.write("@tutor = r\n")
 
86
        #f.write("@lecturer = rw\n")
 
87
        #f.write("@admin = rw\n")
79
88
        f.write("\n")
80
89
    f.close()
81
90
    os.rename(conf.svn_conf + ".new", conf.svn_conf)
82
91
 
83
 
def make_svn_config(login):
 
92
def make_svn_config(login, throw_on_error=True):
84
93
    """Add an entry to the apache-svn config file for the given user.
85
94
       Assumes the given user is either a guest or a student.
86
95
    """
87
96
    f = open(conf.svn_conf, "a")
88
97
    f.write("[%s:/]\n" % login)
89
98
    f.write("%s = rw\n" % login)
90
 
    f.write("@tutor = r\n")
91
 
    f.write("@lecturer = rw\n")
92
 
    f.write("@admin = rw\n")
 
99
    #f.write("@tutor = r\n")
 
100
    #f.write("@lecturer = rw\n")
 
101
    #f.write("@admin = rw\n")
93
102
    f.write("\n")
94
103
    f.close()
95
104
 
96
 
def make_svn_auth(login):
 
105
def make_svn_auth(login, throw_on_error=True):
97
106
    """Setup svn authentication for the given user.
98
107
       FIXME: create local.auth entry
99
108
    """
103
112
    else:
104
113
        create = "c"
105
114
 
106
 
    db.DB().update_user({'svn_pass':passwd})
 
115
    db.DB().update_user(login, svn_pass=passwd)
107
116
 
108
 
    res = os.system("htpasswd -%smb %s %s" % (create,
 
117
    res = os.system("htpasswd -%smb %s %s %s" % (create,
109
118
                                              conf.svn_auth_ivle,
110
119
                                              login, passwd))
111
 
    if res != 0:
 
120
    if res != 0 and throw_on_error:
112
121
        raise Exception("Unable to create ivle-auth for %s" % login)
113
122
 
 
123
    return passwd
 
124
 
114
125
def make_jail(username, uid, force=True):
115
126
    """Creates a new user's jail space, in the jail directory as configured in
116
127
    conf.py.
237
248
    if errors:
238
249
        raise Exception, errors
239
250
 
240
 
def make_user_db(**kwargs):
 
251
def make_user_db(throw_on_error = True, **kwargs):
241
252
    """Creates a user's entry in the database, filling in all the fields.
242
253
    All arguments must be keyword args. They are the fields in the table.
243
254
    However, instead of supplying a "passhash", you must supply a
249
260
    dbconn = db.DB()
250
261
    dbconn.create_user(**kwargs)
251
262
    dbconn.close()
 
263
 
 
264
    if kwargs['password']:
 
265
        if os.path.exists(conf.svn_auth_local):
 
266
            create = ""
 
267
        else:
 
268
            create = "c"
 
269
        res = os.system("htpasswd -%smb %s %s %s" % (create,
 
270
                                                     conf.svn_auth_local,
 
271
                                                     kwargs['login'],
 
272
                                                     kwargs['password']))
 
273
        if res != 0 and throw_on_error:
 
274
            raise Exception("Unable to create local-auth for %s" % kwargs['login'])
 
275