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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/layout_tests/servers/server_base.py

Issue 2014063002: Run format-webkit on webkitpy code (without string conversion). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 # Copyright (C) 2011 Google Inc. All rights reserved. 1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 25 matching lines...) Expand all
36 36
37 37
38 _log = logging.getLogger(__name__) 38 _log = logging.getLogger(__name__)
39 39
40 40
41 class ServerError(Exception): 41 class ServerError(Exception):
42 pass 42 pass
43 43
44 44
45 class ServerBase(object): 45 class ServerBase(object):
46
46 """A skeleton class for starting and stopping servers used by the layout tes ts.""" 47 """A skeleton class for starting and stopping servers used by the layout tes ts."""
47 48
48 def __init__(self, port_obj, output_dir): 49 def __init__(self, port_obj, output_dir):
49 self._port_obj = port_obj 50 self._port_obj = port_obj
50 self._executive = port_obj._executive 51 self._executive = port_obj._executive
51 self._filesystem = port_obj._filesystem 52 self._filesystem = port_obj._filesystem
52 self._platform = port_obj.host.platform 53 self._platform = port_obj.host.platform
53 self._output_dir = output_dir 54 self._output_dir = output_dir
54 55
55 # We need a non-checkout-dependent place to put lock files, etc. We 56 # We need a non-checkout-dependent place to put lock files, etc. We
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 152
152 def _remove_stale_logs(self): 153 def _remove_stale_logs(self):
153 """This routine can be overridden by subclasses to try and remove logs 154 """This routine can be overridden by subclasses to try and remove logs
154 left over from a prior run. This routine should log warnings if the 155 left over from a prior run. This routine should log warnings if the
155 files cannot be deleted, but should not fail unless failure to 156 files cannot be deleted, but should not fail unless failure to
156 delete the logs will actually cause start() to fail.""" 157 delete the logs will actually cause start() to fail."""
157 # Sometimes logs are open in other processes but they should clear event ually. 158 # Sometimes logs are open in other processes but they should clear event ually.
158 for log_prefix in self._log_prefixes: 159 for log_prefix in self._log_prefixes:
159 try: 160 try:
160 self._remove_log_files(self._output_dir, log_prefix) 161 self._remove_log_files(self._output_dir, log_prefix)
161 except OSError, e: 162 except OSError as e:
162 _log.warning('Failed to remove old %s %s files' % (self._name, l og_prefix)) 163 _log.warning('Failed to remove old %s %s files' % (self._name, l og_prefix))
163 164
164 def _spawn_process(self): 165 def _spawn_process(self):
165 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd )) 166 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd ))
166 self._process = self._executive.popen(self._start_cmd, 167 self._process = self._executive.popen(self._start_cmd,
167 env=self._env, 168 env=self._env,
168 cwd=self._cwd, 169 cwd=self._cwd,
169 stdout=self._stdout, 170 stdout=self._stdout,
170 stderr=self._stderr) 171 stderr=self._stderr)
171 pid = self._process.pid 172 pid = self._process.pid
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 _log.debug("Server isn't running at all") 248 _log.debug("Server isn't running at all")
248 self._log_errors_from_subprocess() 249 self._log_errors_from_subprocess()
249 raise ServerError("Server exited") 250 raise ServerError("Server exited")
250 251
251 for mapping in self._mappings: 252 for mapping in self._mappings:
252 s = socket.socket() 253 s = socket.socket()
253 port = mapping['port'] 254 port = mapping['port']
254 try: 255 try:
255 s.connect(('localhost', port)) 256 s.connect(('localhost', port))
256 _log.debug("Server running on %d" % port) 257 _log.debug("Server running on %d" % port)
257 except IOError, e: 258 except IOError as e:
258 if e.errno not in (errno.ECONNREFUSED, errno.ECONNRESET): 259 if e.errno not in (errno.ECONNREFUSED, errno.ECONNRESET):
259 raise 260 raise
260 _log.debug("Server NOT running on %d: %s" % (port, e)) 261 _log.debug("Server NOT running on %d: %s" % (port, e))
261 return False 262 return False
262 finally: 263 finally:
263 s.close() 264 s.close()
264 return True 265 return True
265 266
266 def _check_that_all_ports_are_available(self): 267 def _check_that_all_ports_are_available(self):
267 for mapping in self._mappings: 268 for mapping in self._mappings:
268 s = socket.socket() 269 s = socket.socket()
269 if not self._platform.is_win(): 270 if not self._platform.is_win():
270 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 271 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
271 port = mapping['port'] 272 port = mapping['port']
272 try: 273 try:
273 s.bind(('localhost', port)) 274 s.bind(('localhost', port))
274 except IOError, e: 275 except IOError as e:
275 if e.errno in (errno.EALREADY, errno.EADDRINUSE): 276 if e.errno in (errno.EALREADY, errno.EADDRINUSE):
276 raise ServerError('Port %d is already in use.' % port) 277 raise ServerError('Port %d is already in use.' % port)
277 elif self._platform.is_win() and e.errno in (errno.WSAEACCES,): # pylint: disable=E1101 278 elif self._platform.is_win() and e.errno in (errno.WSAEACCES,): # pylint: disable=E1101
278 raise ServerError('Port %d is already in use.' % port) 279 raise ServerError('Port %d is already in use.' % port)
279 else: 280 else:
280 raise 281 raise
281 finally: 282 finally:
282 s.close() 283 s.close()
283 _log.debug('all ports are available') 284 _log.debug('all ports are available')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698