author | amit@thunder |
Fri, 12 Feb 2010 01:11:21 +0530 | |
changeset 2 | 52d12eb31c30 |
parent 0 | web/texpand.py~@8083d21c0020 |
permissions | -rwxr-xr-x |
0
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
2 |
# |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
3 |
# Use Django's template machinery to expand static web pages. First |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
4 |
# tries the default template path for a particular installation, then |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
5 |
# looks for templates in the filesystem. |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
6 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
7 |
import sys |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
8 |
sys.path.append('/home/amit/hgbook-alqua/web/hgbook') |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
9 |
from django.template import Context, TemplateDoesNotExist |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
10 |
from django.template.loader import get_template, get_template_from_string |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
11 |
from django.core.management import setup_environ |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
12 |
import hgbook.settings as settings |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
13 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
14 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
15 |
setup_environ(settings) |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
16 |
c = Context() |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
17 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
18 |
if len(sys.argv) == 2: |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
19 |
in_name = sys.argv[1] |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
20 |
out_name = 'stdout' |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
21 |
out_fp = sys.stdout |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
22 |
elif len(sys.argv) == 3: |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
23 |
in_name = sys.argv[1] |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
24 |
out_name = sys.argv[2] |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
25 |
out_fp = None |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
26 |
else: |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
27 |
print >> sys.stderr, 'Usage: %s template-file [output-file]' |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
28 |
sys.exit(1) |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
29 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
30 |
try: |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
31 |
t = get_template(in_name) |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
32 |
except TemplateDoesNotExist: |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
33 |
t = get_template_from_string(open(in_name).read(), name=in_name) |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
34 |
if out_fp is None: |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
35 |
out_fp = open(out_name, 'w') |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
36 |
out_fp.write(t.render(c)) |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
37 |
out_fp.close() |