James E. Blair | 1ce97ad | 2012-05-29 15:38:19 -0700 | [diff] [blame] | 1 | #!/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. Blair | ee74361 | 2012-05-29 14:49:32 -0700 | [diff] [blame] | 16 | import argparse |
| 17 | import ConfigParser |
| 18 | import os |
| 19 | |
| 20 | import zuul.scheduler |
| 21 | import zuul.launcher.jenkins |
| 22 | import zuul.trigger.gerrit |
| 23 | |
| 24 | import logging.config |
| 25 | |
| 26 | def 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 | |
| 32 | def 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 | |
| 45 | def 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 | |
| 54 | def 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 | |
| 64 | if __name__ == '__main__': |
| 65 | args = parse_arguments() |
| 66 | config = read_config(args) |
| 67 | setup_logging(config) |
| 68 | main(config) |