2019-12-08 22:43:49 +01:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
from bemani.api import app, config # noqa: F401
|
2021-08-19 21:25:10 +02:00
|
|
|
from bemani.utils.config import load_config as base_load_config
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
def load_config(filename: str) -> None:
|
|
|
|
global config
|
2021-08-19 21:25:10 +02:00
|
|
|
base_load_config(filename, config)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
2022-10-15 20:56:30 +02:00
|
|
|
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",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-r",
|
|
|
|
"--profile",
|
|
|
|
help="Turn on profiling for API, writing CProfile data to the currenct directory",
|
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-o",
|
|
|
|
"--read-only",
|
|
|
|
action="store_true",
|
|
|
|
help="Force the database into read-only mode.",
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Set up app
|
|
|
|
load_config(args.config)
|
2021-08-20 21:37:26 +02:00
|
|
|
if args.read_only:
|
2022-10-15 20:56:30 +02:00
|
|
|
config["database"]["read_only"] = True
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if args.profile:
|
2021-05-31 20:07:03 +02:00
|
|
|
from werkzeug.contrib.profiler import ProfilerMiddleware
|
2022-10-15 20:56:30 +02:00
|
|
|
|
|
|
|
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir=".") # type: ignore
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Run the app
|
2022-10-15 20:56:30 +02:00
|
|
|
app.run(host="0.0.0.0", port=args.port, debug=True)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if __name__ == "__main__":
|
2019-12-08 22:43:49 +01:00
|
|
|
main()
|