2019-12-08 22:43:49 +01:00
|
|
|
import argparse
|
2021-05-31 20:07:03 +02:00
|
|
|
import yaml
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.data import Data
|
|
|
|
from bemani.api import app, config # noqa: F401
|
|
|
|
|
|
|
|
|
|
|
|
def load_config(filename: str) -> None:
|
|
|
|
global config
|
|
|
|
|
2021-05-31 20:07:03 +02:00
|
|
|
config.update(yaml.safe_load(open(filename)))
|
2019-12-08 22:43:49 +01:00
|
|
|
config['database']['engine'] = Data.create_engine(config)
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
parser = argparse.ArgumentParser(description="An API services provider for eAmusement games, conforming to BEMAPI specs.")
|
|
|
|
parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80)
|
|
|
|
parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml")
|
2021-08-12 17:57:54 +02:00
|
|
|
parser.add_argument("-r", "--profile", help="Turn on profiling for API, writing CProfile data to the currenct directory", action="store_true")
|
2019-12-08 22:43:49 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Set up app
|
|
|
|
load_config(args.config)
|
|
|
|
|
|
|
|
if args.profile:
|
2021-05-31 20:07:03 +02:00
|
|
|
from werkzeug.contrib.profiler import ProfilerMiddleware
|
2019-12-08 22:43:49 +01:00
|
|
|
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir='.') # type: ignore
|
|
|
|
|
|
|
|
# Run the app
|
|
|
|
app.run(host='0.0.0.0', port=args.port, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|