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

Side by Side Diff: native_client_sdk/src/tools/tests/chrome_mock.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 5 years, 11 months 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) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 optparse 6 """Mock chrome process used by test code for http server."""
7
8 import argparse
7 import sys 9 import sys
8 import time 10 import time
9 import urllib2 11 import urllib2
10 12
11 def PrintAndFlush(s): 13 def PrintAndFlush(s):
12 print s 14 sys.stdout.write(s + '\n')
13 sys.stdout.flush() 15 sys.stdout.flush()
14 16
15 def main(args): 17 def main(args):
16 parser = optparse.OptionParser(usage='%prog [options] <URL to load>') 18 parser = argparse.ArgumentParser(description=__doc__)
17 parser.add_option('--post', help='POST to URL.', dest='post', 19 parser.add_argument('--post', help='POST to URL.', dest='post',
18 action='store_true') 20 action='store_true')
19 parser.add_option('--get', help='GET to URL.', dest='get', 21 parser.add_argument('--get', help='GET to URL.', dest='get',
20 action='store_true') 22 action='store_true')
21 parser.add_option('--sleep', 23 parser.add_argument('--sleep',
22 help='Number of seconds to sleep after reading URL', 24 help='Number of seconds to sleep after reading URL',
23 dest='sleep', default=0) 25 dest='sleep', default=0)
24 parser.add_option('--expect-to-be-killed', help='If set, the script will warn' 26 parser.add_argument('--expect-to-be-killed', help='If set, the script will'
25 ' if it isn\'t killed before it finishes sleeping.', 27 ' warn if it isn\'t killed before it finishes sleeping.',
26 dest='expect_to_be_killed', action='store_true') 28 dest='expect_to_be_killed', action='store_true')
27 options, args = parser.parse_args(args) 29 parser.add_argument('url')
28 if len(args) != 1: 30
29 parser.error('Expected URL to load.') 31 options = parser.parse_args(args)
30 32
31 PrintAndFlush('Starting %s.' % sys.argv[0]) 33 PrintAndFlush('Starting %s.' % sys.argv[0])
32 34
33 if options.post: 35 if options.post:
34 urllib2.urlopen(args[0], data='').read() 36 urllib2.urlopen(options.url, data='').read()
35 elif options.get: 37 elif options.get:
36 urllib2.urlopen(args[0]).read() 38 urllib2.urlopen(options.url).read()
37 else: 39 else:
38 # Do nothing but wait to be killed. 40 # Do nothing but wait to be killed.
39 pass 41 pass
40 42
41 time.sleep(float(options.sleep)) 43 time.sleep(float(options.sleep))
42 44
43 if options.expect_to_be_killed: 45 if options.expect_to_be_killed:
44 PrintAndFlush('Done sleeping. Expected to be killed.') 46 PrintAndFlush('Done sleeping. Expected to be killed.')
45 return 0 47 return 0
46 48
47 if __name__ == '__main__': 49 if __name__ == '__main__':
48 sys.exit(main(sys.argv[1:])) 50 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/sel_ldr.py ('k') | native_client_sdk/src/tools/tests/create_html_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698