1
0
mirror of synced 2025-02-20 20:50:59 +01:00

Fix a few places using enums directly instead of their value, formalize 'support' entry in config.

This commit is contained in:
Jennifer Taylor 2021-08-19 19:25:10 +00:00
parent b92cd4f579
commit 5fe48fb1c3
11 changed files with 112 additions and 121 deletions

View File

@ -209,7 +209,7 @@ def lookup(protoversion: str, requestgame: str, requestversion: str) -> Dict[str
('reflecbeat', GameConstants.REFLEC_BEAT),
('soundvoltex', GameConstants.SDVX),
]:
if g.config.get('support', {}).get(constant, False):
if constant in g.config['support']:
gamemapping[gameid] = constant
game = gamemapping.get(requestgame)
if game is None:

View File

@ -88,20 +88,19 @@ class GlobalUserData(BaseGlobalData):
'extid': profile['extid'],
}
profilegame = GameConstants(profile['game'])
if profilegame == GameConstants.DDR:
if profile['game'] == GameConstants.DDR:
base.update(self.__format_ddr_profile(profile))
if profilegame == GameConstants.IIDX:
if profile['game'] == GameConstants.IIDX:
base.update(self.__format_iidx_profile(profile))
if profilegame == GameConstants.JUBEAT:
if profile['game'] == GameConstants.JUBEAT:
base.update(self.__format_jubeat_profile(profile))
if profilegame == GameConstants.MUSECA:
if profile['game'] == GameConstants.MUSECA:
base.update(self.__format_museca_profile(profile))
if profilegame == GameConstants.POPN_MUSIC:
if profile['game'] == GameConstants.POPN_MUSIC:
base.update(self.__format_popn_profile(profile))
if profilegame == GameConstants.REFLEC_BEAT:
if profile['game'] == GameConstants.REFLEC_BEAT:
base.update(self.__format_reflec_profile(profile))
if profilegame == GameConstants.SDVX:
if profile['game'] == GameConstants.SDVX:
base.update(self.__format_sdvx_profile(profile))
return ValidatedDict(base)
@ -135,7 +134,7 @@ class GlobalUserData(BaseGlobalData):
del profile['match']
# Add in our defaults we always provide
profile['game'] = game.value
profile['game'] = game
profile['version'] = version if exact_match else 0
profile['refid'] = refid
profile['extid'] = extid
@ -224,7 +223,7 @@ class GlobalUserData(BaseGlobalData):
extid = self.user.get_extid(game, version, userid)
# Add in our defaults we always provide
profile['game'] = game.value
profile['game'] = game
profile['version'] = version if exact_match else 0
profile['refid'] = refid
profile['extid'] = extid
@ -283,7 +282,7 @@ class GlobalUserData(BaseGlobalData):
extid = self.user.get_extid(game, version, userid)
# Add in our defaults we always provide
profile['game'] = game.value
profile['game'] = game
profile['version'] = version
profile['refid'] = refid
profile['extid'] = extid

View File

@ -503,7 +503,7 @@ class UserData(BaseData):
profile = {
'refid': result['refid'],
'extid': result['extid'],
'game': game.value,
'game': game,
'version': version,
}
@ -602,7 +602,7 @@ class UserData(BaseData):
profile = {
'refid': result['refid'],
'extid': result['extid'],
'game': game.value,
'game': game,
'version': version,
}
profile.update(self.deserialize(result['data']))

View File

@ -156,9 +156,9 @@ def viewevents() -> Response:
'refresh': url_for('admin_pages.listevents', since=-1),
'backfill': url_for('admin_pages.backfillevents', until=-1),
'viewuser': url_for('admin_pages.viewuser', userid=-1),
'jubeatsong': url_for('jubeat_pages.viewtopscores', musicid=-1) if g.config.get('support', {}).get(GameConstants.JUBEAT, False) else None,
'iidxsong': url_for('iidx_pages.viewtopscores', musicid=-1) if g.config.get('support', {}).get(GameConstants.IIDX, False) else None,
'pnmsong': url_for('popn_pages.viewtopscores', musicid=-1) if g.config.get('support', {}).get(GameConstants.POPN_MUSIC, False) else None,
'jubeatsong': url_for('jubeat_pages.viewtopscores', musicid=-1) if GameConstants.JUBEAT in g.config['support'] else None,
'iidxsong': url_for('iidx_pages.viewtopscores', musicid=-1) if GameConstants.IIDX in g.config['support'] else None,
'pnmsong': url_for('popn_pages.viewtopscores', musicid=-1) if GameConstants.POPN_MUSIC in g.config['support'] else None,
},
)

View File

@ -272,7 +272,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.BISHI_BASHI, False):
if GameConstants.BISHI_BASHI in g.config['support']:
# BishiBashi pages
bishi_entries = []
if len([p for p in profiles if p[0] == GameConstants.BISHI_BASHI]) > 0:
@ -301,7 +301,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.DDR, False):
if GameConstants.DDR in g.config['support']:
# DDR pages
ddr_entries = []
if len([p for p in profiles if p[0] == GameConstants.DDR]) > 0:
@ -350,7 +350,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.IIDX, False):
if GameConstants.IIDX in g.config['support']:
# IIDX pages
iidx_entries = []
if len([p for p in profiles if p[0] == GameConstants.IIDX]) > 0:
@ -399,7 +399,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.JUBEAT, False):
if GameConstants.JUBEAT in g.config['support']:
# Jubeat pages
jubeat_entries = []
if len([p for p in profiles if p[0] == GameConstants.JUBEAT]) > 0:
@ -448,7 +448,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.MUSECA, False):
if GameConstants.MUSECA in g.config['support']:
# Museca pages
museca_entries = []
if len([p for p in profiles if p[0] == GameConstants.MUSECA]) > 0:
@ -493,7 +493,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.POPN_MUSIC, False):
if GameConstants.POPN_MUSIC in g.config['support']:
# Pop'n Music pages
popn_entries = []
if len([p for p in profiles if p[0] == GameConstants.POPN_MUSIC]) > 0:
@ -542,7 +542,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.REFLEC_BEAT, False):
if GameConstants.REFLEC_BEAT in g.config['support']:
# ReflecBeat pages
reflec_entries = []
if len([p for p in profiles if p[0] == GameConstants.REFLEC_BEAT]) > 0:
@ -591,7 +591,7 @@ def navigation() -> Dict[str, Any]:
},
)
if g.config.get('support', {}).get(GameConstants.SDVX, False):
if GameConstants.SDVX in g.config['support']:
# SDVX pages
sdvx_entries = []
if len([p for p in profiles if p[0] == GameConstants.SDVX]) > 0:

View File

@ -1,15 +1,12 @@
import argparse
import yaml
from bemani.data import Data
from bemani.api import app, config # noqa: F401
from bemani.utils.config import load_config as base_load_config
def load_config(filename: str) -> None:
global config
config.update(yaml.safe_load(open(filename)))
config['database']['engine'] = Data.create_engine(config)
base_load_config(filename, config)
def main() -> None:

43
bemani/utils/config.py Normal file
View File

@ -0,0 +1,43 @@
import yaml
from typing import Any, Dict, Set
from bemani.backend.iidx import IIDXFactory
from bemani.backend.popn import PopnMusicFactory
from bemani.backend.jubeat import JubeatFactory
from bemani.backend.bishi import BishiBashiFactory
from bemani.backend.ddr import DDRFactory
from bemani.backend.sdvx import SoundVoltexFactory
from bemani.backend.reflec import ReflecBeatFactory
from bemani.backend.museca import MusecaFactory
from bemani.common import GameConstants
from bemani.data import Data
def load_config(filename: str, config: Dict[str, Any]) -> None:
config.update(yaml.safe_load(open(filename)))
config['database']['engine'] = Data.create_engine(config)
supported_series: Set[GameConstants] = set()
for series in GameConstants:
if config.get('support', {}).get(series.value, False):
supported_series.add(series)
config['support'] = supported_series
def register_games(config: Dict[str, Any]) -> None:
if GameConstants.POPN_MUSIC in config['support']:
PopnMusicFactory.register_all()
if GameConstants.JUBEAT in config['support']:
JubeatFactory.register_all()
if GameConstants.IIDX in config['support']:
IIDXFactory.register_all()
if GameConstants.BISHI_BASHI in config['support']:
BishiBashiFactory.register_all()
if GameConstants.DDR in config['support']:
DDRFactory.register_all()
if GameConstants.SDVX in config['support']:
SoundVoltexFactory.register_all()
if GameConstants.REFLEC_BEAT in config['support']:
ReflecBeatFactory.register_all()
if GameConstants.MUSECA in config['support']:
MusecaFactory.register_all()

View File

@ -1,16 +1,6 @@
import argparse
import yaml
from bemani.backend.iidx import IIDXFactory
from bemani.backend.popn import PopnMusicFactory
from bemani.backend.jubeat import JubeatFactory
from bemani.backend.bishi import BishiBashiFactory
from bemani.backend.ddr import DDRFactory
from bemani.backend.sdvx import SoundVoltexFactory
from bemani.backend.reflec import ReflecBeatFactory
from bemani.backend.museca import MusecaFactory
from bemani.common import GameConstants
from bemani.data import Data
from bemani.frontend import app, config # noqa: F401
from bemani.frontend.account import account_pages
from bemani.frontend.admin import admin_pages
@ -24,6 +14,7 @@ from bemani.frontend.ddr import ddr_pages
from bemani.frontend.sdvx import sdvx_pages
from bemani.frontend.reflec import reflec_pages
from bemani.frontend.museca import museca_pages
from bemani.utils.config import load_config as base_load_config, register_games as base_register_games
def register_blueprints() -> None:
@ -34,50 +25,32 @@ def register_blueprints() -> None:
app.register_blueprint(arcade_pages)
app.register_blueprint(home_pages)
if config.get('support', {}).get(GameConstants.IIDX, False):
if GameConstants.IIDX in config['support']:
app.register_blueprint(iidx_pages)
if config.get('support', {}).get(GameConstants.POPN_MUSIC, False):
if GameConstants.POPN_MUSIC in config['support']:
app.register_blueprint(popn_pages)
if config.get('support', {}).get(GameConstants.JUBEAT, False):
if GameConstants.JUBEAT in config['support']:
app.register_blueprint(jubeat_pages)
if config.get('support', {}).get(GameConstants.BISHI_BASHI, False):
if GameConstants.BISHI_BASHI in config['support']:
app.register_blueprint(bishi_pages)
if config.get('support', {}).get(GameConstants.DDR, False):
if GameConstants.DDR in config['support']:
app.register_blueprint(ddr_pages)
if config.get('support', {}).get(GameConstants.SDVX, False):
if GameConstants.SDVX in config['support']:
app.register_blueprint(sdvx_pages)
if config.get('support', {}).get(GameConstants.REFLEC_BEAT, False):
if GameConstants.REFLEC_BEAT in config['support']:
app.register_blueprint(reflec_pages)
if config.get('support', {}).get(GameConstants.MUSECA, False):
if GameConstants.MUSECA in config['support']:
app.register_blueprint(museca_pages)
def register_games() -> None:
global config
if config.get('support', {}).get(GameConstants.POPN_MUSIC, False):
PopnMusicFactory.register_all()
if config.get('support', {}).get(GameConstants.JUBEAT, False):
JubeatFactory.register_all()
if config.get('support', {}).get(GameConstants.IIDX, False):
IIDXFactory.register_all()
if config.get('support', {}).get(GameConstants.BISHI_BASHI, False):
BishiBashiFactory.register_all()
if config.get('support', {}).get(GameConstants.DDR, False):
DDRFactory.register_all()
if config.get('support', {}).get(GameConstants.SDVX, False):
SoundVoltexFactory.register_all()
if config.get('support', {}).get(GameConstants.REFLEC_BEAT, False):
ReflecBeatFactory.register_all()
if config.get('support', {}).get(GameConstants.MUSECA, False):
MusecaFactory.register_all()
base_register_games(config)
def load_config(filename: str) -> None:
global config
config.update(yaml.safe_load(open(filename)))
config['database']['engine'] = Data.create_engine(config)
base_load_config(filename, config)
app.secret_key = config['secret_key']

View File

@ -3656,7 +3656,13 @@ if __name__ == "__main__":
# Load the config so we can talk to the server
config = yaml.safe_load(open(args.config))
if args.series == GameConstants.POPN_MUSIC:
series = None
try:
series = GameConstants(args.series)
except ValueError:
pass
if series == GameConstants.POPN_MUSIC:
popn = ImportPopn(config, args.version, args.no_combine, args.update)
if args.bin:
songs = popn.scrape(args.bin)
@ -3670,7 +3676,7 @@ if __name__ == "__main__":
popn.import_music_db(songs)
popn.close()
elif args.series == GameConstants.JUBEAT:
elif series == GameConstants.JUBEAT:
jubeat = ImportJubeat(config, args.version, args.no_combine, args.update)
if args.tsv is not None:
# Special case for Jubeat, grab the title/artist metadata that was
@ -3691,7 +3697,7 @@ if __name__ == "__main__":
jubeat.import_emblems(emblems)
jubeat.close()
elif args.series == GameConstants.IIDX:
elif series == GameConstants.IIDX:
iidx = ImportIIDX(config, args.version, args.no_combine, args.update)
if args.tsv is not None:
# Special case for IIDX, grab the title/artist metadata that was
@ -3712,7 +3718,7 @@ if __name__ == "__main__":
iidx.import_qpros(qpros)
iidx.close()
elif args.series == GameConstants.DDR:
elif series == GameConstants.DDR:
ddr = ImportDDR(config, args.version, args.no_combine, args.update)
if args.server and args.token:
songs = ddr.lookup(args.server, args.token)
@ -3735,7 +3741,7 @@ if __name__ == "__main__":
ddr.import_music_db(songs)
ddr.close()
elif args.series == GameConstants.SDVX:
elif series == GameConstants.SDVX:
sdvx = ImportSDVX(config, args.version, args.no_combine, args.update)
if args.server and args.token:
sdvx.import_from_server(args.server, args.token)
@ -3754,7 +3760,7 @@ if __name__ == "__main__":
sdvx.import_appeal_cards(args.csv)
sdvx.close()
elif args.series == GameConstants.MUSECA:
elif series == GameConstants.MUSECA:
museca = ImportMuseca(config, args.version, args.no_combine, args.update)
if args.server and args.token:
museca.import_from_server(args.server, args.token)
@ -3767,7 +3773,7 @@ if __name__ == "__main__":
)
museca.close()
elif args.series == GameConstants.REFLEC_BEAT:
elif series == GameConstants.REFLEC_BEAT:
reflec = ImportReflecBeat(config, args.version, args.no_combine, args.update)
if args.bin is not None:
songs = reflec.scrape(args.bin)
@ -3781,7 +3787,7 @@ if __name__ == "__main__":
reflec.import_music_db(songs)
reflec.close()
elif args.series == GameConstants.DANCE_EVOLUTION:
elif series == GameConstants.DANCE_EVOLUTION:
danevo = ImportDanceEvolution(config, args.version, args.no_combine, args.update)
if args.server and args.token:
songs = danevo.lookup(args.server, args.token)

View File

@ -1,5 +1,4 @@
import argparse
import yaml
from typing import Any, Dict, List
from bemani.backend.popn import PopnMusicFactory
@ -20,6 +19,7 @@ from bemani.frontend.reflec import ReflecBeatCache
from bemani.frontend.museca import MusecaCache
from bemani.common import GameConstants, Time
from bemani.data import Data
from bemani.utils.config import load_config
def run_scheduled_work(config: Dict[str, Any]) -> None:
@ -28,28 +28,28 @@ def run_scheduled_work(config: Dict[str, Any]) -> None:
# Only run scheduled work for enabled components
enabled_factories: List[Any] = []
enabled_caches: List[Any] = []
if config.get('support', {}).get(GameConstants.IIDX, False):
if GameConstants.IIDX in config['support']:
enabled_factories.append(IIDXFactory)
enabled_caches.append(IIDXCache)
if config.get('support', {}).get(GameConstants.POPN_MUSIC, False):
if GameConstants.POPN_MUSIC in config['support']:
enabled_factories.append(PopnMusicFactory)
enabled_caches.append(PopnMusicCache)
if config.get('support', {}).get(GameConstants.JUBEAT, False):
if GameConstants.JUBEAT in config['support']:
enabled_factories.append(JubeatFactory)
enabled_caches.append(JubeatCache)
if config.get('support', {}).get(GameConstants.BISHI_BASHI, False):
if GameConstants.BISHI_BASHI in config['support']:
enabled_factories.append(BishiBashiFactory)
enabled_caches.append(BishiBashiCache)
if config.get('support', {}).get(GameConstants.DDR, False):
if GameConstants.DDR in config['support']:
enabled_factories.append(DDRFactory)
enabled_caches.append(DDRCache)
if config.get('support', {}).get(GameConstants.SDVX, False):
if GameConstants.SDVX in config['support']:
enabled_factories.append(SoundVoltexFactory)
enabled_caches.append(SoundVoltexCache)
if config.get('support', {}).get(GameConstants.REFLEC_BEAT, False):
if GameConstants.REFLEC_BEAT in config['support']:
enabled_factories.append(ReflecBeatFactory)
enabled_caches.append(ReflecBeatCache)
if config.get('support', {}).get(GameConstants.MUSECA, False):
if GameConstants.MUSECA in config['support']:
enabled_factories.append(MusecaFactory)
enabled_caches.append(MusecaCache)
@ -75,8 +75,8 @@ if __name__ == '__main__':
args = parser.parse_args()
# Set up global configuration
config = yaml.safe_load(open(args.config))
config['database']['engine'] = Data.create_engine(config)
config: Dict[str, Any] = {}
load_config(args.config, config)
# Run out of band work
run_scheduled_work(config)

View File

@ -1,22 +1,13 @@
import argparse
import copy
import traceback
import yaml
from typing import Any, Dict
from flask import Flask, request, redirect, Response, make_response
from bemani.protocol import EAmuseProtocol
from bemani.backend import Dispatch, UnrecognizedPCBIDException
from bemani.backend.iidx import IIDXFactory
from bemani.backend.popn import PopnMusicFactory
from bemani.backend.jubeat import JubeatFactory
from bemani.backend.bishi import BishiBashiFactory
from bemani.backend.ddr import DDRFactory
from bemani.backend.sdvx import SoundVoltexFactory
from bemani.backend.reflec import ReflecBeatFactory
from bemani.backend.museca import MusecaFactory
from bemani.common import GameConstants
from bemani.data import Data
from bemani.utils.config import load_config as base_load_config, register_games as base_register_games
app = Flask(__name__)
@ -125,32 +116,14 @@ def receive_request(path: str) -> Response:
dataprovider.close()
def load_config(filename: str) -> None:
global config
config.update(yaml.safe_load(open(filename)))
config['database']['engine'] = Data.create_engine(config)
def register_games() -> None:
global config
base_register_games(config)
if config.get('support', {}).get(GameConstants.POPN_MUSIC, False):
PopnMusicFactory.register_all()
if config.get('support', {}).get(GameConstants.JUBEAT, False):
JubeatFactory.register_all()
if config.get('support', {}).get(GameConstants.IIDX, False):
IIDXFactory.register_all()
if config.get('support', {}).get(GameConstants.BISHI_BASHI, False):
BishiBashiFactory.register_all()
if config.get('support', {}).get(GameConstants.DDR, False):
DDRFactory.register_all()
if config.get('support', {}).get(GameConstants.REFLEC_BEAT, False):
ReflecBeatFactory.register_all()
if config.get('support', {}).get(GameConstants.SDVX, False):
SoundVoltexFactory.register_all()
if config.get('support', {}).get(GameConstants.MUSECA, False):
MusecaFactory.register_all()
def load_config(filename: str) -> None:
global config
base_load_config(filename, config)
if __name__ == '__main__':
@ -160,7 +133,7 @@ if __name__ == '__main__':
parser.add_argument("-r", "--profile", help="Turn on profiling for services, writing CProfile data to the currenct directory", action="store_true")
args = parser.parse_args()
# Set up global configuration, overriding config port for convenience
# Set up global configuration, overriding config port for convenience in debugging.
load_config(args.config)
config['server']['port'] = args.port