From 0127a9cf26eae6ab2b4de77e9b08967826ab24c8 Mon Sep 17 00:00:00 2001 From: Thorsten S Date: Mon, 21 Dec 2015 10:41:58 +0100 Subject: [PATCH] replace direct write with proxy function for future locking --- config.py | 6 +++++- idlebot.py | 2 +- plugins.py | 10 +++++----- urlbot.py | 7 +++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index 3805062..dab24dc 100644 --- a/config.py +++ b/config.py @@ -51,7 +51,7 @@ def conf_set(key, val): def runtimeconf_set(key, value): runtime_config_store[key] = value - runtime_config_store.write() + runtimeconf_persist() def runtimeconf_get(key, default=None): @@ -61,6 +61,10 @@ def runtimeconf_get(key, default=None): return runtime_config_store.get(key, default=default) +def runtimeconf_persist(): + runtime_config_store.write() + + def runtimeconf_deepget(key, default=None): if '.' not in key: return runtimeconf_get(key, default) diff --git a/idlebot.py b/idlebot.py index a6d10ab..802ac19 100755 --- a/idlebot.py +++ b/idlebot.py @@ -52,7 +52,7 @@ class IdleBot(ClientXMPP): )) self.hangup() return False - elif msg_obj['mucnick'] in config.runtime_config_store["other_bots"]: + elif msg_obj['mucnick'] in config.runtimeconf_get("other_bots"): # not talking to the other bot. return False else: diff --git a/plugins.py b/plugins.py index 7247072..71511d9 100644 --- a/plugins.py +++ b/plugins.py @@ -46,7 +46,7 @@ def plugin_enabled_set(plugin, enabled): config.runtime_config_store['plugins'][plugin.plugin_name] = {} config.runtime_config_store['plugins'][plugin.plugin_name]['enabled'] = enabled - config.runtime_config_store.write() + config.runtimeconf_persist() config.conf_set('persistent_locked', False) @@ -594,7 +594,7 @@ def command_usersetting(argv, **args): config.runtime_config_store['user_pref'][arg_user][arg_key] = 'on' == arg_val - config.runtime_config_store.write() + config.runtimeconf_persist() config.conf_set('persistent_locked', False) # display value written to db @@ -822,7 +822,7 @@ def command_record(argv, **args): config.runtime_config_store['user_records'][target_user].append(message) - config.runtime_config_store.write() + config.runtimeconf_persist() config.conf_set('persistent_locked', False) return { @@ -961,7 +961,7 @@ def recognize_bots(**args): def _add_to_list(username, message): if username not in config.runtime_config_store['other_bots']: config.runtime_config_store['other_bots'].append(username) - config.runtime_config_store.write() + config.runtimeconf_persist() return { 'event': { 'time': time.time() + 3, @@ -988,7 +988,7 @@ def remove_from_botlist(argv, **args): if argv[1] in config.runtime_config_store['other_bots']: config.runtime_config_store['other_bots'].remove(argv[1]) - config.runtime_config_store.write() + config.runtimeconf_persist() return {'msg': '%s was removed from the botlist.' % argv[1]} else: return False diff --git a/urlbot.py b/urlbot.py index 39bca32..0428a94 100755 --- a/urlbot.py +++ b/urlbot.py @@ -73,7 +73,7 @@ class UrlBot(IdleBot): # TODO: move this to a undirected plugin, maybe new plugin type arg_user = msg_obj['muc']['nick'] arg_user_key = arg_user.lower() - user_records = config.runtime_config_store['user_records'] + user_records = config.runtimeconf_get('user_records') if arg_user_key in user_records: records = user_records[arg_user_key] @@ -102,7 +102,7 @@ class UrlBot(IdleBot): config.conf_set('persistent_locked', True) user_records.pop(arg_user_key) - config.runtime_config_store.write() + config.runtimeconf_persist() config.conf_set('persistent_locked', False) @@ -116,7 +116,6 @@ class UrlBot(IdleBot): return config.runtimeconf_set('request_counter', config.runtimeconf_get('request_counter') + 1) - config.runtime_config_store.write() if str is not type(message): message = '\n'.join(message) @@ -141,7 +140,7 @@ class UrlBot(IdleBot): @cached def get_bots_present(room): - other_bots = config.runtime_config_store["other_bots"] + other_bots = config.runtimeconf_get("other_bots") if not other_bots: return False users = self.plugin['xep_0045'].getRoster(room)