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, ])
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, ])
def create_web_dir(user): """Create web directory for user with appropriate permissions. 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. """ path = utils.web_dir(user) # create web directory subprocess.check_call([ 'sudo', 'install', '-d', '--mode=0755', '--group=ocf', '--owner=' + user, '--', path, ]) # symlink it from ~user/public_html subprocess.check_call([ 'sudo', '-u', user, 'ln', '-fs', '--', path, os.path.join(utils.home_dir(user), 'public_html'), ])
def create_web_dir(user): """Create web directory for user with appropriate permissions. 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. """ path = utils.web_dir(user) # create web directory subprocess.check_call([ 'sudo', 'install', '-d', '--mode=0755', '--group=ocf', '--owner=' + user, '--', path, ]) # symlink it from ~user/public_html subprocess.check_call([ 'sudo', '-u', user, 'ln', '-fs', '--', path, os.path.join(utils.home_dir(user), 'public_html'), ])
def test_web_dir_errors_bad_user(self, user): with pytest.raises(ValueError): web_dir(user)
def test_web_dir(self, user, expected): assert web_dir(user) == expected
def test_web_dir_errors_bad_user(self, user): with pytest.raises(ValueError): web_dir(user)
def test_web_dir(self, user, expected): assert web_dir(user) == expected