#!/usr/bin/env python from waitress import serve from flask import Flask import argparse import logging from src.config import parse_config, DEFAULT_CONFIG, Config logger = logging.getLogger(__name__) def create_app(name: str, config: Config) -> Flask: logging.basicConfig(level=config.logging.level, format=('%(asctime)s %(levelname)s [%(name)s] %(message)s')) app = Flask(name) if config.host: app.config['SERVER_NAME'] = config.host return app def main(): parser = argparse.ArgumentParser('Cereal', description='run the Cereal server') parser.add_argument('--config', '-c', help='The path to the configuration file, expects JSON') args = parser.parse_args() config = parse_config(args.config) if args.config else DEFAULT_CONFIG app = create_app('Cereal', config) logger.info(str(config)) serve(app, host='0.0.0.0' if config.host is None else config.host, port=config.port) if __name__ == '__main__': main()