Browse Source

add __init__

this include a generate_homepage function and absorbs the mustache file.
master
nathaniel smith 4 years ago
parent
commit
1108de407d
4 changed files with 35 additions and 23 deletions
  1. +1
    -0
      MANIFEST.in
  2. +3
    -1
      setup.py
  3. +31
    -0
      tildetown/__init__.py
  4. +0
    -22
      tildetown/mustache.py

+ 1
- 0
MANIFEST.in View File

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

+ 3
- 1
setup.py View File

@@ -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',
]
},
)

+ 31
- 0
tildetown/__init__.py 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))

+ 0
- 22
tildetown/mustache.py 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))


Loading…
Cancel
Save