Chromium Code Reviews| 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..db66c5ad253b3a8838cbf69e0fac2eccbbb25a77 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,12 +306,32 @@ 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='%(message)s') |
|
DaleCurtis
2012/01/06 23:19:42
Need a more descriptive message here. One that is
shadi
2012/01/07 04:56:19
cherrypy.log only shows date. I added thread numbe
DaleCurtis
2012/01/09 19:21:19
Ah, I'm thinking of cherrypy.request.log() I think
|
| + |
| + |
| +def _CheckRootAccess(): |
|
DaleCurtis
2012/01/06 23:19:42
This is not complete and should instead be in the
shadi
2012/01/07 04:56:19
Check http://codereview.chromium.org/9125022/
On 2
|
| + if os.geteuid() != 0: |
| + sys.exit('Need root access to run a constrained server.') |
| + |
| + |
| def Main(): |
| """Configure and start the ConstrainedNetworkServer.""" |
| options = ParseArgs() |
| + _CheckRootAccess() |
| cherrypy.config.update( |
| {'server.socket_host': '::', 'server.socket_port': options.port}) |