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

Unified Diff: native_client_sdk/src/tools/run.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/oshelpers.py ('k') | native_client_sdk/src/tools/sel_ldr.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/tools/run.py
diff --git a/native_client_sdk/src/tools/run.py b/native_client_sdk/src/tools/run.py
index 441cc1f5669aca96ef9d7a32df827e94ad648c7a..b0131c5e428912556b60d9ed003ce979c41d313b 100755
--- a/native_client_sdk/src/tools/run.py
+++ b/native_client_sdk/src/tools/run.py
@@ -3,13 +3,17 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Launch a local server on an ephemeral port, then launch a executable that
-points to that server.
+"""Launch a local http server, then launch a executable directed at the server.
+
+This command creates a local server (on port 5103 by default) then runs:
+ <executable> <args..> http://localhost:<port>/<page>.
+
+Where <page> can be set by -P, or uses index.html by default.
"""
+import argparse
import copy
import getos
-import optparse
import os
import subprocess
import sys
@@ -22,30 +26,24 @@ if sys.version_info < (2, 7, 0):
def main(args):
- usage = """usage: %prog [options] -- executable args...
-
- This command creates a local server on an ephemeral port, then runs:
- <executable> <args..> http://localhost:<port>/<page>.
-
- Where <page> can be set by -P, or uses index.html by default."""
- parser = optparse.OptionParser(usage)
- parser.add_option('-C', '--serve-dir',
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('-C', '--serve-dir',
help='Serve files out of this directory.',
dest='serve_dir', default=os.path.abspath('.'))
- parser.add_option('-P', '--path', help='Path to load from local server.',
+ parser.add_argument('-P', '--path', help='Path to load from local server.',
dest='path', default='index.html')
- parser.add_option('-D',
+ parser.add_argument('-D',
help='Add debug command-line when launching the chrome debug.',
dest='debug', action='append', default=[])
- parser.add_option('-E',
+ parser.add_argument('-E',
help='Add environment variables when launching the executable.',
dest='environ', action='append', default=[])
- parser.add_option('-p', '--port',
+ parser.add_argument('-p', '--port',
help='Port to run server on. Default is 5103, ephemeral is 0.',
- type='int', default=5103)
- options, args = parser.parse_args(args)
- if not args:
- parser.error('No executable given.')
+ type=int, default=5103)
+ parser.add_argument('executable', help='command to run')
+ parser.add_argument('args', nargs='*', help='arguments for executable')
+ options = parser.parse_args(args)
# 0 means use an ephemeral port.
server = httpd.LocalHTTPServer(options.serve_dir, options.port)
@@ -56,7 +54,7 @@ def main(args):
key, value = map(str.strip, e.split('='))
env[key] = value
- cmd = args + [server.GetURL(options.path)]
+ cmd = [options.executable] + options.args + [server.GetURL(options.path)]
print 'Running: %s...' % (' '.join(cmd),)
process = subprocess.Popen(cmd, env=env)
« no previous file with comments | « native_client_sdk/src/tools/oshelpers.py ('k') | native_client_sdk/src/tools/sel_ldr.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698