Torchlight3/Torchlight/Config.py

30 lines
623 B
Python
Raw Normal View History

2017-08-02 23:41:02 +02:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import logging
import json
2019-12-30 17:43:48 +01:00
import sys
2017-08-02 23:41:02 +02:00
class Config():
def __init__(self):
self.Logger = logging.getLogger(__class__.__name__)
self.Config = dict()
2019-12-30 17:43:48 +01:00
if len(sys.argv) >= 2:
self.ConfigPath = sys.argv[1]
else:
self.ConfigPath = "config.json"
2017-08-02 23:41:02 +02:00
self.Load()
def Load(self):
try:
2019-12-30 17:43:48 +01:00
with open(self.ConfigPath, "r") as fp:
2017-08-02 23:41:02 +02:00
self.Config = json.load(fp)
except ValueError as e:
self.Logger.error(sys._getframe().f_code.co_name + ' ' + str(e))
return 1
return 0
def __getitem__(self, key):
if key in self.Config:
return self.Config[key]
return None