1 | #!/afs/bx.psu.edu/project/pythons/linux-x86_64-ucs4/bin/python2.6 |
---|
2 | |
---|
3 | def render(data): |
---|
4 | from mako.template import Template |
---|
5 | from mako.lookup import TemplateLookup |
---|
6 | |
---|
7 | lookup = TemplateLookup(["."]) |
---|
8 | return Template(data, lookup=lookup).render() |
---|
9 | |
---|
10 | def main(argv=None): |
---|
11 | from os.path import isfile |
---|
12 | from sys import stdin |
---|
13 | |
---|
14 | if argv is None: |
---|
15 | import sys |
---|
16 | argv = sys.argv |
---|
17 | |
---|
18 | from optparse import OptionParser |
---|
19 | |
---|
20 | parser = OptionParser("usage: %prog [FILENAME]") |
---|
21 | |
---|
22 | opts, args = parser.parse_args(argv[1:]) |
---|
23 | if len(args) not in (0, 1): |
---|
24 | parser.error("wrong number of arguments") # Will exit |
---|
25 | |
---|
26 | if (len(args) == 0) or (args[0] == "-"): |
---|
27 | fo = stdin |
---|
28 | else: |
---|
29 | filename = args[0] |
---|
30 | if not isfile(filename): |
---|
31 | raise SystemExit("error: can't find %s" % filename) |
---|
32 | fo = open(filename) |
---|
33 | |
---|
34 | data = fo.read() |
---|
35 | print render(data) |
---|
36 | |
---|
37 | if __name__ == "__main__": |
---|
38 | main() |
---|