mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
Fix handling of persistant storage if no persistant storage exists yet
This commit is contained in:
@@ -5,7 +5,7 @@ if '__main__' == __name__:
|
|||||||
print('''this is a library file, which is not meant to be executed''')
|
print('''this is a library file, which is not meant to be executed''')
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
import sys, time, pickle
|
import sys, time, pickle, os
|
||||||
from local_config import conf
|
from local_config import conf
|
||||||
|
|
||||||
RATE_GLOBAL = 0x01
|
RATE_GLOBAL = 0x01
|
||||||
@@ -36,9 +36,13 @@ def conf_save(obj):
|
|||||||
return pickle.dump(obj, fd)
|
return pickle.dump(obj, fd)
|
||||||
|
|
||||||
def conf_load():
|
def conf_load():
|
||||||
with open(conf('persistent_storage'), 'rb') as fd:
|
path = conf('persistent_storage')
|
||||||
|
if os.path.isfile(path):
|
||||||
|
with open(path, 'rb') as fd:
|
||||||
fd.seek(0)
|
fd.seek(0)
|
||||||
return pickle.load(fd)
|
return pickle.load(fd)
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_version_git():
|
def get_version_git():
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|||||||
@@ -441,12 +441,13 @@ def command_usersetting(argv, **args):
|
|||||||
set_conf('persistent_locked', True)
|
set_conf('persistent_locked', True)
|
||||||
blob = conf_load()
|
blob = conf_load()
|
||||||
|
|
||||||
|
if 'user_pref' not in blob:
|
||||||
|
blob['user_pref'] = {}
|
||||||
|
|
||||||
if not arg_user in blob['user_pref']:
|
if not arg_user in blob['user_pref']:
|
||||||
blob['user_pref'][arg_user] = {}
|
blob['user_pref'][arg_user] = {}
|
||||||
|
|
||||||
blob['user_pref'][arg_user][arg_key] = (
|
blob['user_pref'][arg_user][arg_key] = 'on' == arg_val
|
||||||
True if 'on' == arg_val else False
|
|
||||||
)
|
|
||||||
|
|
||||||
conf_save(blob)
|
conf_save(blob)
|
||||||
set_conf('persistent_locked', False)
|
set_conf('persistent_locked', False)
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ def handle_msg(msg_obj):
|
|||||||
return
|
return
|
||||||
|
|
||||||
arg_user = msg_obj['mucnick']
|
arg_user = msg_obj['mucnick']
|
||||||
blob_userpref = conf_load()['user_pref']
|
blob_userpref = conf_load().get('user_pref',[])
|
||||||
nospoiler = False
|
nospoiler = False
|
||||||
|
|
||||||
if arg_user in blob_userpref:
|
if arg_user in blob_userpref:
|
||||||
|
|||||||
Reference in New Issue
Block a user