Beispiel #1
0
def ensure_web_dir(user):
    """Ensure user has web directory with appropriate permissions and
    public_html symlink.

    All users are given a working web directory and public_html symlink at
    account creation. They can later use `makehttp` to fix these if they bork
    the permissions or symlink. If there is already a file in the user's home
    folder named 'public_html', it will be renamed by appending a timestamp.
    """
    path = utils.web_dir(user)

    # ensure web directory exists and has the right permissiosn
    subprocess.check_call([
        'sudo', 'install',
        '-d', '--mode=0755', '--group=ocf', '--owner=' + user,
        '--',
        path,
    ])

    public_html_path = utils.public_html_path(user)

    # rename any existing files named ~user/public_html
    if os.path.exists(public_html_path) and os.path.realpath(public_html_path) != path:
        timestamp = datetime.now().strftime('%m%d%Y-%H%M%S')
        subprocess.check_call([
            'sudo', 'mv', public_html_path, public_html_path + '.' + timestamp,
        ])

    # symlink web dir from ~user/public_html
    subprocess.check_call([
        'sudo', '-u', user,
        'ln', '-fs', '--', path, public_html_path,
    ])
Beispiel #2
0
def ensure_web_dir(user):
    """Ensure user has web directory with appropriate permissions and
    public_html symlink.

    All users are given a working web directory and public_html symlink at
    account creation. They can later use `makehttp` to fix these if they bork
    the permissions or symlink. If there is already a file in the user's home
    folder named 'public_html', it will be renamed by appending a timestamp.
    """
    path = utils.web_dir(user)

    # ensure web directory exists and has the right permissiosn
    subprocess.check_call([
        'sudo', 'install',
        '-d', '--mode=0755', '--group=ocf', '--owner=' + user,
        '--',
        path,
    ])

    public_html_path = utils.public_html_path(user)

    # rename any existing files named ~user/public_html
    if os.path.exists(public_html_path) and os.path.realpath(public_html_path) != path:
        timestamp = datetime.now().strftime('%m%d%Y-%H%M%S')
        subprocess.check_call([
            'sudo', 'mv', public_html_path, public_html_path + '.' + timestamp,
        ])

    # symlink web dir from ~user/public_html
    subprocess.check_call([
        'sudo', '-u', user,
        'ln', '-fs', '--', path, public_html_path,
    ])