forked from THU-MIG/yolov10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
38 lines (24 loc) · 843 Bytes
/
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
"""The config module handles reading config.ini file"""
from configparser import ConfigParser
from pathlib import Path
from typing import Optional
config_reader = ConfigParser()
config_reader.read(Path(__file__).absolute().parent / 'config.ini')
def _get_dir(option: str) -> Optional[Path]:
"""Return the directory named `option` under [dirs] in config ini
If the folder does not exist create it.
Return:
Path to option if set, else None.
"""
if not config_reader.has_section('dirs'):
return None
if not config_reader.has_option('dirs', option):
return None
path = Path(config_reader.get('dirs', option))
if not path.exists():
path.mkdir(parents=True)
return path
def model_folder():
return _get_dir('models')
def data_folder():
return _get_dir('data')