--- /dev/null
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+
+"""
+This code is called by gerrit-plugin to load the backend config to redis.
+"""
+
+import os
+import sys
+import tempfile
+
+from common.backenddb import BackendDB
+from common.gerritevent import get_gerrit_event
+from common.git import Git, clone_gitproject
+
+def load_repos(config_file):
+ """
+ store the repos conf in repos.yaml to redis
+
+ Args:
+ config_file (str): the repos.yaml file location
+ """
+
+ bdb = BackendDB(os.getenv('REDIS_HOSTNAME'),
+ int(os.getenv('REDIS_PORT')))
+ return bdb.read_repos(file(config_file, 'r').read())
+
+def main():
+ """Script entry point.
+ """
+
+ print '---[JOB STARTED: %s ]-------------------------'
+ event = get_gerrit_event()
+
+ if event['project'] == os.getenv('REPOSYAML_PRJ'):
+ # prepare separate temp directory for each build
+ workspace = os.getenv('WORKSPACE')
+ tmpdir = tempfile.mkdtemp(prefix=workspace+'/')
+ prjdir = os.path.join(tmpdir, event['project'])
+
+ # clone gerrit project to local dir
+ clone_gitproject(event['project'], prjdir)
+ mygit = Git(prjdir)
+ mygit.checkout(event['newrev'])
+ return load_repos(os.path.join(prjdir, 'repos.yaml'))
+
+if __name__ == '__main__':
+ sys.exit(main())