From 628828ed12d3bb75efc5ac7ba2adfa0402aade22 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Fri, 20 Aug 2021 04:43:36 +0000 Subject: [PATCH] Unify config loading for remaining utilities that read the same server.yaml. --- bemani/utils/dbutils.py | 7 ++++--- bemani/utils/read.py | 9 ++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bemani/utils/dbutils.py b/bemani/utils/dbutils.py index eb4cdf4..7b1cb60 100644 --- a/bemani/utils/dbutils.py +++ b/bemani/utils/dbutils.py @@ -1,10 +1,10 @@ import argparse import getpass import sys -import yaml from typing import Any, Dict, Optional from bemani.data import Data, DBCreateException +from bemani.utils.config import load_config def create(config: Dict[str, Any]) -> None: @@ -96,8 +96,9 @@ def main() -> None: parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") args = parser.parse_args() - config = yaml.safe_load(open(args.config)) - config['database']['engine'] = Data.create_engine(config) + config: Dict[str, Any] = {} + load_config(args.config, config) + try: if args.operation == "create": create(config) diff --git a/bemani/utils/read.py b/bemani/utils/read.py index 9654d03..6eee766 100644 --- a/bemani/utils/read.py +++ b/bemani/utils/read.py @@ -8,9 +8,7 @@ import jaconv # type: ignore import json import os import struct -import yaml import xml.etree.ElementTree as ET -from sqlalchemy import create_engine # type: ignore from sqlalchemy.engine import CursorResult # type: ignore from sqlalchemy.orm import sessionmaker # type: ignore from sqlalchemy.sql import text # type: ignore @@ -25,6 +23,7 @@ from bemani.data.api.music import GlobalMusicData from bemani.data.api.game import GlobalGameData from bemani.data.mysql.music import MusicData from bemani.data.mysql.user import UserData +from bemani.utils.config import load_config class ReadAPI(APIProviderInterface): @@ -60,8 +59,7 @@ class ImportBase: self.update = update self.no_combine = no_combine self.__config = config - self.__url = f"mysql://{config['database']['user']}:{config['database']['password']}@{config['database']['address']}/{config['database']['database']}?charset=utf8mb4" - self.__engine = create_engine(self.__url) + self.__engine = self.__config['database']['engine'] self.__sessionmanager = sessionmaker(self.__engine) self.__conn = self.__engine.connect() self.__session = self.__sessionmanager(bind=self.__conn) @@ -3654,7 +3652,8 @@ if __name__ == "__main__": raise Exception("Cannot specify both a remote server and a local file to read from!") # Load the config so we can talk to the server - config = yaml.safe_load(open(args.config)) + config: Dict[str, Any] = {} + load_config(args.config, config) series = None try: