hgbook

view web/texpand.py @ 650:7e7c47481e4f

Oops, this is the real merge for my hg's oddity
author Dongsheng Song <dongsheng.song@gmail.com>
date Fri Mar 20 16:43:35 2009 +0800 (2009-03-20)
parents
children 7893b3824715
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 rwh.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()