Ejemplo n.º 1
0
def send_out(user, config):
    """
    Copies material to user account and makes the user owner of it.

    Parameters
    ----------
    user: `dict`
        A dictionary as parsed from the database describing a user.
    config: `dict`
        A dictionary as parsed from the configuration file.
    """
    # must not fail
    pw_entry = pwd.getpwnam(user["username"])
    # copy content of material dir into user directory
    destination_path = os.path.normpath(os.path.join(pw_entry.pw_dir,
            config["tutorial dir"]))
    material = os.path.basename(config["material dir"])
    if not material:
        material = os.path.dirname(config["material dir"])
    try:
        gutil.interactive_tree_copy(config["material dir"],
                os.path.join(destination_path, material))
    except shutil.Error:
        raise OSError(errno.ENOENT,
                u"copying files for user '{0}' failed".format(user["username"]))
    # change the owner of the files in the user directory
    gutil.tree_chown(pw_entry, destination_path)
Ejemplo n.º 2
0
def retrieve_from(user, config):
    """
    Retrieve all data in the material directory of the user.

    Parameters
    ----------
    user: `dict`
        A dictionary as parsed from the database describing a user.
    config: `dict`
        A dictionary as parsed from the configuration file.
    """
    # retrieve user generated material
    try:
        pw_entry = pwd.getpwnam(user["username"])
    except KeyError:
        LOGGER.debug(u"pssst:", exc_info=True)
        LOGGER.warn(u"Failed to get passwd entry for '{0}'."\
                .format(user["username"]))
        return
    source_path = os.path.normpath(os.path.join(pw_entry.pw_dir,
            config["tutorial dir"]))
    material = os.path.basename(config["material dir"])
    if not material:
        material = os.path.dirname(config["material dir"])
    dest_path = os.path.join(config["storage dir"], user["username"])
    try:
        gutil.tree_copy(source_path, dest_path)
    except shutil.Error:
        LOGGER.debug(u"pssst:", exc_info=True)
        LOGGER.warn(u"Retrieving files for user '{0}' failed."\
                .format(user["username"]))
    user["port"] = u""
    # change the owner of the files in the storage directory
    try:
        owner_entry = pwd.getpwnam(config["owner"])
    except KeyError:
        LOGGER.warn(u"Failed to get passwd entry for owner '{0}',"\
                u" did you set it in the config file?".format(config["owner"]))
        return
    gutil.tree_chown(owner_entry, dest_path)