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

« back to all changes in this revision

Viewing changes to lib/common/makeuser.py

  • Committer: mattgiuca
  • Date: 2008-02-19 06:10:53 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:503
user.py: Added acct_expired and pass_expired methods.
login.py: Removed has_expired function (now we put it inside the class)
    and called those methods instead.

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