diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..3358463 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include tildetown/templates * \ No newline at end of file diff --git a/setup.py b/setup.py index 605a0da..b8002fb 100644 --- a/setup.py +++ b/setup.py @@ -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', ] }, ) diff --git a/tildetown/__init__.py b/tildetown/__init__.py index e69de29..83992d2 100644 --- a/tildetown/__init__.py +++ b/tildetown/__init__.py @@ -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)) diff --git a/tildetown/mustache.py b/tildetown/mustache.py deleted file mode 100644 index 75eed52..0000000 --- a/tildetown/mustache.py +++ /dev/null @@ -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)) -