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

Side by Side Diff: media/tools/constrained_network_server/cns.py

Issue 10825051: Update CNS to run on chromeperf34 and CNS tests to run on windows perf_av bot. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Constrained Network Server. Serves files with supplied network constraints. 6 """Constrained Network Server. Serves files with supplied network constraints.
7 7
8 The CNS exposes a web based API allowing network constraints to be imposed on 8 The CNS exposes a web based API allowing network constraints to be imposed on
9 file serving. 9 file serving.
10 10
11 TODO(dalecurtis): Add some more docs here. 11 TODO(dalecurtis): Add some more docs here.
12 12
13 """ 13 """
14 14
15 import logging 15 import logging
16 from logging import handlers
DaleCurtis 2012/07/27 00:49:43 What does gpylint say about the ordering here?
shadi 2012/07/27 01:06:25 I did check gpylint, this is actually its recommen
16 import mimetypes 17 import mimetypes
17 import optparse 18 import optparse
18 import os 19 import os
19 import signal 20 import signal
20 import sys 21 import sys
21 import threading 22 import threading
22 import time 23 import time
23 import traffic_control 24 import traffic_control
24 25
25 try: 26 try:
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 options.port_range = [int(port) for port in options.port_range.split(',')] 315 options.port_range = [int(port) for port in options.port_range.split(',')]
315 except ValueError: 316 except ValueError:
316 parser.error('Invalid port range specified.') 317 parser.error('Invalid port range specified.')
317 318
318 if options.expiry_time < 0: 319 if options.expiry_time < 0:
319 parser.error('Invalid expiry time specified.') 320 parser.error('Invalid expiry time specified.')
320 321
321 # Convert the path to an absolute to remove any . or .. 322 # Convert the path to an absolute to remove any . or ..
322 options.www_root = os.path.abspath(options.www_root) 323 options.www_root = os.path.abspath(options.www_root)
323 324
324 # Required so that cherrypy logs do not get propagated to root logger causing
325 # the logs to be printed twice.
326 cherrypy.log.error_log.propagate = False
327 cherrypy.log.access_log.propagate = False
328
329 _SetLogger(options.verbose) 325 _SetLogger(options.verbose)
330 326
331 return options 327 return options
332 328
333 329
334 def _SetLogger(verbose): 330 def _SetLogger(verbose):
335 # Logging is used for traffic_control debug statements. 331 file_handler = handlers.RotatingFileHandler('cns.log', 'a', 10000000, 1000)
DaleCurtis 2012/07/27 00:49:43 How will we see the logs on Linux now?
shadi 2012/07/27 01:06:25 It should show as it currently does since locally
332 file_handler.setFormatter(logging.Formatter('[%(threadName)s] %(message)s'))
333
336 log_level = _DEFAULT_LOG_LEVEL 334 log_level = _DEFAULT_LOG_LEVEL
337 if verbose: 335 if verbose:
338 log_level = logging.DEBUG 336 log_level = logging.DEBUG
339 logging.basicConfig(level=log_level, format='[%(threadName)s] %(message)s') 337 file_handler.setLevel(log_level)
338
339 cherrypy.log.error_log.addHandler(file_handler)
340 cherrypy.log.access_log.addHandler(file_handler)
340 341
341 342
342 def Main(): 343 def Main():
343 """Configure and start the ConstrainedNetworkServer.""" 344 """Configure and start the ConstrainedNetworkServer."""
344 options = ParseArgs() 345 options = ParseArgs()
345 346
346 try: 347 try:
347 traffic_control.CheckRequirements() 348 traffic_control.CheckRequirements()
348 except traffic_control.TrafficControlError as e: 349 except traffic_control.TrafficControlError as e:
349 cherrypy.log(e.msg) 350 cherrypy.log(e.msg)
(...skipping 14 matching lines...) Expand all
364 try: 365 try:
365 cherrypy.quickstart(ConstrainedNetworkServer(options, pa)) 366 cherrypy.quickstart(ConstrainedNetworkServer(options, pa))
366 finally: 367 finally:
367 # Disable Ctrl-C handler to prevent interruption of cleanup. 368 # Disable Ctrl-C handler to prevent interruption of cleanup.
368 signal.signal(signal.SIGINT, lambda signal, frame: None) 369 signal.signal(signal.SIGINT, lambda signal, frame: None)
369 pa.Cleanup(all_ports=True) 370 pa.Cleanup(all_ports=True)
370 371
371 372
372 if __name__ == '__main__': 373 if __name__ == '__main__':
373 Main() 374 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698