equal
deleted
inserted
replaced
|
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. |
|
6 |
|
7 import sys |
|
8 sys.path.append('/home/amit/hgbook-alqua/web/hgbook') |
|
9 from django.template import Context, TemplateDoesNotExist |
|
10 from django.template.loader import get_template, get_template_from_string |
|
11 from django.core.management import setup_environ |
|
12 import hgbook.settings as settings |
|
13 |
|
14 |
|
15 setup_environ(settings) |
|
16 c = Context() |
|
17 |
|
18 if len(sys.argv) == 2: |
|
19 in_name = sys.argv[1] |
|
20 out_name = 'stdout' |
|
21 out_fp = sys.stdout |
|
22 elif len(sys.argv) == 3: |
|
23 in_name = sys.argv[1] |
|
24 out_name = sys.argv[2] |
|
25 out_fp = None |
|
26 else: |
|
27 print >> sys.stderr, 'Usage: %s template-file [output-file]' |
|
28 sys.exit(1) |
|
29 |
|
30 try: |
|
31 t = get_template(in_name) |
|
32 except TemplateDoesNotExist: |
|
33 t = get_template_from_string(open(in_name).read(), name=in_name) |
|
34 if out_fp is None: |
|
35 out_fp = open(out_name, 'w') |
|
36 out_fp.write(t.render(c)) |
|
37 out_fp.close() |