You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
674 B
33 lines
674 B
5 years ago
|
import configparser
|
||
|
import os
|
||
|
|
||
|
|
||
|
FILENAME = 'settings.cfg'
|
||
|
|
||
|
|
||
|
class Config(object):
|
||
|
|
||
|
def __init__(self):
|
||
|
self.last_mtime = 0
|
||
|
self.config = None
|
||
|
|
||
|
def __contains__(self, item):
|
||
|
return item in self.config
|
||
|
|
||
|
def __getitem__(self, key):
|
||
|
return self.config[key]
|
||
|
|
||
|
def __getattr__(self, name):
|
||
|
return getattr(self.config, name)
|
||
|
|
||
|
def reload(self):
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read(FILENAME)
|
||
|
self.config = config
|
||
|
|
||
|
def reload_if_needed(self):
|
||
|
mtime = os.stat(FILENAME).st_mtime
|
||
|
if mtime > self.last_mtime:
|
||
|
self.last_mtime = mtime
|
||
|
self.reload()
|