refactor template-loading
* use ChoiceLoader([PackageLoader, FileSystemLoader]) instead of FileSystemLoader * add PackageLoader to allow template-access on egg-installations * use correct way to get filesystem-path to package (dirname(__file__)) * remove superflous template_name-arg from tsstats.template.render_template * bump version to 0.6.0
This commit is contained in:
parent
52a05acdab
commit
fe29b6f050
|
@ -54,9 +54,9 @@ author = 'Thor77'
|
|||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.5'
|
||||
version = '0.6'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.5.9'
|
||||
release = '0.6.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup
|
|||
|
||||
setup(
|
||||
name='tsstats',
|
||||
version='0.5.9',
|
||||
version='0.6.0',
|
||||
author='Thor77',
|
||||
author_email='thor77@thor77.org',
|
||||
description='A simple Teamspeak stats-generator',
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
from os.path import abspath
|
||||
from os.path import dirname
|
||||
from time import localtime, strftime
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from jinja2 import ChoiceLoader, Environment, FileSystemLoader, PackageLoader
|
||||
|
||||
from tsstats.utils import seconds_to_text, sort_clients
|
||||
|
||||
logger = logging.getLogger('tsstats')
|
||||
|
||||
|
||||
def render_template(clients, output, template_name='tsstats/template.html',
|
||||
title='TeamspeakStats'):
|
||||
def render_template(clients, output, title='TeamspeakStats'):
|
||||
'''
|
||||
render template with `clients`
|
||||
|
||||
|
@ -42,13 +41,16 @@ def render_template(clients, output, template_name='tsstats/template.html',
|
|||
('Bans', clients_bans), ('passive Bans', clients_pbans)]
|
||||
|
||||
# render
|
||||
template_loader = FileSystemLoader(abspath('.'))
|
||||
template_loader = ChoiceLoader([
|
||||
PackageLoader(__package__, ''),
|
||||
FileSystemLoader(dirname(__file__))
|
||||
])
|
||||
template_env = Environment(loader=template_loader)
|
||||
|
||||
def fmttime(timestamp):
|
||||
return strftime('%x %X', localtime(int(timestamp)))
|
||||
template_env.filters['frmttime'] = fmttime
|
||||
template = template_env.get_template(template_name)
|
||||
template = template_env.get_template('template.html')
|
||||
with open(output, 'w') as f:
|
||||
f.write(template.render(title=title, objs=objs,
|
||||
debug=logger.level <= logging.DEBUG))
|
||||
|
|
Loading…
Reference in New Issue