Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: native_client_sdk/src/build_tools/easy_template.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698