def getConfigDict(configPath):
configDict = None
try:
configRaw = open(configPath, "rb").read()
except IOError:
print("ERROR: I/O fatal error.", file = sys.stderr)
sys.exit(1)
if configRaw.startswith(codecs.BOM_UTF8):
configRaw = configRaw[3:]
try:
configDict = toml.loads(configRaw)
except toml.TomlDecodeError as tomlExp:
for string in tomlExp.args:
print("ERROR: Invalid TOML syntax. " + string, file = sys.stderr)
sys.exit(1)
except TypeError as typeExp:
for string in typeExp.args:
print("ERROR: Invalid config file. " + string, file = sys.stderr)
sys.exit(1)
except:
print("ERROR: Invalid config file. Please make sure it is UTF-8 encoded and complies TOML specification.", file = sys.stderr)
print("Please review TOML specification at: https://github.com/toml-lang/toml", file = sys.stderr)
sys.exit(1)
return configDict
评论列表
文章目录