refactor tsstats.log.parse_log(s)
* rename tsstats.log.parse_logs to tsstats.log.parse_log and remove glob-functionality * create tsstats.log.parse_log to handle globbing * fix tests to use tsstats.log.parse_log instead of tsstats.log.parse_logs * bump version to 0.4.0
This commit is contained in:
parent
1f5a6211b9
commit
53ffad3d81
|
@ -54,9 +54,9 @@ author = 'Thor77'
|
|||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.3'
|
||||
version = '0.4'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.3.0'
|
||||
release = '0.4.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup
|
|||
|
||||
setup(
|
||||
name='tsstats',
|
||||
version='0.3.0',
|
||||
version='0.4.0',
|
||||
author='Thor77',
|
||||
author_email='thor77@thor77.org',
|
||||
description='A simple Teamspeak stats-generator',
|
||||
|
|
|
@ -14,41 +14,41 @@ re_disconnect_invoker = re.compile(
|
|||
logger = logging.getLogger('tsstats')
|
||||
|
||||
|
||||
def parse_logs(log_path, ident_map=None):
|
||||
def parse_logs(log_glob, ident_map=None):
|
||||
for log_file in sorted(log_file for log_file in glob(log_glob)):
|
||||
parse_log(log_file, ident_map)
|
||||
|
||||
|
||||
def parse_log(log_path, ident_map=None):
|
||||
clients = Clients(ident_map)
|
||||
|
||||
# find all log-files and open them TODO: move this into main
|
||||
file_paths = sorted([file_path for file_path in glob(log_path)])
|
||||
|
||||
for file_path in file_paths:
|
||||
log_file = open(file_path)
|
||||
# process lines
|
||||
logger.debug('Started parsing of %s', log_file.name)
|
||||
for line in log_file:
|
||||
parts = line.split('|')
|
||||
log_format = '%Y-%m-%d %H:%M:%S.%f'
|
||||
stripped_time = datetime.strptime(parts[0], log_format)
|
||||
logdatetime = int((stripped_time - datetime(1970, 1, 1))
|
||||
.total_seconds())
|
||||
data = '|'.join(parts[4:]).strip()
|
||||
if data.startswith('client'):
|
||||
nick, clid = re_dis_connect.findall(data)[0]
|
||||
client = clients.setdefault(clid, Client(clid, nick))
|
||||
client.nick = nick # set nick to display changes
|
||||
if data.startswith('client connected'):
|
||||
client.connect(logdatetime)
|
||||
elif data.startswith('client disconnected'):
|
||||
client.disconnect(logdatetime)
|
||||
if 'invokeruid' in data:
|
||||
re_disconnect_data = re_disconnect_invoker.findall(
|
||||
data)
|
||||
invokernick, invokeruid = re_disconnect_data[0]
|
||||
invoker = clients.setdefault(invokeruid,
|
||||
Client(invokeruid))
|
||||
invoker.nick = invokernick
|
||||
if 'bantime' in data:
|
||||
invoker.ban(client)
|
||||
else:
|
||||
invoker.kick(client)
|
||||
logger.debug('Finished parsing of %s', log_file.name)
|
||||
log_file = open(log_path)
|
||||
# process lines
|
||||
logger.debug('Started parsing of %s', log_file.name)
|
||||
for line in log_file:
|
||||
parts = line.split('|')
|
||||
log_format = '%Y-%m-%d %H:%M:%S.%f'
|
||||
stripped_time = datetime.strptime(parts[0], log_format)
|
||||
logdatetime = int((stripped_time - datetime(1970, 1, 1))
|
||||
.total_seconds())
|
||||
data = '|'.join(parts[4:]).strip()
|
||||
if data.startswith('client'):
|
||||
nick, clid = re_dis_connect.findall(data)[0]
|
||||
client = clients.setdefault(clid, Client(clid, nick))
|
||||
client.nick = nick # set nick to display changes
|
||||
if data.startswith('client connected'):
|
||||
client.connect(logdatetime)
|
||||
elif data.startswith('client disconnected'):
|
||||
client.disconnect(logdatetime)
|
||||
if 'invokeruid' in data:
|
||||
re_disconnect_data = re_disconnect_invoker.findall(
|
||||
data)
|
||||
invokernick, invokeruid = re_disconnect_data[0]
|
||||
invoker = clients.setdefault(invokeruid,
|
||||
Client(invokeruid))
|
||||
invoker.nick = invokernick
|
||||
if 'bantime' in data:
|
||||
invoker.ban(client)
|
||||
else:
|
||||
invoker.kick(client)
|
||||
logger.debug('Finished parsing of %s', log_file.name)
|
||||
return clients
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import pytest
|
||||
|
||||
from tsstats.exceptions import InvalidLog
|
||||
from tsstats.log import parse_logs
|
||||
from tsstats.log import parse_log
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def clients():
|
||||
return parse_logs('tsstats/tests/res/test.log')
|
||||
return parse_log('tsstats/tests/res/test.log')
|
||||
|
||||
|
||||
def test_log_client_count(clients):
|
||||
|
@ -36,4 +36,4 @@ def test_log_pbans(clients):
|
|||
|
||||
def test_log_invalid():
|
||||
with pytest.raises(InvalidLog):
|
||||
parse_logs('tsstats/tests/res/test.log.broken')
|
||||
parse_log('tsstats/tests/res/test.log.broken')
|
||||
|
|
|
@ -4,12 +4,12 @@ from os import remove
|
|||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from tsstats.log import parse_logs
|
||||
from tsstats.log import parse_log
|
||||
from tsstats.template import render_template
|
||||
from tsstats.utils import seconds_to_text
|
||||
|
||||
output_path = 'tsstats/tests/res/output.html'
|
||||
clients = parse_logs('tsstats/tests/res/test.log')
|
||||
clients = parse_log('tsstats/tests/res/test.log')
|
||||
|
||||
logger = logging.getLogger('tsstats')
|
||||
|
||||
|
|
Loading…
Reference in New Issue