Last change
on this file since 3023 was
2977,
checked in by gdb, 15 years ago
|
Added an invirt mako render script.
|
-
Property svn:executable set to
*
|
File size:
998 bytes
|
Rev | Line | |
---|
[2977] | 1 | #!/usr/bin/python |
---|
| 2 | # Modified from mako-render by gdb. |
---|
| 3 | # TODO: set the lookup path dynamically. |
---|
| 4 | |
---|
| 5 | def render(data): |
---|
| 6 | from mako.template import Template |
---|
| 7 | from mako.lookup import TemplateLookup |
---|
| 8 | |
---|
| 9 | lookup = TemplateLookup(['.', '/etc/apache2/conf.invirt']) |
---|
| 10 | return Template(data, lookup=lookup).render() |
---|
| 11 | |
---|
| 12 | def main(argv=None): |
---|
| 13 | from os.path import isfile |
---|
| 14 | from sys import stdin |
---|
| 15 | |
---|
| 16 | if argv is None: |
---|
| 17 | import sys |
---|
| 18 | argv = sys.argv |
---|
| 19 | |
---|
| 20 | from optparse import OptionParser |
---|
| 21 | |
---|
| 22 | parser = OptionParser("usage: %prog [FILENAME]") |
---|
| 23 | |
---|
| 24 | opts, args = parser.parse_args(argv[1:]) |
---|
| 25 | if len(args) not in (0, 1): |
---|
| 26 | parser.error("wrong number of arguments") # Will exit |
---|
| 27 | |
---|
| 28 | if (len(args) == 0) or (args[0] == "-"): |
---|
| 29 | fo = stdin |
---|
| 30 | else: |
---|
| 31 | filename = args[0] |
---|
| 32 | if not isfile(filename): |
---|
| 33 | raise SystemExit("error: can't find %s" % filename) |
---|
| 34 | fo = open(filename) |
---|
| 35 | |
---|
| 36 | data = fo.read() |
---|
| 37 | print render(data) |
---|
| 38 | |
---|
| 39 | if __name__ == "__main__": |
---|
| 40 | main() |
---|
Note: See
TracBrowser
for help on using the repository browser.