2021-05-30 16:57:23 +00:00
|
|
|
import configparser
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
class LGDConf(configparser.ConfigParser):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.modified = False
|
|
|
|
self.read_only = False
|
|
|
|
self.modtime = None
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def read(self, filename):
|
|
|
|
# if config file exists, save modification time
|
|
|
|
if os.path.exists(filename):
|
|
|
|
self.modtime = int(os.stat(filename).st_mtime)
|
|
|
|
|
|
|
|
return super().read(filename)
|
|
|
|
|
|
|
|
def set(self, *args, **kwargs):
|
|
|
|
if self.read_only:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.modified = True
|
|
|
|
super().set(*args, **kwargs)
|
|
|
|
|
2021-06-17 13:21:46 +00:00
|
|
|
def remove_option(self, section, option):
|
|
|
|
if self.read_only:
|
|
|
|
return False
|
|
|
|
|
|
|
|
self.modified = True
|
|
|
|
return super().remove_option(section, option)
|
|
|
|
|
2021-05-30 16:57:23 +00:00
|
|
|
def __setitem__(self, key, value):
|
|
|
|
if self.read_only:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.modified = True
|
|
|
|
super().__setitem__(key, value)
|