forked from Hanabi/hanabi-league
Fix decorator
This commit is contained in:
parent
ab32fae4f2
commit
22bfb38011
2 changed files with 10 additions and 8 deletions
17
config.py
17
config.py
|
@ -3,9 +3,9 @@ from typing import Dict
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import platformdirs
|
import platformdirs
|
||||||
from pathlib import Path
|
import datetime
|
||||||
from datetime import datetime, timezone
|
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import constants
|
import constants
|
||||||
from log_setup import logger
|
from log_setup import logger
|
||||||
|
@ -77,12 +77,14 @@ def create_db_config() -> None:
|
||||||
|
|
||||||
|
|
||||||
def check_config_attr(func):
|
def check_config_attr(func):
|
||||||
def wrapper():
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
func()
|
return func(*args, **kwargs)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logger.error("Missing config attribute:\n{}".format(e))
|
logger.error("Missing config attribute:\n{}".format(e))
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, config: Dict):
|
def __init__(self, config: Dict):
|
||||||
|
@ -92,7 +94,6 @@ class Config:
|
||||||
def player_base_rating(self) -> int:
|
def player_base_rating(self) -> int:
|
||||||
return self._config["player_base_rating"]
|
return self._config["player_base_rating"]
|
||||||
|
|
||||||
@check_config_attr
|
|
||||||
def min_player_count(self) -> int:
|
def min_player_count(self) -> int:
|
||||||
return self._config["min_player_count"]
|
return self._config["min_player_count"]
|
||||||
|
|
||||||
|
@ -117,14 +118,14 @@ class Config:
|
||||||
return self._config["ending_game_id"]
|
return self._config["ending_game_id"]
|
||||||
|
|
||||||
@check_config_attr
|
@check_config_attr
|
||||||
def starting_time(self):
|
def starting_time(self) -> datetime.datetime:
|
||||||
time = self._config["starting_time"]
|
time = self._config["starting_time"]
|
||||||
return dateutil.parser(time, tzinfos={'EST': 'US/Eastern'})
|
return dateutil.parser(time, tzinfos={'EST': 'US/Eastern'})
|
||||||
|
|
||||||
@check_config_attr
|
@check_config_attr
|
||||||
def ending_time(self):
|
def ending_time(self) -> datetime.datetime:
|
||||||
time = self._config["ending_time"]
|
time = self._config["ending_time"]
|
||||||
return dateutil.parser(time, tzinfos={'EST': 'US/Eastern'})
|
return dateutil.parser.parse(time, tzinfos={'EST': 'US/Eastern'})
|
||||||
|
|
||||||
@check_config_attr
|
@check_config_attr
|
||||||
def variant_base_rating(self, variant_name: str, player_count: int) -> int:
|
def variant_base_rating(self, variant_name: str, player_count: int) -> int:
|
||||||
|
|
1
main.py
1
main.py
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import datetime
|
||||||
|
|
||||||
import verboselogs
|
import verboselogs
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue