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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/tools/tests/chrome_mock.py
diff --git a/native_client_sdk/src/tools/tests/chrome_mock.py b/native_client_sdk/src/tools/tests/chrome_mock.py
index 227a6062204fac4885d5d4ecb6a8e19d5087c557..966e2310ad70444284b603d25baf3e565f153421 100755
--- a/native_client_sdk/src/tools/tests/chrome_mock.py
+++ b/native_client_sdk/src/tools/tests/chrome_mock.py
@@ -3,37 +3,39 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import optparse
+"""Mock chrome process used by test code for http server."""
+
+import argparse
import sys
import time
import urllib2
def PrintAndFlush(s):
- print s
+ sys.stdout.write(s + '\n')
sys.stdout.flush()
def main(args):
- parser = optparse.OptionParser(usage='%prog [options] <URL to load>')
- parser.add_option('--post', help='POST to URL.', dest='post',
- action='store_true')
- parser.add_option('--get', help='GET to URL.', dest='get',
- action='store_true')
- parser.add_option('--sleep',
- help='Number of seconds to sleep after reading URL',
- dest='sleep', default=0)
- parser.add_option('--expect-to-be-killed', help='If set, the script will warn'
- ' if it isn\'t killed before it finishes sleeping.',
- dest='expect_to_be_killed', action='store_true')
- options, args = parser.parse_args(args)
- if len(args) != 1:
- parser.error('Expected URL to load.')
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--post', help='POST to URL.', dest='post',
+ action='store_true')
+ parser.add_argument('--get', help='GET to URL.', dest='get',
+ action='store_true')
+ parser.add_argument('--sleep',
+ help='Number of seconds to sleep after reading URL',
+ dest='sleep', default=0)
+ parser.add_argument('--expect-to-be-killed', help='If set, the script will'
+ ' warn if it isn\'t killed before it finishes sleeping.',
+ dest='expect_to_be_killed', action='store_true')
+ parser.add_argument('url')
+
+ options = parser.parse_args(args)
PrintAndFlush('Starting %s.' % sys.argv[0])
if options.post:
- urllib2.urlopen(args[0], data='').read()
+ urllib2.urlopen(options.url, data='').read()
elif options.get:
- urllib2.urlopen(args[0]).read()
+ urllib2.urlopen(options.url).read()
else:
# Do nothing but wait to be killed.
pass
« 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