Use pendulum instead of plain datetime

because it is more intuitive to use and doesn't require the
tz_aware_datetime-workaround.
This commit is contained in:
Thor77 2017-05-20 00:31:26 +02:00
parent 3d469ce28c
commit 4d03e7d096
1 changed files with 7 additions and 8 deletions

View File

@ -4,13 +4,13 @@ import logging
import re import re
from codecs import open from codecs import open
from collections import namedtuple from collections import namedtuple
from datetime import datetime
from glob import glob from glob import glob
from os.path import basename from os.path import basename
from time import time from time import time
import pendulum
from tsstats.client import Client, Clients from tsstats.client import Client, Clients
from tsstats.utils import tz_aware_datime
re_log_filename = re.compile(r'ts3server_(?P<date>\d{4}-\d\d-\d\d)' re_log_filename = re.compile(r'ts3server_(?P<date>\d{4}-\d\d-\d\d)'
'__(?P<time>\d\d_\d\d_\d\d.\d+)_(?P<sid>\d).log') '__(?P<time>\d\d_\d\d_\d\d.\d+)_(?P<sid>\d).log')
@ -81,9 +81,9 @@ def _bundle_logs(logs):
match = re_log_filename.match(basename(log)) match = re_log_filename.match(basename(log))
if match: if match:
match = match.groupdict() match = match.groupdict()
timestamp = datetime.strptime('{0} {1}'.format( timestamp = pendulum.parse('{0} {1}'.format(
match['date'], match['time'].replace('_', ':')), match['date'], match['time'].replace('_', ':'))
log_timestamp_format) )
tl = TimedLog(log, timestamp) tl = TimedLog(log, timestamp)
sid = match['sid'] sid = match['sid']
if sid in vserver_logfiles: if sid in vserver_logfiles:
@ -136,8 +136,7 @@ def _parse_details(log_path, ident_map=None, clients=None, online_dc=True):
logger.debug('No match: "%s"', line) logger.debug('No match: "%s"', line)
continue continue
match = match.groupdict() match = match.groupdict()
logdatetime = tz_aware_datime(datetime.strptime(match['timestamp'], logdatetime = pendulum.parse(match['timestamp'])
log_timestamp_format))
message = match['message'] message = match['message']
if message.startswith('client'): if message.startswith('client'):
match = re_dis_connect.match(message) match = re_dis_connect.match(message)
@ -178,7 +177,7 @@ def _parse_details(log_path, ident_map=None, clients=None, online_dc=True):
] ]
if online_dc: if online_dc:
def _reconnect(client): def _reconnect(client):
client.disconnect(tz_aware_datime(datetime.utcnow())) client.disconnect(pendulum.now())
client.connected += 1 client.connected += 1
[_reconnect(client) for client in clients if client.connected] [_reconnect(client) for client in clients if client.connected]
logger.debug( logger.debug(