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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: William Grant
  • Date: 2009-04-30 01:51:44 UTC
  • Revision ID: grantw@unimelb.edu.au-20090430015144-eewmf8nnpqah9hrs
Use some multiline strings to make ivle.makeuser prettier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import logging
28
28
import subprocess
29
29
 
30
 
from ivle.database import ProjectGroup
 
30
import ivle.config
 
31
from ivle.database import ProjectGroup, User
31
32
 
32
33
def chown_to_webserver(filename):
33
34
    """chown a directory and its contents to the web server.
55
56
 
56
57
    @param config: An ivle.config.Config object.
57
58
    """
58
 
    users = store.find(ivle.database.User)
59
 
    groups = {}
60
 
    # TODO: Populate groups with per-offering tutors/lecturers/etc.
 
59
    users = store.find(User)
61
60
    conf_name = config['paths']['svn']['conf']
62
61
    temp_name = conf_name + ".new"
63
62
    f = open(temp_name, "w")
64
 
    f.write("# IVLE SVN Repositories Configuration\n")
65
 
    f.write("# Auto-generated on %s\n" % time.asctime())
66
 
    f.write("\n")
67
 
    f.write("[groups]\n")
68
 
    for (g,ls) in groups.iteritems():
69
 
        f.write("%s = %s\n" % (g, ",".join(ls)))
70
 
    f.write("\n")
 
63
    f.write("""\
 
64
# IVLE SVN repository authorisation configuration
 
65
# Generated: %(time)s
 
66
""" % {'time': time.asctime()})
 
67
 
71
68
    for u in users:
72
 
        f.write("[%s:/]\n" % u.login)
73
 
        f.write("%s = rw\n" % u.login)
74
 
        #f.write("@tutor = r\n")
75
 
        #f.write("@lecturer = rw\n")
76
 
        #f.write("@admin = rw\n")
77
 
        f.write("\n")
 
69
        f.write("""
 
70
[%(login)s:/]
 
71
%(login)s = rw
 
72
""" % {'login': u.login})
 
73
 
78
74
    f.close()
79
75
    os.rename(temp_name, conf_name)
80
76
    chown_to_webserver(conf_name)
87
83
    conf_name = config['paths']['svn']['group_conf']
88
84
    temp_name = conf_name + ".new"
89
85
    f = open(temp_name, "w")
90
 
    f.write("# IVLE SVN Group Repositories Configuration\n")
91
 
    f.write("# Auto-generated on %s\n" % time.asctime())
92
 
    f.write("\n")
 
86
 
 
87
    f.write("""\
 
88
# IVLE SVN group repository authorisation configuration
 
89
# Generated: %(time)s
 
90
 
 
91
""" % {'time': time.asctime()})
 
92
 
93
93
    for group in store.find(ProjectGroup):
94
94
        offering = group.project_set.offering
95
95
        reponame = "_".join([offering.subject.short_name,
96
96
                             offering.semester.year,
97
97
                             offering.semester.semester,
98
98
                             group.name])
99
 
        f.write("[%s:/]\n"%reponame)
 
99
 
 
100
        f.write("[%s:/]\n" % reponame)
100
101
        for user in group.members:
101
102
            f.write("%s = rw\n" % user.login)
102
103
        f.write("\n")
 
104
 
103
105
    f.close()
104
106
    os.rename(temp_name, conf_name)
105
107
    chown_to_webserver(conf_name)
118
120
    else:
119
121
        create = "c"
120
122
 
121
 
    user = ivle.database.User.get_by_login(store, login)
 
123
    user = User.get_by_login(store, login)
122
124
    user.svn_pass = unicode(passwd)
123
125
 
124
126
    res = subprocess.call(['htpasswd', '-%smb' % create,