OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import copy | 6 import copy |
7 import cStringIO | 7 import cStringIO |
8 import optparse | 8 import argparse |
binji
2014/11/13 23:57:01
sort
Sam Clegg
2014/11/30 17:55:11
Done.
| |
9 import os | 9 import os |
10 import re | 10 import re |
11 import sys | 11 import sys |
12 | 12 |
13 | 13 |
14 STATEMENT_RE = "\[\[(.*?)\]\]" # [[...]] | 14 STATEMENT_RE = "\[\[(.*?)\]\]" # [[...]] |
15 EXPR_RE = "\{\{(.*?)\}\}" # {{...}} | 15 EXPR_RE = "\{\{(.*?)\}\}" # {{...}} |
16 | 16 |
17 def TemplateToPython(template, statement_re, expr_re): | 17 def TemplateToPython(template, statement_re, expr_re): |
18 output = cStringIO.StringIO() | 18 output = cStringIO.StringIO() |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 | 91 |
92 | 92 |
93 def RunTemplateString(src, template_dict, statement_re=None, expr_re=None): | 93 def RunTemplateString(src, template_dict, statement_re=None, expr_re=None): |
94 srcstr = cStringIO.StringIO(src) | 94 srcstr = cStringIO.StringIO(src) |
95 dststr = cStringIO.StringIO() | 95 dststr = cStringIO.StringIO() |
96 RunTemplate(srcstr, dststr, template_dict, statement_re, expr_re) | 96 RunTemplate(srcstr, dststr, template_dict, statement_re, expr_re) |
97 return dststr.getvalue() | 97 return dststr.getvalue() |
98 | 98 |
99 | 99 |
100 def main(args): | 100 def main(args): |
101 parser = optparse.OptionParser() | 101 parser = argparse.ArgumentParser() |
102 _, args = parser.parse_args(args) | 102 parser.add_arguments('template') |
103 if not args: | 103 options = parser.parse_args(args) |
104 return | |
105 | 104 |
106 with open(args[0]) as f: | 105 with open(options.templet) as f: |
binji
2014/11/13 23:57:01
template
Sam Clegg
2014/11/30 17:55:11
Done.
binji
2014/12/08 21:58:20
template :)
Sam Clegg
2015/01/14 15:28:32
Done.
| |
107 print TemplateToPython( | 106 print TemplateToPython( |
108 f.read(), re.compile(STATEMENT_RE), re.compile(EXPR_RE)) | 107 f.read(), re.compile(STATEMENT_RE), re.compile(EXPR_RE)) |
109 | 108 |
110 if __name__ == '__main__': | 109 if __name__ == '__main__': |
111 sys.exit(main(sys.argv[1:])) | 110 sys.exit(main(sys.argv[1:])) |
OLD | NEW |