diff options
Diffstat (limited to 'scripts/update-repos')
-rw-r--r-- | scripts/update-repos | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/scripts/update-repos b/scripts/update-repos index 73a6539..154e0fa 100644 --- a/scripts/update-repos +++ b/scripts/update-repos @@ -6,9 +6,14 @@ import os import re import subprocess +from tempfile import gettempdir + # Match a directory that ends with .git, but not only .git GIT_DIRECTORY_ENDS = re.compile(".+\.git$") +# Name for a lock file. +LOCK_FILE_NAME = "update-repos.lock" +LOCK_FILE = os.path.join(gettempdir(), LOCK_FILE_NAME) def args_parser(): @@ -22,10 +27,8 @@ def args_parser(): return parser -if __name__ == '__main__': - parser = args_parser() - args = parser.parse_args() - +def fetch_updates(): + """Traverse the file system and fetc updates.""" for root, dirs, files in os.walk(os.path.abspath(args.repos_dir)): if GIT_DIRECTORY_ENDS.match(root): if files: @@ -49,3 +52,17 @@ if __name__ == '__main__': # git repositories always have a HEAD file, or it means they # are empty. continue + + +if __name__ == '__main__': + parser = args_parser() + args = parser.parse_args() + + if os.path.exists(LOCK_FILE): + print "Another process is still running: cannot acquire lock." + else: + try: + with open(LOCK_FILE, 'w'): + fetch_updates() + finally: + os.unlink(LOCK_FILE) |