aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMilo Casagrande <milo@ubuntu.com>2013-01-29 19:04:59 +0100
committerMilo Casagrande <milo@ubuntu.com>2013-01-29 19:04:59 +0100
commitcee289ddd70ea6316918b7609751b2a0d0f4dbaf (patch)
treee5f829a4464572f955f66cec0150166dac111c9b /scripts
parent3b1532462c14c0cfd0628fcabc25073609ebbd8d (diff)
parentb73d49839dca960cfe2715163b8553e9d9b2f388 (diff)
Merge branch 'milo'
Diffstat (limited to 'scripts')
-rw-r--r--scripts/mirror-repos53
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/mirror-repos b/scripts/mirror-repos
index ffa4d5d..b75555f 100644
--- a/scripts/mirror-repos
+++ b/scripts/mirror-repos
@@ -6,8 +6,14 @@ import os
import subprocess
import sys
import urlparse
+import pwd
+# Default read-only git URL.
BASE_PATH = "http://git.linaro.org/git-ro/"
+# Path to local bin directory, %s is the user name.
+LOCAL_BIN_DIR = "/home/%s/.local/bin"
+# Default API host for RhodeCode.
+DEFAULT_API_HOST = "http://0.0.0.0:5000"
def args_parser():
@@ -21,6 +27,17 @@ def args_parser():
help="Where git repositories will be cloned.")
parser.add_argument("--user",
help="User to run the commands as.")
+ parser.add_argument("--rescan-repos",
+ action="store_true",
+ help="If the directory containing repositories "
+ "should be re-scanned when adding new ones.")
+ parser.add_argument("--api-key",
+ help="The RhodeCode API key to use for re-scanning "
+ "the repositories.")
+ parser.add_argument("--api-host",
+ default=DEFAULT_API_HOST,
+ help="The host URL where API interface is located. "
+ "Defaults to '%s'." % DEFAULT_API_HOST)
return parser
@@ -44,6 +61,17 @@ def check_args(args, parser):
parser.print_usage()
sys.exit(1)
+ if args.rescan_repos:
+ if not args.api_key:
+ print ("It is necessary to specify the API key of the admin user "
+ "to perform the rescan operation.")
+ parser.print_usage()
+ sys.exit(1)
+ # Just print a warning...
+ if args.api_host == DEFAULT_API_HOST:
+ print ("Warning: default API host will be used: "
+ "%s" % DEFAULT_API_HOST)
+
def mirror_repos(file, dest, user=None):
"""Clone a mirror copy of a remote repository from git.linaro.org.
@@ -76,6 +104,28 @@ def mirror_repos(file, dest, user=None):
execute_command(cmd_args, work_dir=full_path, user=user)
+def rescan_git_directory(api_key, api_host, user=None):
+ """Rescans git directories for new repositories added.
+
+ :param api_key: The RhodeCode API key.
+ :type str
+ :param api_host: The RhodeCode host where to run the remote command.
+ :type str
+ :param user: The user to run the command as.
+ :type str
+ """
+ if not user:
+ # Try to gess a user.
+ user = pwd.getpwuid(os.getuid())[0]
+
+ api_key_cmd = "--apikey=%s" % str(api_key)
+ api_host_cmd = "--apihost=%s" % api_host
+
+ api_cmd = os.path.join(LOCAL_BIN_DIR % user, "rhodecode-api")
+ cmd_args = [api_cmd, api_key_cmd, api_host_cmd, "rescan_repos"]
+ execute_command(cmd_args, user=user)
+
+
def execute_command(cmd_args, as_sudo=True, user=None, work_dir=os.getcwd()):
"""Executes the command using Popen.
@@ -110,3 +160,6 @@ if __name__ == '__main__':
args = parser.parse_args()
check_args(args, parser)
mirror_repos(args.repos_list, args.checkout_dir, user=args.user)
+
+ if args.rescan_repos:
+ rescan_git_directory(args.api_key, args.api_host, user=args.user)