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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: me at id
  • Date: 2009-01-15 05:45:05 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:1160
ivle.database.User: Order 'enrolments' the same way as 'active_enrolments'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
import filecmp
46
46
import logging
47
47
import ivle.conf
 
48
import ivle.db
48
49
import ivle.pulldown_subj
49
50
 
50
 
from ivle.database import ProjectGroup
51
 
 
52
51
def chown_to_webserver(filename):
53
52
    """
54
53
    Chowns a file so the web server user owns it.
106
105
def rebuild_svn_group_config(store):
107
106
    """Build the complete SVN configuration file for groups
108
107
    """
 
108
    conn = ivle.db.DB()
 
109
    groups = conn.get_all('project_group',
 
110
        ['groupid', 'groupnm', 'projectsetid'])
109
111
    f = open(ivle.conf.svn_group_conf + ".new", "w")
110
112
    f.write("# IVLE SVN Group Repositories Configuration\n")
111
113
    f.write("# Auto-generated on %s\n" % time.asctime())
112
114
    f.write("\n")
113
 
    for group in store.find(ProjectGroup):
114
 
        offering = group.project_set.offering
115
 
        reponame = "_".join([offering.subject.short_name,
116
 
                             offering.semester.year,
117
 
                             offering.semester.semester,
118
 
                             group.name])
 
115
    for g in groups:
 
116
        projectsetid = g['projectsetid']
 
117
        offeringinfo = conn.get_offering_info(projectsetid)
 
118
        subj_short_name = offeringinfo['subj_short_name']
 
119
        year = offeringinfo['year']
 
120
        semester = offeringinfo['semester']
 
121
        reponame = "_".join([subj_short_name, year, semester, g['groupnm']])
119
122
        f.write("[%s:/]\n"%reponame)
120
 
        for user in group.members:
121
 
            f.write("%s = rw\n" % user.login)
 
123
        users = conn.get_projectgroup_members(g['groupid'])
 
124
        for u in users:
 
125
            f.write("%s = rw\n"%u['login'])
122
126
        f.write("\n")
123
127
    f.close()
124
128
    os.rename(ivle.conf.svn_group_conf + ".new", ivle.conf.svn_group_conf)
304
308
                      % (username, unixid, unixid, username))
305
309
    passwd_file.close()
306
310
 
 
311
def make_user_db(throw_on_error = True, **kwargs):
 
312
    """Creates a user's entry in the database, filling in all the fields.
 
313
    All arguments must be keyword args. They are the fields in the table.
 
314
    However, instead of supplying a "passhash", you must supply a
 
315
    "password" argument, which will be hashed internally.
 
316
    Also do not supply a state. All users are created in the "no_agreement"
 
317
    state.
 
318
    Also pulls the user's subjects using the configured subject pulldown
 
319
    module, and adds enrolments to the DB.
 
320
    Throws an exception if the user already exists.
 
321
    """
 
322
    dbconn = ivle.db.DB()
 
323
    dbconn.create_user(**kwargs)
 
324
    dbconn.close()
 
325
 
 
326
    # Pulldown subjects and add enrolments
 
327
    ivle.pulldown_subj.enrol_user(kwargs['login'])
 
328
 
307
329
def mount_jail(login):
308
330
    # This is where we'll mount to...
309
331
    destdir = os.path.join(ivle.conf.jail_base, login)