hgbook
diff web/texpand.py @ 653:6b1577ef5135
Update Chinese translation
author | Dongsheng Song <dongsheng.song@gmail.com> |
---|---|
date | Fri Mar 20 17:17:55 2009 +0800 (2009-03-20) |
parents | |
children | 7893b3824715 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/web/texpand.py Fri Mar 20 17:17:55 2009 +0800 1.3 @@ -0,0 +1,35 @@ 1.4 +#!/usr/bin/env python 1.5 +# 1.6 +# Use Django's template machinery to expand static web pages. First 1.7 +# tries the default template path for a particular installation, then 1.8 +# looks for templates in the filesystem. 1.9 + 1.10 +from django.template import Context, TemplateDoesNotExist 1.11 +from django.template.loader import get_template, get_template_from_string 1.12 +from django.core.management import setup_environ 1.13 +import rwh.settings as settings 1.14 +import sys 1.15 + 1.16 +setup_environ(settings) 1.17 +c = Context() 1.18 + 1.19 +if len(sys.argv) == 2: 1.20 + in_name = sys.argv[1] 1.21 + out_name = 'stdout' 1.22 + out_fp = sys.stdout 1.23 +elif len(sys.argv) == 3: 1.24 + in_name = sys.argv[1] 1.25 + out_name = sys.argv[2] 1.26 + out_fp = None 1.27 +else: 1.28 + print >> sys.stderr, 'Usage: %s template-file [output-file]' 1.29 + sys.exit(1) 1.30 + 1.31 +try: 1.32 + t = get_template(in_name) 1.33 +except TemplateDoesNotExist: 1.34 + t = get_template_from_string(open(in_name).read(), name=in_name) 1.35 +if out_fp is None: 1.36 + out_fp = open(out_name, 'w') 1.37 +out_fp.write(t.render(c)) 1.38 +out_fp.close()