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

Unified Diff: media/tools/constrained_network_server/cns.py

Issue 9127009: Constrained Network test does not fail fast under fatal conditions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: and again... Created 8 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
Index: media/tools/constrained_network_server/cns.py
diff --git a/media/tools/constrained_network_server/cns.py b/media/tools/constrained_network_server/cns.py
index 4f0198d922d47c8a243465b31053abcea44fed71..5b9ff516bece5545a96e9fdd2380ea6140461668 100755
--- a/media/tools/constrained_network_server/cns.py
+++ b/media/tools/constrained_network_server/cns.py
@@ -12,6 +12,7 @@ TODO(dalecurtis): Add some more docs here.
"""
+import logging
import mimetypes
import optparse
import os
@@ -31,6 +32,9 @@ except ImportError:
# Add webm file types to mimetypes map since cherrypy's default type is text.
mimetypes.types_map['.webm'] = 'video/webm'
+# Default logging is ERROR. Use --verbose to enable DEBUG logging.
+_DEFAULT_LOG_LEVEL = logging.ERROR
+
# Default port to serve the CNS on.
_DEFAULT_SERVING_PORT = 9000
@@ -287,6 +291,8 @@ def ParseArgs():
parser.add_option('--www-root', default=os.getcwd(),
help=('Directory root to serve files from. Defaults to the '
'current directory: %default'))
+ parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
+ default=False, help='Turn on verbose output.')
options = parser.parse_args()[0]
@@ -300,9 +306,23 @@ def ParseArgs():
# Convert the path to an absolute to remove any . or ..
options.www_root = os.path.abspath(options.www_root)
+ # Required so that cherrypy logs do not get propagated to root logger causing
+ # the logs to be printed twice.
+ cherrypy.log.error_log.propagate = False
+
+ _SetLogger(options.verbose)
+
return options
+def _SetLogger(verbose):
+ # Logging is used for traffic_control debug statements.
+ log_level = _DEFAULT_LOG_LEVEL
+ if verbose:
+ log_level = logging.DEBUG
+ logging.basicConfig(level=log_level, format='[%(threadName)s] %(message)s')
+
+
def Main():
"""Configure and start the ConstrainedNetworkServer."""
options = ParseArgs()

Powered by Google App Engine
This is Rietveld 408576698