aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo@ubuntu.com>2013-01-25 13:58:13 +0100
committerMilo Casagrande <milo@ubuntu.com>2013-01-25 14:00:21 +0100
commit3116ad2c4f4d5398b717463f26bf4366305792e9 (patch)
tree72c702f1046c450c924617e8ad90d83d7bf0d898
parente1c6c49d20afe234a0e85621420e79da606319db (diff)
Added script to update mirrored repositories.
-rw-r--r--scripts/update-repos49
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/update-repos b/scripts/update-repos
new file mode 100644
index 0000000..e727252
--- /dev/null
+++ b/scripts/update-repos
@@ -0,0 +1,49 @@
+#!/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")
+
+
+def args_parser():
+ """Sets up the argument parser."""
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--repos-dir",
+ required=True,
+ help="The directory where repositories are stored.")
+ parser.add_argument("--user",
+ help="User to run the commands as.")
+ return parser
+
+
+if __name__ == '__main__':
+ parser = args_parser()
+ args = parser.parse_args()
+
+ for root, dirs, files in os.walk(os.path.abspath(args.repos_dir)):
+ if GIT_DIRECTORY_ENDS.match(root):
+ if files:
+ # We really are in a git repository.
+ cmd_args = []
+ if args.user:
+ cmd_args = ["sudo", "-u", args.user, "-H"]
+ cmd_args += ["git", "fetch", "--all", "-q"]
+ process = subprocess.Popen(cmd_args,
+ cwd=root,
+ stout=subprocess.Pipe,
+ stderr=subprocess.Pipe)
+
+ p_out, p_err = process.communicate()
+ if process.returncode != 0:
+ print ("Error fetching updates for repository '%s'" % \
+ os.path.basename(root))
+ else:
+ # git repositories always have a HEAD file, or it means they
+ # are empty.
+ continue