media/tools/constrained_network_server/cns.py
def ParseArgs():
  """Define and parse the command-line arguments."""
  parser = optparse.OptionParser()

  parser.add_option('--expiry-time', type='int',
                    default=_DEFAULT_PORT_EXPIRY_TIME_SECS,
                    help=('Number of seconds before constrained ports expire '
                          'and are cleaned up. 0=Disabled. Default: %default'))
  parser.add_option('--port', type='int', default=_DEFAULT_SERVING_PORT,
                    help='Port to serve the API on. Default: %default')
  parser.add_option('--port-range', default=_DEFAULT_CNS_PORT_RANGE,
                    help=('Range of ports for constrained serving. Specify as '
                          'a comma separated value pair. Default: %default'))
  parser.add_option('--interface', default='eth0',
                    help=('Interface to setup constraints on. Use lo for a '
                          'local client. Default: %default'))
  parser.add_option('--socket-timeout', type='int',
                    default=cherrypy.server.socket_timeout,
                    help=('Number of seconds before a socket connection times '
                          'out. Default: %default'))
  parser.add_option('--threads', type='int',
                    default=cherrypy._cpserver.Server.thread_pool,
                    help=('Number of threads in the thread pool. Default: '
                          '%default'))
  parser.add_option('--www-root', default='',
                    help=('Directory root to serve files from. If --local-'
                          'server-port is used, the path is appended to the '
                          'redirected URL of local server. Defaults to the '
                          'current directory (if --local-server-port is not '
                          'used): %s' % os.getcwd()))
  parser.add_option('--local-server-port', type='int',
                    help=('Optional local server port to host files.'))
  parser.add_option('-v', '--verbose', action='store_true', default=False,
                    help='Turn on verbose output.')

  options = parser.parse_args()[0]

  # Convert port range into the desired tuple format.
  try:
    if isinstance(options.port_range, str):
      options.port_range = [int(port) for port in options.port_range.split(',')]
  except ValueError:
    parser.error('Invalid port range specified.')

  if options.expiry_time < 0:
    parser.error('Invalid expiry time specified.')

  # Convert the path to an absolute to remove any . or ..
  if not options.local_server_port:
    if not options.www_root:
      options.www_root = os.getcwd()
    options.www_root = os.path.abspath(options.www_root)

  _SetLogger(options.verbose)

  return options
Define and parse the command-line arguments.
Define and parse the command-line arguments.
Define and parse the command - line arguments .
def ParseArgs():
  parser = optparse.OptionParser()
  parser.add_option('--expiry-time', type='int',
                    default=_DEFAULT_PORT_EXPIRY_TIME_SECS,
                    help=('Number of seconds before constrained ports expire '
                          'and are cleaned up. 0=Disabled. Default: %default'))
  parser.add_option('--port', type='int', default=_DEFAULT_SERVING_PORT,
                    help='Port to serve the API on. Default: %default')
  parser.add_option('--port-range', default=_DEFAULT_CNS_PORT_RANGE,
                    help=('Range of ports for constrained serving. Specify as '
                          'a comma separated value pair. Default: %default'))
  parser.add_option('--interface', default='eth0',
                    help=('Interface to setup constraints on. Use lo for a '
                          'local client. Default: %default'))
  parser.add_option('--socket-timeout', type='int',
                    default=cherrypy.server.socket_timeout,
                    help=('Number of seconds before a socket connection times '
                          'out. Default: %default'))
  parser.add_option('--threads', type='int',
                    default=cherrypy._cpserver.Server.thread_pool,
                    help=('Number of threads in the thread pool. Default: '
                          '%default'))
  parser.add_option('--www-root', default='',
                    help=('Directory root to serve files from. If --local-'
                          'server-port is used, the path is appended to the '
                          'redirected URL of local server. Defaults to the '
                          'current directory (if --local-server-port is not '
                          'used): %s' % os.getcwd()))
  parser.add_option('--local-server-port', type='int',
                    help=('Optional local server port to host files.'))
  parser.add_option('-v', '--verbose', action='store_true', default=False,
                    help='Turn on verbose output.')
  options = parser.parse_args()[0]
  try:
    if isinstance(options.port_range, str):
      options.port_range = [int(port) for port in options.port_range.split(',')]
  except ValueError:
    parser.error('Invalid port range specified.')
  if options.expiry_time < 0:
    parser.error('Invalid expiry time specified.')
  if not options.local_server_port:
    if not options.www_root:
      options.www_root = os.getcwd()
    options.www_root = os.path.abspath(options.www_root)
  _SetLogger(options.verbose)
  return options
def ParseArgs ( ) : parser = optparse . OptionParser ( ) parser . add_option ( '--expiry-time' , type = 'int' , default = _DEFAULT_PORT_EXPIRY_TIME_SECS , help = ( 'Number of seconds before constrained ports expire ' 'and are cleaned up. 0=Disabled. Default: %default' ) ) parser . add_option ( '--port' , type = 'int' , default = _DEFAULT_SERVING_PORT , help = 'Port to serve the API on. Default: %default' ) parser . add_option ( '--port-range' , default = _DEFAULT_CNS_PORT_RANGE , help = ( 'Range of ports for constrained serving. Specify as ' 'a comma separated value pair. Default: %default' ) ) parser . add_option ( '--interface' , default = 'eth0' , help = ( 'Interface to setup constraints on. Use lo for a ' 'local client. Default: %default' ) ) parser . add_option ( '--socket-timeout' , type = 'int' , default = cherrypy . server . socket_timeout , help = ( 'Number of seconds before a socket connection times ' 'out. Default: %default' ) ) parser . add_option ( '--threads' , type = 'int' , default = cherrypy . _cpserver . Server . thread_pool , help = ( 'Number of threads in the thread pool. Default: ' '%default' ) ) parser . add_option ( '--www-root' , default = '' , help = ( 'Directory root to serve files from. If --local-' 'server-port is used, the path is appended to the ' 'redirected URL of local server. Defaults to the ' 'current directory (if --local-server-port is not ' 'used): %s' % os . getcwd ( ) ) ) parser . add_option ( '--local-server-port' , type = 'int' , help = ( 'Optional local server port to host files.' ) ) parser . add_option ( '-v' , '--verbose' , action = 'store_true' , default = False , help = 'Turn on verbose output.' ) options = parser . parse_args ( ) [ 0 ] try : if isinstance ( options . port_range , str ) : options . port_range = [ int ( port ) for port in options . port_range . split ( ',' ) ] except ValueError : parser . error ( 'Invalid port range specified.' ) if options . expiry_time < 0 : parser . error ( 'Invalid expiry time specified.' ) if not options . local_server_port : if not options . www_root : options . www_root = os . getcwd ( ) options . www_root = os . path . abspath ( options . www_root ) _SetLogger ( options . verbose ) return options
Define and parse the command-line arguments.
Define and parse the command - line arguments .
"""Define and parse the command-line arguments.""" # Convert port range into the desired tuple format. # Convert the path to an absolute to remove any . or ..