-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
73 lines (56 loc) · 1.96 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import logging
import os
from configparser import ConfigParser
from dataclasses import dataclass
from enum import Enum
LOG_CONFIG = logging.getLogger("CONFIG")
class Api(Enum):
LIBLAVA = 1
D3D9 = 2
@dataclass
class Settings:
cache_duration: int
benchmark_duration: int
api: Api
skip_confirmation: bool
@dataclass
class Liblava:
fullscreen: bool
x_resolution: int
y_resolution: int
fps_cap: int
triple_buffering: bool
class Config:
def __init__(self, config_path: str):
if not os.path.exists(config_path):
error_msg = f"config file not found at path: {config_path}"
LOG_CONFIG.error(error_msg)
raise FileNotFoundError(error_msg)
config = ConfigParser(delimiters="=")
config.read(config_path)
apis: dict[int, Api] = {
1: Api.LIBLAVA,
2: Api.D3D9,
}
self.settings = Settings(
cache_duration=config.getint("settings", "cache_duration"),
benchmark_duration=config.getint("settings", "benchmark_duration"),
api=apis[config.getint("settings", "api")],
skip_confirmation=config.getboolean("settings", "skip_confirmation"),
)
self.liblava = Liblava(
config.getboolean("liblava", "fullscreen"),
config.getint("liblava", "x_resolution"),
config.getint("liblava", "y_resolution"),
config.getint("liblava", "fps_cap"),
config.getboolean("liblava", "triple_buffering"),
)
def validate_config(self):
errors = 0
if self.settings.cache_duration < 0 or self.settings.benchmark_duration <= 0:
LOG_CONFIG.error("invalid durations specified")
errors += 1
if self.settings.api not in Api:
LOG_CONFIG.error("invalid api specified")
errors += 1
return 1 if errors else 0