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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: Matt Giuca
  • Date: 2009-03-24 06:50:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090324065039-5c6xkjeb8x2f5d01
doc/conf.py: Renamed project from "ivle" to "IVLE". (Turns out this is a
    friendly name).

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    """
80
80
    users = store.find(ivle.database.User)
81
81
    groups = {}
82
 
    for u in users:
83
 
        role = str(u.role)
84
 
        if role not in groups:
85
 
            groups[role] = []
86
 
        groups[role].append(u.login)
 
82
    # TODO: Populate groups with per-offering tutors/lecturers/etc.
87
83
    f = open(ivle.conf.svn_conf + ".new", "w")
88
84
    f.write("# IVLE SVN Repositories Configuration\n")
89
85
    f.write("# Auto-generated on %s\n" % time.asctime())
197
193
        raise Exception("Must run make_jail as root")
198
194
    
199
195
    # tempdir is for putting backup homes in
200
 
    tempdir = os.path.join(ivle.conf.jail_base, '__temp__')
 
196
    tempdir = os.path.join(ivle.conf.jail_src_base, '__temp__')
201
197
    if not os.path.exists(tempdir):
202
198
        os.makedirs(tempdir)
203
199
    elif not os.path.isdir(tempdir):
227
223
        # Change the ownership of all the files to the right unixid
228
224
        logging.debug("chown %s's home directory files to uid %d"
229
225
            %(user.login, user.unixid))
230
 
        os.chown(userhomedir, user.unixid, user.unixid)
231
 
        for root, dirs, files in os.walk(userhomedir):
232
 
            for fsobj in dirs + files:
233
 
                os.chown(os.path.join(root, fsobj), user.unixid, user.unixid)
 
226
        os.spawnvp(os.P_WAIT, 'chown', ['chown', '-R', '%d:%d' % (user.unixid,
 
227
                                        user.unixid), userhomedir])
234
228
    else:
235
229
        # No user jail exists
236
230
        # Set up the user's home directory
240
234
        # Chmod to rwxr-xr-x (755)
241
235
        os.chmod(userhomedir, 0755)
242
236
 
243
 
    make_conf_py(user.login, userdir, ivle.conf.jail_system, user.svn_pass)
 
237
    make_conf_py(user.login, userdir, user.svn_pass)
244
238
    make_etc_passwd(user.login, userdir, ivle.conf.jail_system, user.unixid)
245
239
 
246
240
    return userhomedir
247
241
 
248
 
def make_conf_py(username, user_jail_dir, staging_dir, svn_pass):
 
242
def make_conf_py(username, user_jail_dir, svn_pass):
249
243
    """
250
244
    Creates (overwriting any existing file, and creating directories) a
251
245
    file ${python_site_packages}/ivle/conf/conf.py in a given user's jail.
252
246
    username: Username.
253
247
    user_jail_dir: User's jail dir, ie. ivle.conf.jail_base + username
254
 
    staging_dir: The dir with the staging copy of the jail. (With the
255
 
        template conf.py file).
256
 
    svn_pass: As with make_jail. User's SVN password, but if not supplied,
257
 
        will look up in the DB.
 
248
    svn_pass: User's SVN password.
258
249
    """
259
 
    template_conf_path = os.path.join(staging_dir,
260
 
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
261
250
    conf_path = os.path.join(user_jail_dir,
262
251
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
263
252
    os.makedirs(os.path.dirname(conf_path))
264
253
 
265
 
    # Read the contents of the template conf file
266
 
    try:
267
 
        template_conf_file = open(template_conf_path, "r")
268
 
        template_conf_data = template_conf_file.read()
269
 
        template_conf_file.close()
270
 
    except:
271
 
        # Couldn't open template conf.py for some reason
272
 
        # Just treat it as empty file
273
 
        template_conf_data = ("# Warning: Problem building config script.\n"
274
 
                              "# Could not find template conf.py file.\n")
 
254
    # In the "in-jail" version of conf, we don't need MOST of the details
 
255
    # (it would be a security risk to have them here).
 
256
    # So we just write root_dir, and jail_base is "/".
 
257
    # (jail_base being "/" means "jail-relative" paths are relative to "/"
 
258
    # when inside the jail.)
275
259
 
 
260
    # XXX: jail_base is wrong and shouldn't be here. Unfortunately, jail code
 
261
    #      uses ivle.studpath.url_to_{local,jailpaths}, both of which use
 
262
    #      jail_base. Note that they don't use the bits of the return value
 
263
    #      that depend on jail_base, so it can be any string.
276
264
    conf_file = open(conf_path, "w")
277
 
    conf_file.write(template_conf_data)
278
 
    conf_file.write("\n# The login name for the owner of the jail\n")
279
 
    conf_file.write("login = %s\n" % repr(username))
280
 
    conf_file.write("\n")
281
 
    conf_file.write("# The subversion-only password for the owner of "
282
 
        "the jail\n")
283
 
    conf_file.write("svn_pass = %s\n" % repr(svn_pass))
 
265
    conf_file.write("""# IVLE jail configuration
 
266
 
 
267
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
 
268
# with this).
 
269
# eg. "/" or "/ivle".
 
270
root_dir = %(root_dir)r
 
271
 
 
272
# This value is not relevant inside the jail, but must remain for now. See
 
273
# the XXX in ivle.makeuser.make_conf_py.
 
274
jail_base = '/'
 
275
 
 
276
# The hostname for serving publicly accessible pages
 
277
public_host = %(public_host)r
 
278
 
 
279
# The URL under which the Subversion repositories are located.
 
280
svn_addr = %(svn_addr)r
 
281
 
 
282
# The login name for the owner of the jail
 
283
login = %(username)r
 
284
 
 
285
# The subversion-only password for the owner of the jail
 
286
svn_pass = %(svn_pass)r
 
287
""" % {'root_dir': ivle.conf.root_dir,
 
288
       'public_host': ivle.conf.public_host,
 
289
       'svn_addr': ivle.conf.svn_addr,
 
290
       'username': username,
 
291
       'svn_pass': svn_pass,
 
292
      })
284
293
    conf_file.close()
285
294
 
286
295
    # Make this file world-readable