aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo@ubuntu.com>2013-01-30 14:14:35 +0100
committerMilo Casagrande <milo@ubuntu.com>2013-01-30 14:14:35 +0100
commitfdf40ec232de2b826c13807c74952373d3f549d9 (patch)
tree72a8982ce963281c3bc28516e43e7bb52f7565e0
parent32c1fbcb5b5e5eb8d2eafd1f1294bb5a4a70c178 (diff)
downloadrhodecode-config-fdf40ec232de2b826c13807c74952373d3f549d9.tar.gz
Fixed try-finally block, fixed lock file name.
-rw-r--r--scripts/mirror-repos24
1 files changed, 21 insertions, 3 deletions
diff --git a/scripts/mirror-repos b/scripts/mirror-repos
index b75555f..3b5f842 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,19 @@ 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:
+ rescan_git_directory(args.api_key,
+ args.api_host,
+ user=args.user)
+ finally:
+ os.unlink(LOCK_FILE)