Add cache cli- and config-option

* --disablecache (config: cache, True by default)
* --cachepath (config: cachepath, $XDG_CACHE_HOME or $HOME|/tmp
by default)
This commit is contained in:
Thor77 2018-01-19 23:09:47 +01:00
parent 662a359c4f
commit 74444edd55
2 changed files with 19 additions and 2 deletions

View File

@ -68,6 +68,15 @@ def cli():
help='render last seen timestamp absolute (instead of relative)',
action='store_false', dest='lastseenrelative'
)
parser.add_argument(
'-dc', '--disablecache',
help='disable caching feature',
action='store_false', dest='cache'
)
parser.add_argument(
'-cp', '--cachepath',
type=str, help='Path for cache location'
)
options = parser.parse_args()
if 'config' in options:
configuration = config.load(options.config)
@ -111,7 +120,10 @@ def main(configuration):
servers = parse_logs(
log, ident_map=identmap,
online_dc=configuration.getboolean('General', 'onlinedc')
online_dc=configuration.getboolean('General', 'onlinedc'),
cache_path=pathjoin(
configuration.get('General', 'cachepath'), 'tsstats.pickle'
) if configuration.getboolean('General', 'cache') else None
)
render_servers(
sorted(servers, key=lambda s: s.sid),

View File

@ -4,6 +4,7 @@ try:
except ImportError:
from ConfigParser import RawConfigParser
import os
import logging
logger = logging.getLogger('tsstats')
@ -20,7 +21,11 @@ DEFAULT_CONFIG = {
'template': 'index.jinja2',
'datetimeformat': '%x %X %Z',
'onlinetimethreshold': -1,
'lastseenrelative': True
'lastseenrelative': True,
'cache': True,
'cachepath': os.environ.get('XDG_CACHE_HOME') or os.path.join(
os.environ.get('HOME', '/tmp'), '.cache'
)
}
}