aboutsummaryrefslogtreecommitdiff
path: root/update-gerrit-parents.py
diff options
context:
space:
mode:
authorPaul Sokolovsky <paul.sokolovsky@linaro.org>2016-04-21 00:13:27 +0300
committerPaul Sokolovsky <paul.sokolovsky@linaro.org>2016-05-10 22:01:53 +0300
commit909611172fd7aca4ddb1729f886cc3bd83f012b5 (patch)
treea5d0c49ab7830b37e69595e11718fec5d6c8e1a4 /update-gerrit-parents.py
parentce9f894cd88bdfa0a62686c1aef0dc83a7b0a4b0 (diff)
update-gerrit-parents.py: Cronjob to check/set project parents.
This allows to define mapping between project path prefixes and Gerrit parent project which should be set for all matching projects. It also allows to define more than one possible parent, in which case the script just issues a warning in case of non-match, leaving choosing the right parent to operator. Change-Id: Ia53fb9359dd717fe003200c81643619f4d2ab837
Diffstat (limited to 'update-gerrit-parents.py')
-rwxr-xr-xupdate-gerrit-parents.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/update-gerrit-parents.py b/update-gerrit-parents.py
new file mode 100755
index 0000000..74e3a31
--- /dev/null
+++ b/update-gerrit-parents.py
@@ -0,0 +1,68 @@
+#!/usr/bin/python
+from __future__ import print_function
+import sys
+import json
+import logging
+import argparse
+import linaro_gerrit
+
+from update_gerrit_parents_conf import PARENT_MAP
+# update_gerrit_parents_conf.py should contain per-server parent map in
+# the following format:
+# (prefix, parent project)
+# or
+# (prefix, (parent, more parents...))
+# e.g.:
+#
+#PARENT_MAP = {
+# "https://review.linaro.org": [
+# ("toolchain",
+# ("Toolchain-Projects", "Toolchain-Upstream-Mirrors")),
+# ("infrastructure", "infrastructure"),
+# ],
+#}
+
+parser = argparse.ArgumentParser(
+ description='Update Gerrit project parents based on tree prefix')
+parser.add_argument('--server',
+ help="Server to use config for (if differs from --base)")
+parser.add_argument('--limit', type=int, default=-1,
+ help="Process at most LIMIT projects")
+linaro_gerrit.add_gerrit_args(parser)
+args = parser.parse_args()
+linaro_gerrit.apply_gerrit_conf(args)
+logging.basicConfig()
+log = logging.getLogger("update-gerrit-parents")
+log.setLevel(getattr(logging, args.loglevel.upper()))
+
+gerrit = linaro_gerrit.LinaroGerrit(args.base, args.username, args.password,
+ args.noverify, args.loglevel, args.dryrun)
+parent_map = PARENT_MAP[args.server or args.base]
+
+proj_map = gerrit.list_projects(parents=True)
+
+limit = args.limit
+for name, info in proj_map.items():
+ if limit == 0:
+ break
+ for prefix, parents in parent_map:
+ if name != prefix and name.startswith(prefix):
+ if not isinstance(parents, tuple):
+ parents = (parents,)
+ if info["parent"] == "All-Projects":
+ if len(parents) == 1:
+ log.debug("Current parent of %s is %s, setting to %s",
+ name, info["parent"], parents[0])
+ gerrit.set_project_parent(name, parents[0])
+ limit -= 1
+ else:
+ log.warn("Current parent of %s is %s, should be one of %s",
+ name, info["parent"], parents)
+ elif info["parent"] not in parents:
+ log.info("Parent of '%s' is '%s', but not among expected %s",
+ name, info["parent"], parents)
+ else:
+ log.debug("Parent of '%s' is already '%s'",
+ name, info["parent"])
+ # If matched one rule, skip processing next
+ break