-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
42 lines (34 loc) · 1.2 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
import functools
from dataclasses import asdict, dataclass
import dacite
from pathier import Pathier, Pathish
from typing_extensions import Optional, Self
@dataclass
class JobglobDaemon:
glob_interval: int
@dataclass
class Config:
logs_dir: Pathier
scrapers_dir: Pathier
jobglob_daemon: JobglobDaemon
board_meta_path: Pathier
careers_page_stubs_path: Pathier
db_path: Pathier
sql_dir: Pathier
templates_dir: Pathier
peruse_filters_path: Pathier
@functools.cached_property
def scraper_logs_dir(self) -> Pathier:
return self.logs_dir / self.scrapers_dir.stem
@classmethod
def load(cls, path: Pathish = Pathier(__file__).parent / "config.toml") -> Self:
"""Return a `datamodel` object populated from `path`."""
data = Pathier(path).loads()
for key in data:
if key.endswith("_dir") or key.endswith("_path"):
data[key] = Pathier(__file__).parent / data[key]
return dacite.from_dict(cls, data)
def dump(self, path: Pathish = Pathier(__file__).parent / "config.toml"):
"""Write the contents of this `datamodel` object to `path`."""
data = asdict(self)
Pathier(path).dumps(data)