diff --git a/tsstats/__main__.py b/tsstats/__main__.py index 66dd1b2..4f12778 100644 --- a/tsstats/__main__.py +++ b/tsstats/__main__.py @@ -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), diff --git a/tsstats/config.py b/tsstats/config.py index 056f912..bbcb086 100644 --- a/tsstats/config.py +++ b/tsstats/config.py @@ -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' + ) } }