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

« back to all changes in this revision

Viewing changes to lib/common/makeuser.py

  • Committer: wagrant
  • Date: 2008-08-19 12:49:58 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1031
Example worksheets: Fix the element names in worksheet 1 to be actually
                    correct. Also fix the first exercise so it too
                    functions properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    except:
60
60
        pass
61
61
 
62
 
def make_svn_repo(login, throw_on_error=True):
63
 
    """Create a repository for the given user.
 
62
def make_svn_repo(path, throw_on_error=True):
 
63
    """Create a Subversion repository at the given path.
64
64
    """
65
 
    path = os.path.join(conf.svn_repo_path, login)
66
65
    try:
67
66
        res = os.system("svnadmin create '%s'" % path)
68
67
        if res != 0 and throw_on_error:
69
 
            raise Exception("Cannot create repository for %s" % login)
 
68
            raise Exception("Cannot create repository: %s" % path)
70
69
    except Exception, exc:
71
70
        print repr(exc)
72
71
        if throw_on_error:
78
77
    """Build the complete SVN configuration file.
79
78
    """
80
79
    conn = db.DB()
81
 
    res = conn.query("SELECT login, rolenm FROM login;").dictresult()
 
80
    users = conn.get_users()
82
81
    groups = {}
83
 
    for r in res:
84
 
        role = r['rolenm']
 
82
    for u in users:
 
83
        role = str(u.role)
85
84
        if role not in groups:
86
85
            groups[role] = []
87
 
        groups[role].append(r['login'])
 
86
        groups[role].append(u.login)
88
87
    f = open(conf.svn_conf + ".new", "w")
89
88
    f.write("# IVLE SVN Repositories Configuration\n")
90
89
    f.write("# Auto-generated on %s\n" % time.asctime())
93
92
    for (g,ls) in groups.iteritems():
94
93
        f.write("%s = %s\n" % (g, ",".join(ls)))
95
94
    f.write("\n")
96
 
    for r in res:
97
 
        login = r['login']
98
 
        f.write("[%s:/]\n" % login)
99
 
        f.write("%s = rw\n" % login)
 
95
    for u in users:
 
96
        f.write("[%s:/]\n" % u.login)
 
97
        f.write("%s = rw\n" % u.login)
100
98
        #f.write("@tutor = r\n")
101
99
        #f.write("@lecturer = rw\n")
102
100
        #f.write("@admin = rw\n")
105
103
    os.rename(conf.svn_conf + ".new", conf.svn_conf)
106
104
    chown_to_webserver(conf.svn_conf)
107
105
 
108
 
def make_svn_config(login, throw_on_error=True):
109
 
    """Add an entry to the apache-svn config file for the given user.
110
 
       Assumes the given user is either a guest or a student.
 
106
def rebuild_svn_group_config():
 
107
    """Build the complete SVN configuration file for groups
111
108
    """
112
 
    f = open(conf.svn_conf, "a")
113
 
    f.write("[%s:/]\n" % login)
114
 
    f.write("%s = rw\n" % login)
115
 
    #f.write("@tutor = r\n")
116
 
    #f.write("@lecturer = rw\n")
117
 
    #f.write("@admin = rw\n")
 
109
    conn = db.DB()
 
110
    groups = conn.get_all('project_group',
 
111
        ['groupid', 'groupnm', 'projectsetid'])
 
112
    f = open(conf.svn_group_conf + ".new", "w")
 
113
    f.write("# IVLE SVN Group Repositories Configuration\n")
 
114
    f.write("# Auto-generated on %s\n" % time.asctime())
118
115
    f.write("\n")
 
116
    for g in groups:
 
117
        projectsetid = g['projectsetid']
 
118
        offeringinfo = conn.get_offering_info(projectsetid)
 
119
        subj_short_name = offeringinfo['subj_short_name']
 
120
        year = offeringinfo['year']
 
121
        semester = offeringinfo['semester']
 
122
        reponame = "_".join([subj_short_name, year, semester, g['groupnm']])
 
123
        f.write("[%s:/]\n"%reponame)
 
124
        users = conn.get_projectgroup_members(g['groupid'])
 
125
        for u in users:
 
126
            f.write("%s = rw\n"%u['login'])
 
127
        f.write("\n")
119
128
    f.close()
120
 
    chown_to_webserver(conf.svn_conf)
 
129
    os.rename(conf.svn_group_conf + ".new", conf.svn_group_conf)
 
130
    chown_to_webserver(conf.svn_group_conf)
121
131
 
122
132
def make_svn_auth(login, throw_on_error=True):
123
133
    """Setup svn authentication for the given user.