mirror of
				https://github.com/Thor77/TeamspeakStats.git
				synced 2025-11-03 23:32:45 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									662a359c4f
								
							
						
					
					
						commit
						74444edd55
					
				
					 2 changed files with 19 additions and 2 deletions
				
			
		| 
						 | 
					@ -68,6 +68,15 @@ def cli():
 | 
				
			||||||
        help='render last seen timestamp absolute (instead of relative)',
 | 
					        help='render last seen timestamp absolute (instead of relative)',
 | 
				
			||||||
        action='store_false', dest='lastseenrelative'
 | 
					        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()
 | 
					    options = parser.parse_args()
 | 
				
			||||||
    if 'config' in options:
 | 
					    if 'config' in options:
 | 
				
			||||||
        configuration = config.load(options.config)
 | 
					        configuration = config.load(options.config)
 | 
				
			||||||
| 
						 | 
					@ -111,7 +120,10 @@ def main(configuration):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    servers = parse_logs(
 | 
					    servers = parse_logs(
 | 
				
			||||||
        log, ident_map=identmap,
 | 
					        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(
 | 
					    render_servers(
 | 
				
			||||||
        sorted(servers, key=lambda s: s.sid),
 | 
					        sorted(servers, key=lambda s: s.sid),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ try:
 | 
				
			||||||
except ImportError:
 | 
					except ImportError:
 | 
				
			||||||
    from ConfigParser import RawConfigParser
 | 
					    from ConfigParser import RawConfigParser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
logger = logging.getLogger('tsstats')
 | 
					logger = logging.getLogger('tsstats')
 | 
				
			||||||
| 
						 | 
					@ -20,7 +21,11 @@ DEFAULT_CONFIG = {
 | 
				
			||||||
        'template': 'index.jinja2',
 | 
					        'template': 'index.jinja2',
 | 
				
			||||||
        'datetimeformat': '%x %X %Z',
 | 
					        'datetimeformat': '%x %X %Z',
 | 
				
			||||||
        'onlinetimethreshold': -1,
 | 
					        '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'
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue