diff options
Diffstat (limited to 'scripts/mirror-repos')
-rw-r--r-- | scripts/mirror-repos | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/scripts/mirror-repos b/scripts/mirror-repos index b75555f..d013b14 100644 --- a/scripts/mirror-repos +++ b/scripts/mirror-repos @@ -8,12 +8,18 @@ import sys import urlparse import pwd +from tempfile import gettempdir + + # 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" +# Name for a lock file. +LOCK_FILE_NAME = "mirror-repos.lock" +LOCK_FILE = os.path.join(gettempdir(), LOCK_FILE_NAME) def args_parser(): @@ -159,7 +165,20 @@ if __name__ == '__main__': parser = args_parser() 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) + if os.path.exists(LOCK_FILE): + print "Another process is still running: cannot acquire lock." + else: + try: + with open(LOCK_FILE, 'w'): + mirror_repos(args.repos_list, + args.checkout_dir, + user=args.user) + + if args.rescan_repos: + print "Re-scanning git repositories directory..." + rescan_git_directory(args.api_key, + args.api_host, + user=args.user) + finally: + os.unlink(LOCK_FILE) |