-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
57 lines (48 loc) · 1.66 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
from pydantic import BaseModel
from yaml import dump, safe_load
from application.util.helper import POCKER_CONFIG_BASE_PATH
CONFIG_PATH = POCKER_CONFIG_BASE_PATH / "config.yaml"
class Config(BaseModel):
log_tail: int = 2000
max_log_lines: int = 2000
start_wrap: bool = False
show_all_containers: bool = False
start_fullscreen: bool = False
start_scroll: bool = True
keymap: dict[str, str] = {
"quit": "q",
"logs": "l",
"attributes": "a",
"environment": "e",
"statistics": "d",
"shell": "v",
"fullscreen": "f",
"fullscreen-ci": "n",
"wrap-logs": "w",
"toggle-scroll": "s",
}
def __repr__(self) -> str:
return super().__repr__(self.start_wrap)
def create_default_config(self):
default_config = {
"log_tail": self.log_tail,
"max_log_lines": self.max_log_lines,
"start_wrap": self.start_wrap,
"show_all_containers": self.show_all_containers,
"start_fullscreen": self.start_fullscreen,
"start_scroll": self.start_scroll,
"keymap": self.keymap,
}
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
with CONFIG_PATH.open("w") as file:
dump(default_config, file)
def save(self):
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
with CONFIG_PATH.open("w") as file:
dump(self.model_dump(), file)
def load_config():
if not CONFIG_PATH.exists():
Config().create_default_config()
with CONFIG_PATH.open() as file:
config_dict = safe_load(file)
return Config(**config_dict)