bos@574: #!/usr/bin/env python bos@574: # bos@574: # Use Django's template machinery to expand static web pages. First bos@574: # tries the default template path for a particular installation, then bos@574: # looks for templates in the filesystem. bos@574: bos@574: from django.template import Context, TemplateDoesNotExist bos@574: from django.template.loader import get_template, get_template_from_string bos@574: from django.core.management import setup_environ bos@574: import rwh.settings as settings bos@574: import sys bos@574: bos@574: setup_environ(settings) bos@574: c = Context() bos@574: bos@574: if len(sys.argv) == 2: bos@574: in_name = sys.argv[1] bos@574: out_name = 'stdout' bos@574: out_fp = sys.stdout bos@574: elif len(sys.argv) == 3: bos@574: in_name = sys.argv[1] bos@574: out_name = sys.argv[2] bos@574: out_fp = None bos@574: else: bos@574: print >> sys.stderr, 'Usage: %s template-file [output-file]' bos@574: sys.exit(1) bos@574: bos@574: try: bos@574: t = get_template(in_name) bos@574: except TemplateDoesNotExist: bos@574: t = get_template_from_string(open(in_name).read(), name=in_name) bos@574: if out_fp is None: bos@574: out_fp = open(out_name, 'w') bos@574: out_fp.write(t.render(c)) bos@574: out_fp.close()