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

« back to all changes in this revision

Viewing changes to lib/common/makeuser.py

  • Committer: wagrant
  • Date: 2008-07-17 04:28:35 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:906
editor.js: Warn before saving if the open file is an old revision.

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(path, throw_on_error=True):
63
 
    """Create a Subversion repository at the given path.
 
62
def make_svn_repo(login, throw_on_error=True):
 
63
    """Create a repository for the given user.
64
64
    """
 
65
    path = os.path.join(conf.svn_repo_path, login)
65
66
    try:
66
67
        res = os.system("svnadmin create '%s'" % path)
67
68
        if res != 0 and throw_on_error:
68
 
            raise Exception("Cannot create repository: %s" % path)
 
69
            raise Exception("Cannot create repository for %s" % login)
69
70
    except Exception, exc:
70
71
        print repr(exc)
71
72
        if throw_on_error:
77
78
    """Build the complete SVN configuration file.
78
79
    """
79
80
    conn = db.DB()
80
 
    users = conn.get_users()
 
81
    res = conn.query("SELECT login, rolenm FROM login;").dictresult()
81
82
    groups = {}
82
 
    for u in users:
83
 
        role = str(u.role)
 
83
    for r in res:
 
84
        role = r['rolenm']
84
85
        if role not in groups:
85
86
            groups[role] = []
86
 
        groups[role].append(u.login)
 
87
        groups[role].append(r['login'])
87
88
    f = open(conf.svn_conf + ".new", "w")
88
89
    f.write("# IVLE SVN Repositories Configuration\n")
89
90
    f.write("# Auto-generated on %s\n" % time.asctime())
92
93
    for (g,ls) in groups.iteritems():
93
94
        f.write("%s = %s\n" % (g, ",".join(ls)))
94
95
    f.write("\n")
95
 
    for u in users:
96
 
        f.write("[%s:/]\n" % u.login)
97
 
        f.write("%s = rw\n" % u.login)
 
96
    for r in res:
 
97
        login = r['login']
 
98
        f.write("[%s:/]\n" % login)
 
99
        f.write("%s = rw\n" % login)
98
100
        #f.write("@tutor = r\n")
99
101
        #f.write("@lecturer = rw\n")
100
102
        #f.write("@admin = rw\n")
103
105
    os.rename(conf.svn_conf + ".new", conf.svn_conf)
104
106
    chown_to_webserver(conf.svn_conf)
105
107
 
106
 
def rebuild_svn_group_config():
107
 
    """Build the complete SVN configuration file for groups
 
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.
108
111
    """
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())
 
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")
115
118
    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")
128
119
    f.close()
129
 
    os.rename(conf.svn_group_conf + ".new", conf.svn_group_conf)
130
 
    chown_to_webserver(conf.svn_group_conf)
 
120
    chown_to_webserver(conf.svn_conf)
131
121
 
132
122
def make_svn_auth(login, throw_on_error=True):
133
123
    """Setup svn authentication for the given user.
237
227
        shutil.rmtree(userdir)
238
228
        os.makedirs(homedir)
239
229
        shutil.move(homebackup, homedir)
240
 
        # Change the ownership of all the files to the right unixid
241
 
        logging.debug("chown %s's home directory files to uid %d"
242
 
            %(username, uid))
243
 
        os.chown(userhomedir, uid, uid)
244
 
        for root, dirs, files in os.walk(userhomedir):
245
 
            for fsobj in dirs + files:
246
 
                os.chown(os.path.join(root, fsobj), uid, uid)
247
230
    else:
248
231
        # No user jail exists
249
232
        # Set up the user's home directory