James E. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 1 | import argparse |
| 2 | import ConfigParser |
| 3 | import os |
| 4 | |
| 5 | import zuul.scheduler |
| 6 | import zuul.launcher.jenkins |
| 7 | import zuul.trigger.gerrit |
| 8 | |
| 9 | import logging.config |
| 10 | |
| 11 | def 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 | |
| 17 | def 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 | |
| 30 | def 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 | |
| 39 | def 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 | |
| 49 | if __name__ == '__main__': |
| 50 | args = parse_arguments() |
| 51 | config = read_config(args) |
| 52 | setup_logging(config) |
| 53 | main(config) |