From 91a9b8e4c784429f34f5c882408fb71a52babda4 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Wed, 23 Aug 2017 20:57:40 +0200 Subject: [PATCH] Implement online_dc again --- tsstats/log.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tsstats/log.py b/tsstats/log.py index 10bf0ee..a729f7a 100644 --- a/tsstats/log.py +++ b/tsstats/log.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -# TODO: Implemented online_dc again import itertools import logging import re @@ -125,17 +124,25 @@ def parse_logs(log_glob, ident_map=None, online_dc=True, *args, **kwargs): ''' for virtualserver_id, logs in _bundle_logs(glob(log_glob)).items(): clients = Clients(ident_map) - for log in logs: + for index, log in enumerate(logs): with open(log.path, encoding='utf-8') as f: # parse logfile line by line and filter lines without events events = filter(None, map(_parse_line, f)) # chain apply events to Client-obj clients.apply_events(itertools.chain.from_iterable(events)) - # warn for online clients + + # find connected clients online_clients = list(filter(lambda c: c.connected, clients)) + logger.debug( - 'Some clients are still connected: %s' % online_clients + 'Some clients are still connected: %s', online_clients ) + if index == len(logs) - 1 and online_dc: + logger.debug('Last log => disconnecting online clients') + # last iteration => disconnect online clients if desired + for online_client in online_clients: + online_client.disconnect(pendulum.utcnow()) + online_client.connected += 1 if len(clients) >= 1: # assemble Server-obj and yield yield Server(virtualserver_id, clients)