blob: e3e19267138a8a6981c2ba585ea4c9ba9a32f678 [file] [log] [blame]
James E. Blairee743612012-05-29 14:49:32 -07001import argparse
2import ConfigParser
3import os
4
5import zuul.scheduler
6import zuul.launcher.jenkins
7import zuul.trigger.gerrit
8
9import logging.config
10
11def parse_arguments():
12 parser = argparse.ArgumentParser(description='Project gating system.')
13 parser.add_argument('-c', dest='config',
14 help='specify the config file')
15 return parser.parse_args()
16
17def read_config(args):
18 config=ConfigParser.ConfigParser()
19 if args.config:
20 locations = [args.config]
21 else:
22 locations = ['/etc/zuul/zuul.conf',
23 '~/zuul.conf']
24 for fp in locations:
25 if os.path.exists(os.path.expanduser(fp)):
26 config.read(fp)
27 return config
28 raise Exception("Unable to locate config file in %s" % locations)
29
30def setup_logging(config):
31 if config.has_option('zuul', 'log_config'):
32 fp = os.path.expanduser(config.get('zuul', 'log_config'))
33 if not os.path.exists(fp):
34 raise Exception("Unable to read logging config file at %s" % fp)
35 logging.config.fileConfig(fp)
36 else:
37 logging.basicConfig(level=logging.DEBUG)
38
39def main(config):
40 sched = zuul.scheduler.Scheduler(config)
41
42 jenkins = zuul.launcher.jenkins.Jenkins(config, sched)
43 gerrit = zuul.trigger.gerrit.Gerrit(config, sched)
44
45 sched.setLauncher(jenkins)
46 sched.setTrigger(gerrit)
47 sched.run()
48
49if __name__ == '__main__':
50 args = parse_arguments()
51 config = read_config(args)
52 setup_logging(config)
53 main(config)