diff options
author | Milo Casagrande <milo@ubuntu.com> | 2013-01-23 13:26:17 +0100 |
---|---|---|
committer | Milo Casagrande <milo@ubuntu.com> | 2013-01-23 13:26:17 +0100 |
commit | 8effaebcc2e50d57ce0afb1a47757882303c9688 (patch) | |
tree | f2873cb2eec999853e874de1d5928568af3b4561 /scripts/rhodecode-setup | |
parent | 8b13b001b6e80764f464c43244b997f0387c2dfe (diff) |
Reworked functions to setp directories and permissions.
Diffstat (limited to 'scripts/rhodecode-setup')
-rw-r--r-- | scripts/rhodecode-setup | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/scripts/rhodecode-setup b/scripts/rhodecode-setup index 5d7b300..c24c963 100644 --- a/scripts/rhodecode-setup +++ b/scripts/rhodecode-setup @@ -187,26 +187,17 @@ def setup_user(user, home_dir, group): execute_command(cmd_args) -def setup_directories(data_dir, repos_dir, celery_log_dir, rhodecode_usr): - if not os.path.exists(data_dir): - cmd_args = ["mkdir", "-p", data_dir] - execute_command(cmd_args) - - if not os.path.exists(repos_dir): - cmd_args = ["mkdir", "-p", repos_dir] - execute_command(cmd_args) - - if not os.path.exists(celery_log_dir): - cmd_args = ["mkdir", "-p", celery_log_dir] - execute_command(cmd_args) - - # Set ownership of the directories to the RhodeCode user. - set_owners(data_dir, rhodecode_usr) - - set_owners(repos_dir, rhodecode_usr) +def setup_directories(directories, rhodecode_usr): + """Sets up the correct necessary directories.""" + if not isinstance(directories, list): + directories = [directories] - set_owners(celery_log_dir, rhodecode_usr) - set_permissions(celery_log_dir, "g+w") + for directory in directories: + if not os.path.exists(directory): + cmd_args = ["mkdir", "-p", directory] + execute_command(cmd_args) + # Set ownership of the directories to the RhodeCode user. + set_owners(directory, rhodecode_usr) def execute_command(cmd_args, @@ -412,13 +403,16 @@ def set_owners(directory, usr, group=None): def set_permissions(file_or_dir, permissions): """Sets the permissions on the given path. - :param file_or_dir: The path to what the permissions should be set. - :type str + :param file_or_dir: A list of paths to set the permissions. + :type list :param permissions: String containing the permissions as passed to the 'chmod' command. """ - cmd_args = ["chmod", "-R", permissions, file_or_dir] - execute_command(cmd_args) + if not isinstance(file_or_dir, list): + file_or_dir = [file_or_dir] + for element in file_or_dir: + cmd_args = ["chmod", "-R", permissions, element] + execute_command(cmd_args) def install_rhodecode(work_dir, user=None): @@ -547,10 +541,15 @@ if __name__ == '__main__': setup_user(args.rhodecode_usr, home_dir, args.rhodecode_usr) # Create the necessary directories to store RhodeCode data and cache. - setup_directories(args.rhodecode_data_dir, - args.repos_dir, - args.celery_log_dir, - args.rhodecode_usr) + directories = [args.rhodecode_data_dir, args.repos_dir] + if not args.no_celery: + directories.append(args.celery_log_dir) + + setup_directories(directories, args.rhodecode_usr) + + # Set the correct permissions to the directories, at least the group + # should be able to write. + set_permissions(directories, "g+w") # Take git-core package from Launchpad PPA of git maintainers. install_git_from_ppa(assume_yes=args.assume_yes) |