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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: William Grant
  • Date: 2009-02-23 23:47:02 UTC
  • mfrom: (1099.1.211 new-dispatch)
  • Revision ID: grantw@unimelb.edu.au-20090223234702-db4b1llly46ignwo
Merge from lp:~ivle-dev/ivle/new-dispatch.

Pretty much everything changes. Reread the setup docs. Backup your databases.
Every file is now in a different installed location, the configuration system
is rewritten, the dispatch system is rewritten, URLs are different, the
database is different, worksheets and exercises are no longer on the
filesystem, we use a templating engine, jail service protocols are rewritten,
we don't repeat ourselves, we have authorization rewritten, phpBB is gone,
and probably lots of other things that I cannot remember.

This is certainly the biggest commit I have ever made, and hopefully
the largest I ever will.

Show diffs side-by-side

added added

removed removed

Lines of Context:
240
240
        # Chmod to rwxr-xr-x (755)
241
241
        os.chmod(userhomedir, 0755)
242
242
 
243
 
    make_conf_py(user.login, userdir, ivle.conf.jail_system, user.svn_pass)
 
243
    make_conf_py(user.login, userdir, user.svn_pass)
244
244
    make_etc_passwd(user.login, userdir, ivle.conf.jail_system, user.unixid)
245
245
 
246
246
    return userhomedir
247
247
 
248
 
def make_conf_py(username, user_jail_dir, staging_dir, svn_pass):
 
248
def make_conf_py(username, user_jail_dir, svn_pass):
249
249
    """
250
250
    Creates (overwriting any existing file, and creating directories) a
251
251
    file ${python_site_packages}/ivle/conf/conf.py in a given user's jail.
252
252
    username: Username.
253
253
    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.
 
254
    svn_pass: User's SVN password.
258
255
    """
259
 
    template_conf_path = os.path.join(staging_dir,
260
 
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
261
256
    conf_path = os.path.join(user_jail_dir,
262
257
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
263
258
    os.makedirs(os.path.dirname(conf_path))
264
259
 
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")
 
260
    # In the "in-jail" version of conf, we don't need MOST of the details
 
261
    # (it would be a security risk to have them here).
 
262
    # So we just write root_dir, and jail_base is "/".
 
263
    # (jail_base being "/" means "jail-relative" paths are relative to "/"
 
264
    # when inside the jail.)
275
265
 
 
266
    # XXX: jail_base is wrong and shouldn't be here. Unfortunately, jail code
 
267
    #      uses ivle.studpath.url_to_{local,jailpaths}, both of which use
 
268
    #      jail_base. Note that they don't use the bits of the return value
 
269
    #      that depend on jail_base, so it can be any string.
276
270
    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))
 
271
    conf_file.write("""# IVLE jail configuration
 
272
 
 
273
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
 
274
# with this).
 
275
# eg. "/" or "/ivle".
 
276
root_dir = %(root_dir)r
 
277
 
 
278
# This value is not relevant inside the jail, but must remain for now. See
 
279
# the XXX in ivle.makeuser.make_conf_py.
 
280
jail_base = '/'
 
281
 
 
282
# The hostname for serving publicly accessible pages
 
283
public_host = %(public_host)r
 
284
 
 
285
# The URL under which the Subversion repositories are located.
 
286
svn_addr = %(svn_addr)r
 
287
 
 
288
# The login name for the owner of the jail
 
289
login = %(username)r
 
290
 
 
291
# The subversion-only password for the owner of the jail
 
292
svn_pass = %(svn_pass)r
 
293
""" % {'root_dir': ivle.conf.root_dir,
 
294
       'public_host': ivle.conf.public_host,
 
295
       'svn_addr': ivle.conf.svn_addr,
 
296
       'username': username,
 
297
       'svn_pass': svn_pass,
 
298
      })
284
299
    conf_file.close()
285
300
 
286
301
    # Make this file world-readable