This repository has been archived by the owner on May 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
182 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
import os | ||
import configparser | ||
import json | ||
from common.logger import logger | ||
|
||
|
||
class Config: | ||
def __init__(self, config_file=r"../config/config.ini"): | ||
def __init__(self, config_file=r"../config/config.json"): | ||
os.chdir(os.path.dirname(__file__)) | ||
self._path = os.path.abspath(config_file) | ||
if not os.path.exists(self._path): | ||
logger.error(f"No such file:{self._path}") | ||
raise FileNotFoundError(f"No such file:{self._path}") | ||
self._config = configparser.ConfigParser() | ||
self._config.read(self._path, encoding='utf-8-sig') | ||
self._configRaw = configparser.RawConfigParser() | ||
self._configRaw.read(self._path, encoding='utf-8-sig') | ||
self.config = {} | ||
self._json_read() | ||
|
||
@logger.catch | ||
def _json_read(self): | ||
with open(self._path, 'r', encoding='utf-8') as f: | ||
self.config = json.load(f) | ||
logger.debug(f"Loaded [{self._path}]") | ||
|
||
@logger.catch | ||
def refresh(self): | ||
self._config.read(self._path, encoding='utf-8-sig') | ||
self._configRaw.read(self._path, encoding='utf-8-sig') | ||
self._json_read() | ||
logger.debug(f"Refreshed [{self._path}]") | ||
|
||
@logger.catch | ||
def get(self, section, name): | ||
return self._config.get(section, name) | ||
|
||
@logger.catch | ||
def getRaw(self, section, name): | ||
return self._configRaw.get(section, name) | ||
|
||
|
||
global_config = Config(r"../config/config.ini") | ||
global_config = Config(r"../config/config.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.