diff options
-rw-r--r-- | scripts/mirror-repos | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/scripts/mirror-repos b/scripts/mirror-repos index 22228ed..73a1d4b 100644 --- a/scripts/mirror-repos +++ b/scripts/mirror-repos @@ -12,7 +12,8 @@ import urlparse from logging.handlers import TimedRotatingFileHandler from tempfile import gettempdir - +# Default user for operations. +DEFAULT_USER = "rhodecode" # Default read-only git URL. BASE_PATH = "http://git.linaro.org/git-ro/" # Path to local bin directory, %s is the user name. @@ -169,19 +170,24 @@ def rescan_git_directory(api_key, api_host, user=None): :param user: The user to run the command as. :type str """ - if not user: + if user: + bin_dir = LOCAL_BIN_DIR % user + else: # Try to gess a user. - user = pwd.getpwuid(os.getuid())[0] + bin_dir = LOCAL_BIN_DIR % pwd.getpwuid(os.getuid())[0] - api_key_cmd = "--apikey=%s" % str(api_key) + api_key_cmd = "--apikey=%s" % api_key api_host_cmd = "--apihost=%s" % api_host - api_cmd = os.path.join(LOCAL_BIN_DIR % user, "rhodecode-api") + api_cmd = os.path.join(bin_dir, "rhodecode-api") cmd_args = [api_cmd, api_key_cmd, api_host_cmd, "rescan_repos"] - execute_command(cmd_args, user=user) + if user == DEFAULT_USER: + execute_command(cmd_args) + else: + execute_command(cmd_args, as_sudo=True, user=user) -def execute_command(cmd_args, as_sudo=True, user=None, work_dir=os.getcwd()): +def execute_command(cmd_args, as_sudo=False, user=None, work_dir=os.getcwd()): """Executes the command using Popen. :param cmd_args: The list of command and parameters to run. |