blob: f63ae6ad323a09e3e2d6afa059fbb8fd8c4fef80 [file] [log] [blame]
James E. Blair1ce97ad2012-05-29 15:38:19 -07001#!/usr/bin/env python
2# Copyright 2012 Hewlett-Packard Development Company, L.P.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
James E. Blairee743612012-05-29 14:49:32 -070016import argparse
17import ConfigParser
18import os
19
20import zuul.scheduler
21import zuul.launcher.jenkins
22import zuul.trigger.gerrit
23
24import logging.config
25
26def parse_arguments():
27 parser = argparse.ArgumentParser(description='Project gating system.')
28 parser.add_argument('-c', dest='config',
29 help='specify the config file')
30 return parser.parse_args()
31
32def read_config(args):
33 config=ConfigParser.ConfigParser()
34 if args.config:
35 locations = [args.config]
36 else:
37 locations = ['/etc/zuul/zuul.conf',
38 '~/zuul.conf']
39 for fp in locations:
40 if os.path.exists(os.path.expanduser(fp)):
41 config.read(fp)
42 return config
43 raise Exception("Unable to locate config file in %s" % locations)
44
45def setup_logging(config):
46 if config.has_option('zuul', 'log_config'):
47 fp = os.path.expanduser(config.get('zuul', 'log_config'))
48 if not os.path.exists(fp):
49 raise Exception("Unable to read logging config file at %s" % fp)
50 logging.config.fileConfig(fp)
51 else:
52 logging.basicConfig(level=logging.DEBUG)
53
54def main(config):
55 sched = zuul.scheduler.Scheduler(config)
56
57 jenkins = zuul.launcher.jenkins.Jenkins(config, sched)
58 gerrit = zuul.trigger.gerrit.Gerrit(config, sched)
59
60 sched.setLauncher(jenkins)
61 sched.setTrigger(gerrit)
62 sched.run()
63
64if __name__ == '__main__':
65 args = parse_arguments()
66 config = read_config(args)
67 setup_logging(config)
68 main(config)