diff options
author | Milo Casagrande <milo@ubuntu.com> | 2013-02-07 13:33:33 +0100 |
---|---|---|
committer | Milo Casagrande <milo@ubuntu.com> | 2013-02-07 13:33:33 +0100 |
commit | 908370218370238e06faf90b19f078727c04fedb (patch) | |
tree | 8b87a178a57130de8292bd78bbb4ebc9f7bdb070 | |
parent | 80f7efda8d32cbfdea147461bc1cd481d23073ef (diff) |
Added script to update git repositories.
-rw-r--r-- | scripts/update-server-info | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/update-server-info b/scripts/update-server-info new file mode 100644 index 0000000..18db5b7 --- /dev/null +++ b/scripts/update-server-info @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Linaro Ltd. + +import argparse +import os +import re +import subprocess + + +# Match a directory that ends with .git, but not only .git +GIT_DIRECTORY_ENDS = re.compile(".+\.git$") +# Default path to the git repo. +DEFAULT_GIT_REPOS = "/opt/rhodecode/git_repos" +DEFAULT_USER = "rhodecode" + + +def args_parser(): + """Sets up the argument parser.""" + parser = argparse.ArgumentParser() + parser.add_argument("--repos-dir", + default=DEFAULT_GIT_REPOS, + help="The directory where repositories are stored.") + parser.add_argument("--user", + default=DEFAULT_USER, + help="User to run the commands as.") + return parser + + +def update_server_info(repos_dir, user): + for root, dirs, files in os.walk(os.path.abspath(repos_dir)): + if GIT_DIRECTORY_ENDS.match(root): + if files: + # We really are in a git repository. + cmd_args = [] + if user: + cmd_args = ["sudo", "-u", user, "-H"] + cmd_args += ["git", "update-server-info"] + process = subprocess.Popen(cmd_args, + cwd=root, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + p_out, p_err = process.communicate() + if process.returncode != 0: + print "Error executing command on directory %s." % root + else: + # git repositories always have a HEAD file, or it means they + # are empty. + continue + else: + # Directory looks like is not a git one. + continue + + +if __name__ == '__main__': + parser = args_parser() + args = parser.parse_args() + + update_server_info(args.repos_dir, args.user) |