Beispiel #1
0
 def test_add_argparse(self):
     parser = argparse.ArgumentParser()
     parser.add_argument("--foo")
     args = parser.parse_args(["--foo", "bar"])
     config = Config()
     config.add_from_args(args)
     self.assertEqual("bar", config["foo"])
Beispiel #2
0
def get_config():
    global parser, args, config
    parser = argparse.ArgumentParser(description='Pre receive hook for git repositories.')
    parser.add_argument('--dry-run', action='store_true', default=False, help='only log problems')
    parser.add_argument('--logfile', default=os.path.join(tempfile.gettempdir(), 'zooker.log'),
                        help='full path of the logfile')
    parser.add_argument('-c', '--config', help='path to config file')
    parser.add_argument('-v', '--verbose', action='count', help='verbose logging (-vv to be more verbose)', default=0)
    parser.add_argument('base', help='base commit hash')
    parser.add_argument('commit', help='new commit hash')
    parser.add_argument('ref', help='commit ref')
    args = parser.parse_args()
    level = [logging.ERROR, logging.INFO, logging.DEBUG]
    if args.logfile == '-':
        logging.basicConfig(format=LOG_CONSOLE_FORMAT, level=level[args.verbose])
    else:
        logging.basicConfig(filename=args.logfile, level=level[args.verbose])
    config = Config(checkers={'WhiteSpaceChecker': '', 'CodeValidatorChecker': ''}).add_from_default_locations()
    config.add_from_args(args)
    if args.config:
        config.add_from_json(args.config)
    return config