add __init__

this include a generate_homepage function and absorbs the mustache file.
master
nathaniel smith 6 years ago
parent 84263dd78d
commit 1108de407d
  1. 1
      MANIFEST.in
  2. 4
      setup.py
  3. 31
      tildetown/__init__.py
  4. 22
      tildetown/mustache.py

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

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

@ -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))

@ -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))
Loading…
Cancel
Save