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

Unified Diff: mojo/devtools/common/devtoolslib/android_shell.py

Issue 1139053005: Add ServeLocalDirectory to the shell abstraction. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address Ben's comments. Created 5 years, 7 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 | « no previous file | mojo/devtools/common/devtoolslib/http_server.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/devtools/common/devtoolslib/android_shell.py
diff --git a/mojo/devtools/common/devtoolslib/android_shell.py b/mojo/devtools/common/devtoolslib/android_shell.py
index 4bae3de4449c5de79b7ba20bcd41a67d3d93a756..08a7cd0d182e5374210f7c9a77e83fee24826577 100644
--- a/mojo/devtools/common/devtoolslib/android_shell.py
+++ b/mojo/devtools/common/devtoolslib/android_shell.py
@@ -142,17 +142,6 @@ class AndroidShell(Shell):
atexit.register(_UnmapPort)
return device_port
- def _StartHttpServerForDirectory(self, path, port=0):
- """Starts an http server serving files from |path|. Returns the local
- url.
- """
- assert path
- print 'starting http for', path
- server_address = StartHttpServer(path)
-
- print 'local port=%d' % server_address[1]
- return 'http://127.0.0.1:%d/' % self._MapPort(port, server_address[1])
-
def _StartHttpServerForOriginMapping(self, mapping, port):
"""If |mapping| points at a local file starts an http server to serve files
from the directory and returns the new mapping.
@@ -168,7 +157,7 @@ class AndroidShell(Shell):
return mapping
# Assume the destination is a local file. Start a local server that
# redirects to it.
- localUrl = self._StartHttpServerForDirectory(dest, port)
+ localUrl = self.ServeLocalDirectory(dest, port)
print 'started server at %s for %s' % (dest, localUrl)
return parts[0] + '=' + localUrl
@@ -219,10 +208,32 @@ class AndroidShell(Shell):
shell.
"""
- origin_url = self._StartHttpServerForDirectory(
+ origin_url = self.ServeLocalDirectory(
local_dir, DEFAULT_BASE_PORT if fixed_port else 0)
return "--origin=" + origin_url
+ def ServeLocalDirectory(self, local_dir_path, port=0):
+ """Serves the content of the local (host) directory, making it available to
+ the shell under the url returned by the function.
+
+ The server will run on a separate thread until the program terminates. The
+ call returns immediately.
+
+ Args:
+ local_dir_path: path to the directory to be served
+ port: port at which the server will be available to the shell
+
+ Returns:
+ The url that the shell can use to access the content of |local_dir_path|.
+ """
+ assert local_dir_path
+ print 'starting http for', local_dir_path
+ server_address = StartHttpServer(local_dir_path)
+
+ print 'local port=%d' % server_address[1]
+ return 'http://127.0.0.1:%d/' % self._MapPort(port,
+ server_address[1])
+
def StartShell(self,
arguments,
stdout=None,
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/http_server.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698