import os from configparser import ConfigParser from pathlib import Path from PySide2 import QtCore from exceptions import FimeFrackingException def dequotify(string): if string.startswith(('"', "'")) and string.endswith(('"', "'")): return string[1:-1] else: return string class Config: def __init__(self): self._configparser = ConfigParser() config_dir_path = Path(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.ConfigLocation)) config_path = config_dir_path / "fimefracking" / "fimefracking.conf" if config_path.exists(): with open(config_path) as f: config_text = f.read() config_text = "[DEFAULT]\n" + config_text self._configparser.read_string(config_text) if (not self._configparser.has_option("DEFAULT", "jira_url") or not self._configparser.has_option("DEFAULT", "jira_token")): raise FimeFrackingException(f'Please add config file {config_path} ' f'with config keys "jira_url" and "jira_token" in INI style') @property def jira_url(self): return dequotify(self._configparser["DEFAULT"]["jira_url"]) @property def jira_token(self): return dequotify(self._configparser["DEFAULT"]["jira_token"])