diff --git a/docs/source/conf.py b/docs/source/conf.py index 8e520e1..0c8690e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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. diff --git a/setup.py b/setup.py index 75f3706..3abc610 100644 --- a/setup.py +++ b/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', diff --git a/tsstats/log.py b/tsstats/log.py index 44ee296..711ed3e 100644 --- a/tsstats/log.py +++ b/tsstats/log.py @@ -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 diff --git a/tsstats/tests/test_log.py b/tsstats/tests/test_log.py index 18e5f04..338f841 100644 --- a/tsstats/tests/test_log.py +++ b/tsstats/tests/test_log.py @@ -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') diff --git a/tsstats/tests/test_template.py b/tsstats/tests/test_template.py index 9b378a8..84710e0 100644 --- a/tsstats/tests/test_template.py +++ b/tsstats/tests/test_template.py @@ -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')