hgbook

view web/texpand.py @ 787:d511cb890aa9

Better translation of Mercurial abort message.
author Giulio@puck
date Tue Aug 11 18:08:00 2009 +0200 (2009-08-11)
parents ad304b606163
children
line source
1 #!/usr/bin/env python
2 #
3 # Use Django's template machinery to expand static web pages. First
4 # tries the default template path for a particular installation, then
5 # looks for templates in the filesystem.
7 from django.template import Context, TemplateDoesNotExist
8 from django.template.loader import get_template, get_template_from_string
9 from django.core.management import setup_environ
10 import hgbook.settings as settings
11 import sys
13 setup_environ(settings)
14 c = Context()
16 if len(sys.argv) == 2:
17 in_name = sys.argv[1]
18 out_name = 'stdout'
19 out_fp = sys.stdout
20 elif len(sys.argv) == 3:
21 in_name = sys.argv[1]
22 out_name = sys.argv[2]
23 out_fp = None
24 else:
25 print >> sys.stderr, 'Usage: %s template-file [output-file]'
26 sys.exit(1)
28 try:
29 t = get_template(in_name)
30 except TemplateDoesNotExist:
31 t = get_template_from_string(open(in_name).read(), name=in_name)
32 if out_fp is None:
33 out_fp = open(out_name, 'w')
34 out_fp.write(t.render(c))
35 out_fp.close()