save cfg every 10min

unless there's no changes
This commit is contained in:
ed 2018-01-23 03:33:06 +01:00
parent c190dfd3af
commit b6494fbb13
3 changed files with 24 additions and 2 deletions

View File

@ -161,6 +161,7 @@ class Core(object):
def push_worker(self, world, ifaces): def push_worker(self, world, ifaces):
self.pushthr_alive = True self.pushthr_alive = True
nth_iter = 0
last_ts = None last_ts = None
last_date = None last_date = None
while not self.stopping: while not self.stopping:
@ -191,6 +192,11 @@ class Core(object):
pass pass
client.refresh(False) client.refresh(False)
nth_iter += 1
if nth_iter % 600 == 0:
for iface in ifaces:
iface.save_configs()
self.pushthr_alive = False self.pushthr_alive = False

View File

@ -36,6 +36,7 @@ class VT100_Server(asyncore.dispatcher):
self.clients = [] self.clients = []
self.user_config = {} self.user_config = {}
self.user_config_path = None self.user_config_path = None
self.user_config_changed = False
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
if PY2: if PY2:
self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@ -93,6 +94,7 @@ class VT100_Server(asyncore.dispatcher):
'inheritance bug: self.user_config_path not set') 'inheritance bug: self.user_config_path not set')
self.user_config = {} self.user_config = {}
self.user_config_changed = False
if not os.path.isfile(self.user_config_path): if not os.path.isfile(self.user_config_path):
print(' * {0} loaded 0 client configs'.format(self.__class__.__name__)) print(' * {0} loaded 0 client configs'.format(self.__class__.__name__))
return return
@ -113,6 +115,10 @@ class VT100_Server(asyncore.dispatcher):
def save_configs(self): def save_configs(self):
with self.world.mutex: with self.world.mutex:
if not self.user_config_changed:
return
self.user_config_changed = False
with open(self.user_config_path, 'wb') as f: with open(self.user_config_path, 'wb') as f:
f.write('1\n'.encode('utf-8')) f.write('1\n'.encode('utf-8'))
for k, v in sorted(self.user_config.items()): for k, v in sorted(self.user_config.items()):
@ -279,7 +285,7 @@ class VT100_Client(asyncore.dispatcher):
def save_config(self): def save_config(self):
with self.world.mutex: with self.world.mutex:
self.host.user_config[self.addr[0]] = u' '.join([ conf_str = u' '.join([
hex(int(time.time()*8.0))[2:].rstrip('L'), hex(int(time.time()*8.0))[2:].rstrip('L'),
self.user.nick, self.user.nick,
@ -294,6 +300,15 @@ class VT100_Client(asyncore.dispatcher):
# user config # user config
'1' if self.bell else '0']) '1' if self.bell else '0'])
try:
if self.host.user_config[self.addr[0]] == conf_str:
return
except:
pass
self.host.user_config[self.addr[0]] = conf_str
self.host.user_config_changed = True
def set_codec(self, codec_name): def set_codec(self, codec_name):
multibyte = ['utf-8','shift_jis'] multibyte = ['utf-8','shift_jis']

View File

@ -708,5 +708,6 @@ if you are using a mac, PgUp is fn-Shift-PgUp
'(^|[^a-zA-Z0-9]){0}([^a-zA-Z0-9]|$)'.format( '(^|[^a-zA-Z0-9]){0}([^a-zA-Z0-9]|$)'.format(
nick_re)) nick_re))
if self.active_chan:
self.client.save_config() self.client.save_config()