From b6494fbb137e46f30551104324b92925c080460d Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 23 Jan 2018 03:33:06 +0100 Subject: [PATCH] save cfg every 10min unless there's no changes --- r0c/__main__.py | 6 ++++++ r0c/ivt100.py | 17 ++++++++++++++++- r0c/user.py | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/r0c/__main__.py b/r0c/__main__.py index 885fc2e..0dd3043 100644 --- a/r0c/__main__.py +++ b/r0c/__main__.py @@ -161,6 +161,7 @@ class Core(object): def push_worker(self, world, ifaces): self.pushthr_alive = True + nth_iter = 0 last_ts = None last_date = None while not self.stopping: @@ -190,6 +191,11 @@ class Core(object): if not client.handshake_sz: pass client.refresh(False) + + nth_iter += 1 + if nth_iter % 600 == 0: + for iface in ifaces: + iface.save_configs() self.pushthr_alive = False diff --git a/r0c/ivt100.py b/r0c/ivt100.py index 87dcd9f..81b9bbc 100644 --- a/r0c/ivt100.py +++ b/r0c/ivt100.py @@ -36,6 +36,7 @@ class VT100_Server(asyncore.dispatcher): self.clients = [] self.user_config = {} self.user_config_path = None + self.user_config_changed = False self.create_socket(socket.AF_INET, socket.SOCK_STREAM) if PY2: 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') self.user_config = {} + self.user_config_changed = False if not os.path.isfile(self.user_config_path): print(' * {0} loaded 0 client configs'.format(self.__class__.__name__)) return @@ -113,6 +115,10 @@ class VT100_Server(asyncore.dispatcher): def save_configs(self): 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: f.write('1\n'.encode('utf-8')) for k, v in sorted(self.user_config.items()): @@ -279,7 +285,7 @@ class VT100_Client(asyncore.dispatcher): def save_config(self): 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'), self.user.nick, @@ -294,6 +300,15 @@ class VT100_Client(asyncore.dispatcher): # user config '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): multibyte = ['utf-8','shift_jis'] diff --git a/r0c/user.py b/r0c/user.py index 93d1f41..7361cd5 100644 --- a/r0c/user.py +++ b/r0c/user.py @@ -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( nick_re)) - self.client.save_config() + if self.active_chan: + self.client.save_config()