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

Unified Diff: sky/tools/skypy/skyserver.py

Issue 817573003: Move wm_flow off of views and onto Sky (Closed) Base URL: git@github.com:domokit/mojo.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 | « sky/tools/skygo/sky_server.sha1 ('k') | sky/viewer/internals.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tools/skypy/skyserver.py
diff --git a/sky/tools/skypy/skyserver.py b/sky/tools/skypy/skyserver.py
new file mode 100644
index 0000000000000000000000000000000000000000..bddea9e0ab9c03f09cc077fcd4cc4972d5f4cedd
--- /dev/null
+++ b/sky/tools/skypy/skyserver.py
@@ -0,0 +1,55 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import socket
+import subprocess
+import logging
+import os.path
+
+class SkyServer(object):
+ def __init__(self, paths, port, configuration, root):
+ self.paths = paths
+ self.port = port
+ self.configuration = configuration
+ self.root = root
+ self.server = None
+
+ @staticmethod
+ def _port_in_use(port):
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ return sock.connect_ex(('localhost', port)) == 0
+
+ @staticmethod
+ def _download_server_if_necessary(paths):
+ subprocess.call(os.path.join(paths.sky_tools_directory,
+ 'download_sky_server'))
+ return os.path.join(paths.src_root, 'out', 'downloads', 'sky_server')
+
+ def __enter__(self):
+ if self._port_in_use(self.port):
+ logging.warn(
+ 'Port %s already in use, assuming custom sky_server started.' %
+ self.port)
+ return
+
+ server_path = self._download_server_if_necessary(self.paths)
+ server_command = [
+ server_path,
+ '-t', self.configuration,
+ self.root,
+ str(self.port),
+ ]
+ self.server = subprocess.Popen(server_command)
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ if self.server:
+ self.server.terminate()
+
+ def path_as_url(self, path):
+ return self.url_for_path(self.port, self.root, path)
+
+ @staticmethod
+ def url_for_path(port, root, path):
+ relative_path = os.path.relpath(path, root)
+ return 'http://localhost:%s/%s' % (port, relative_path)
« no previous file with comments | « sky/tools/skygo/sky_server.sha1 ('k') | sky/viewer/internals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698