add __init__

this include a generate_homepage function and absorbs the mustache file.
master
nathaniel smith 2017-04-21 23:19:17 -07:00
parent 84263dd78d
commit 1108de407d
4 changed files with 35 additions and 23 deletions

1
MANIFEST.in 100644
View File

@ -0,0 +1 @@
recursive-include tildetown/templates *

View File

@ -16,13 +16,15 @@ setup(
'Topic :: Artistic Software', 'Topic :: Artistic Software',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
], ],
include_package_data=True,
keywords='community', keywords='community',
packages=['tildetown'], packages=['tildetown'],
install_requires = ['pystache==0.5.4'], install_requires = ['pystache==0.5.4'],
entry_points = { entry_points = {
'console_scripts': [ 'console_scripts': [
'stats = tildetown.stats:main', 'stats = tildetown.stats:main',
'mustache = tildetown.mustache:main' 'mustache = tildetown.__init__:mustache',
'generate_homepage = tildetown.__init__:generate_homepage',
] ]
}, },
) )

View File

@ -0,0 +1,31 @@
import json
import os
import pkgutil
import sys
from pystache import render
from .stats import tdp
FRONTPAGE_OUTPUT_PATH = '/var/www/tilde.town/index.html'
TDP_PATH = '/var/www/tilde.town/tilde.json'
def generate_homepage():
"""This function regenerates both our tdp json file and our homepage. It is
intended to be called as root from the command-line."""
template = pkgutil.get_data('tildetown', 'templates/frontpage.html')
stats = tdp()
frontpage_output = render(template, stats)
with open(TDP_PATH, 'w') as f:
f.write(json.dumps(stats))
with open(FRONTPAGE_OUTPUT_PATH, 'w') as f:
f.write(frontpage_output)
def mustache():
with open(sys.argv[1], 'r', encoding='utf-8') as f:
template = f.read()
data = json.loads(sys.stdin.read())
sys.stdout.write(render(template, data))

View File

@ -1,22 +0,0 @@
#!/usr/bin/env python3
import json
import sys
from pystache import render
# when you install scripts with entry_points in a setup.py, the resulting
# executable just calls main() and you have to look up sys.argv yourself. I
# like to explicitly take an argv in my actual main, hence the weird
# indirection. could probably be better.
def _main(argv):
with open(argv[1], 'r', encoding='utf-8') as f:
template = f.read()
data = json.loads(sys.stdin.read())
sys.stdout.write(render(template, data))
def main():
_main(sys.argv)
if __name__ == '__main__':
exit(_main(sys.argv))