From 11edfa66ff95c42eb548fe5f78349bc20d2c3239 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Fri, 28 Jun 2013 16:45:32 +0800 Subject: [PATCH] add new job to store repos.yaml to redis This job will monitor repos.yaml project maintained in gerrit, if anything change, it will store this change to redis. Change-Id: I0ed3bc7f4a2a83a9ef7a4ce53fbb8971de4a6e1e Signed-off-by: Lin Yang --- job_load_repos.yaml.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 job_load_repos.yaml.py diff --git a/job_load_repos.yaml.py b/job_load_repos.yaml.py new file mode 100755 index 0000000..728356a --- /dev/null +++ b/job_load_repos.yaml.py @@ -0,0 +1,48 @@ +#!/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()) -- 2.7.4