Allow data_path to be None (don't load or save data)

This commit is contained in:
nemunaire 2015-02-09 17:23:07 +01:00
parent e7d37991b3
commit 55b1eb5075
2 changed files with 11 additions and 8 deletions

View file

@ -45,7 +45,7 @@ class Bot(threading.Thread):
"""Class containing the bot context and ensuring key goals"""
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
Keyword arguments:
@ -66,7 +66,8 @@ class Bot(threading.Thread):
# Context paths
self.modules_paths = modules_paths
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
self.servers = dict()

View file

@ -139,13 +139,15 @@ class ModuleLoader(SourceFileLoader):
module.del_event = del_event
if not hasattr(module, "NODATA"):
data_file = os.path.join(self.context.data_path,
module.__name__ + ".xml")
if os.path.isfile(data_file):
module.DATAS = parse_file(data_file)
module.DATAS = module_state.ModuleState("nemubotstate")
if self.context.data_path is not None:
data_file = os.path.join(self.context.data_path,
module.__name__ + ".xml")
if os.path.isfile(data_file):
module.DATAS = parse_file(data_file)
module.save = mod_save
else:
module.DATAS = module_state.ModuleState("nemubotstate")
module.save = mod_save
module.save = lambda: False
else:
module.DATAS = None
module.save = lambda: False