Add ability to pass a directory for --log option

If you pass a directory, it will now tack a '*.log' glob on the end of
the path to automatically use all log files inside this directory.
This commit is contained in:
Matthew Gamble 2017-03-09 08:41:41 +11:00
parent cb42b9ee2a
commit f248ad833f
No known key found for this signature in database
GPG key ID: B5D06189C3995B3B
2 changed files with 6 additions and 3 deletions

View file

@ -21,7 +21,8 @@ To start, you can just use cli-arguments to control the behaviour of TeamspeakSt
-c CONFIG, --config CONFIG -c CONFIG, --config CONFIG
path to config path to config
--idmap IDMAP path to id_map --idmap IDMAP path to id_map
-l LOG, --log LOG path to your logfile(s) -l LOG, --log LOG path to your logfile(s). pass a directory to use all
logfiles inside it
-o OUTPUT, --output OUTPUT -o OUTPUT, --output OUTPUT
path to the output-file path to the output-file
-d, --debug debug mode -d, --debug debug mode

View file

@ -3,7 +3,7 @@
import argparse import argparse
import json import json
import logging import logging
from os.path import abspath, exists from os.path import abspath, exists, isdir, join as pathjoin
from tsstats import config from tsstats import config
from tsstats.exceptions import InvalidConfiguration from tsstats.exceptions import InvalidConfiguration
@ -30,7 +30,7 @@ def cli():
) )
parser.add_argument( parser.add_argument(
'-l', '--log', '-l', '--log',
type=str, help='path to your logfile(s)' type=str, help='path to your logfile(s). pass a directory to use all logfiles inside it'
) )
parser.add_argument( parser.add_argument(
'-o', '--output', '-o', '--output',
@ -98,6 +98,8 @@ def main(configuration):
log = configuration.get('General', 'log') log = configuration.get('General', 'log')
if not log: if not log:
raise InvalidConfiguration('log or output missing') raise InvalidConfiguration('log or output missing')
if isdir(log):
log = pathjoin(log, '*.log')
servers = parse_logs( servers = parse_logs(
log, ident_map=identmap, log, ident_map=identmap,