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.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = '0.5'
|
version = '0.6'
|
||||||
# The full version, including alpha/beta/rc tags.
|
# 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
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='tsstats',
|
name='tsstats',
|
||||||
version='0.5.9',
|
version='0.6.0',
|
||||||
author='Thor77',
|
author='Thor77',
|
||||||
author_email='thor77@thor77.org',
|
author_email='thor77@thor77.org',
|
||||||
description='A simple Teamspeak stats-generator',
|
description='A simple Teamspeak stats-generator',
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from os.path import abspath
|
from os.path import dirname
|
||||||
from time import localtime, strftime
|
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
|
from tsstats.utils import seconds_to_text, sort_clients
|
||||||
|
|
||||||
logger = logging.getLogger('tsstats')
|
logger = logging.getLogger('tsstats')
|
||||||
|
|
||||||
|
|
||||||
def render_template(clients, output, template_name='tsstats/template.html',
|
def render_template(clients, output, title='TeamspeakStats'):
|
||||||
title='TeamspeakStats'):
|
|
||||||
'''
|
'''
|
||||||
render template with `clients`
|
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)]
|
('Bans', clients_bans), ('passive Bans', clients_pbans)]
|
||||||
|
|
||||||
# render
|
# render
|
||||||
template_loader = FileSystemLoader(abspath('.'))
|
template_loader = ChoiceLoader([
|
||||||
|
PackageLoader(__package__, ''),
|
||||||
|
FileSystemLoader(dirname(__file__))
|
||||||
|
])
|
||||||
template_env = Environment(loader=template_loader)
|
template_env = Environment(loader=template_loader)
|
||||||
|
|
||||||
def fmttime(timestamp):
|
def fmttime(timestamp):
|
||||||
return strftime('%x %X', localtime(int(timestamp)))
|
return strftime('%x %X', localtime(int(timestamp)))
|
||||||
template_env.filters['frmttime'] = fmttime
|
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:
|
with open(output, 'w') as f:
|
||||||
f.write(template.render(title=title, objs=objs,
|
f.write(template.render(title=title, objs=objs,
|
||||||
debug=logger.level <= logging.DEBUG))
|
debug=logger.level <= logging.DEBUG))
|
||||||
|
|
Loading…
Reference in New Issue