2023-12-14 19:19:03 +08:00
|
|
|
from configparser import ConfigParser
|
|
|
|
import os,inspect
|
|
|
|
|
|
|
|
CF = ConfigParser()
|
|
|
|
__fnm = os.path.join(os.path.dirname(__file__), '../conf/sys.cnf')
|
|
|
|
if not os.path.exists(__fnm):__fnm = os.path.join(os.path.dirname(__file__), '../../conf/sys.cnf')
|
|
|
|
assert os.path.exists(__fnm), f"【EXCEPTION】can't find {__fnm}." + os.path.dirname(__file__)
|
|
|
|
if not os.path.exists(__fnm): __fnm = "./sys.cnf"
|
|
|
|
|
|
|
|
CF.read(__fnm)
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
def __init__(self, env):
|
|
|
|
self.env = env
|
|
|
|
if env == "spark":CF.read("./cv.cnf")
|
|
|
|
|
2023-12-22 17:57:27 +08:00
|
|
|
def get(self, key, default=None):
|
2023-12-14 19:19:03 +08:00
|
|
|
global CF
|
2023-12-25 10:17:13 +08:00
|
|
|
return os.environ.get(key.upper(), \
|
|
|
|
CF[self.env].get(key, default)
|
|
|
|
)
|
2023-12-14 19:19:03 +08:00
|
|
|
|
|
|
|
def init(env):
|
|
|
|
return Config(env)
|
|
|
|
|