Allow data_path to be None (don't load or save data)
This commit is contained in:
parent
e7d37991b3
commit
55b1eb5075
2 changed files with 11 additions and 8 deletions
|
@ -45,7 +45,7 @@ class Bot(threading.Thread):
|
||||||
"""Class containing the bot context and ensuring key goals"""
|
"""Class containing the bot context and ensuring key goals"""
|
||||||
|
|
||||||
def __init__(self, ip="127.0.0.1", modules_paths=list(),
|
def __init__(self, ip="127.0.0.1", modules_paths=list(),
|
||||||
data_path="./datas/", verbosity=0):
|
data_path=None, verbosity=0):
|
||||||
"""Initialize the bot context
|
"""Initialize the bot context
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
|
@ -66,7 +66,8 @@ class Bot(threading.Thread):
|
||||||
# Context paths
|
# Context paths
|
||||||
self.modules_paths = modules_paths
|
self.modules_paths = modules_paths
|
||||||
self.data_path = None
|
self.data_path = None
|
||||||
self.set_data_path(data_path)
|
if data_path is not None:
|
||||||
|
self.set_data_path(data_path)
|
||||||
|
|
||||||
# Keep global context: servers and modules
|
# Keep global context: servers and modules
|
||||||
self.servers = dict()
|
self.servers = dict()
|
||||||
|
|
|
@ -139,13 +139,15 @@ class ModuleLoader(SourceFileLoader):
|
||||||
module.del_event = del_event
|
module.del_event = del_event
|
||||||
|
|
||||||
if not hasattr(module, "NODATA"):
|
if not hasattr(module, "NODATA"):
|
||||||
data_file = os.path.join(self.context.data_path,
|
module.DATAS = module_state.ModuleState("nemubotstate")
|
||||||
module.__name__ + ".xml")
|
if self.context.data_path is not None:
|
||||||
if os.path.isfile(data_file):
|
data_file = os.path.join(self.context.data_path,
|
||||||
module.DATAS = parse_file(data_file)
|
module.__name__ + ".xml")
|
||||||
|
if os.path.isfile(data_file):
|
||||||
|
module.DATAS = parse_file(data_file)
|
||||||
|
module.save = mod_save
|
||||||
else:
|
else:
|
||||||
module.DATAS = module_state.ModuleState("nemubotstate")
|
module.save = lambda: False
|
||||||
module.save = mod_save
|
|
||||||
else:
|
else:
|
||||||
module.DATAS = None
|
module.DATAS = None
|
||||||
module.save = lambda: False
|
module.save = lambda: False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue