2022-02-16 18:13:44 +03:00
|
|
|
from configparser import ConfigParser
|
2023-09-05 13:05:40 +03:00
|
|
|
from typing import Any
|
2022-02-16 18:13:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
CONFIG_FILE = 'config.ini'
|
|
|
|
|
|
|
|
|
2023-09-05 13:05:40 +03:00
|
|
|
class Cfg:
|
|
|
|
def __getattr__(self, name: str) -> Any:
|
|
|
|
for key in self.data.keys():
|
|
|
|
if name not in self.data[key]:
|
|
|
|
continue
|
|
|
|
return self.data[key][name]
|
|
|
|
raise NameError("Config options not found!")
|
|
|
|
|
|
|
|
|
|
|
|
class Configure(Cfg):
|
2022-02-16 18:13:44 +03:00
|
|
|
|
|
|
|
def __init__(self):
|
2023-03-28 09:49:46 +03:00
|
|
|
config = ConfigParser()
|
|
|
|
config.read(CONFIG_FILE)
|
2023-09-05 13:05:40 +03:00
|
|
|
self.config = config
|
2022-02-16 18:13:44 +03:00
|
|
|
self.data = dict()
|
|
|
|
|
2023-03-28 09:49:46 +03:00
|
|
|
for section in config.sections():
|
2022-02-16 18:13:44 +03:00
|
|
|
self.data[section] = dict()
|
|
|
|
|
2023-03-28 09:49:46 +03:00
|
|
|
for key, value in config.items(section):
|
2022-02-16 18:13:44 +03:00
|
|
|
self.data[section][key] = value
|
|
|
|
|
2023-09-05 13:05:40 +03:00
|
|
|
self.config_folder = config.get("Docs_Settings", "Config_folder").rstrip("/")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def documentid(self):
|
|
|
|
return self.config.get("Docs_Settings", 'Document_ID')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def data_file(self):
|
|
|
|
return self.config_folder + "/" + self.config.get("Docs_Settings", "data_file")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def credentials_file(self):
|
|
|
|
return self.config_folder + "/" + self.config.get("Docs_Settings", "credentials_file")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def token_file(self):
|
|
|
|
return self.config_folder + "/" + self.data['Docs_Settings']['token_file']
|