new-run-webkit-websocketserver 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python
  2. # Copyright (C) 2012 Google Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above
  11. # copyright notice, this list of conditions and the following disclaimer
  12. # in the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Google Inc. nor the names of its
  15. # contributors may be used to endorse or promote products derived from
  16. # this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. """A utility script for starting and stopping the web socket server with the
  30. same configuration as used in the layout tests."""
  31. import logging
  32. import optparse
  33. import tempfile
  34. from webkitpy.common.host import Host
  35. from webkitpy.layout_tests.servers import websocket_server
  36. from webkitpy.port import platform_options
  37. def main():
  38. option_parser = optparse.OptionParser()
  39. option_parser.add_option('--server', type='choice',
  40. choices=['start', 'stop'], default='start',
  41. help='Server action (start|stop).')
  42. option_parser.add_option('-p', '--port', dest='port',
  43. default=None, help='Port to listen on.')
  44. option_parser.add_option('-r', '--root',
  45. help='Absolute path to DocumentRoot '
  46. '(overrides layout test roots).')
  47. option_parser.add_option('-t', '--tls', dest='use_tls',
  48. action='store_true',
  49. default=False, help='use TLS (wss://).')
  50. option_parser.add_option('-k', '--private_key', dest='private_key',
  51. default='', help='TLS private key file.')
  52. option_parser.add_option('-c', '--certificate', dest='certificate',
  53. default='', help='TLS certificate file.')
  54. option_parser.add_option('--ca-certificate', dest='ca_certificate',
  55. default='', help='TLS CA certificate file for '
  56. 'client authentication.')
  57. option_parser.add_option('--chromium', action='store_true',
  58. dest='chromium',
  59. default=False,
  60. help='Use the Chromium port.')
  61. option_parser.add_option('--register_cygwin', action="store_true",
  62. dest="register_cygwin",
  63. help='Register Cygwin paths (on Win try bots).')
  64. option_parser.add_option('--pidfile', help='path to pid file.')
  65. option_parser.add_option('--output-dir', dest='output_dir',
  66. default=None, help='output directory.')
  67. option_parser.add_option('-v', '--verbose', action='store_true',
  68. default=False,
  69. help='Include debug-level logging.')
  70. option_group = optparse.OptionGroup(option_parser, "Platform options")
  71. option_group.add_options(platform_options())
  72. option_parser.add_option_group(option_group)
  73. options, args = option_parser.parse_args()
  74. if not options.port:
  75. if options.use_tls:
  76. # FIXME: We shouldn't grab at this private variable.
  77. options.port = websocket_server._DEFAULT_WSS_PORT
  78. else:
  79. # FIXME: We shouldn't grab at this private variable.
  80. options.port = websocket_server._DEFAULT_WS_PORT
  81. if not options.output_dir:
  82. options.output_dir = tempfile.gettempdir()
  83. kwds = {'port': options.port, 'use_tls': options.use_tls}
  84. if options.root:
  85. kwds['root'] = options.root
  86. if options.private_key:
  87. kwds['private_key'] = options.private_key
  88. if options.certificate:
  89. kwds['certificate'] = options.certificate
  90. if options.ca_certificate:
  91. kwds['ca_certificate'] = options.ca_certificate
  92. if options.pidfile:
  93. kwds['pidfile'] = options.pidfile
  94. host = Host()
  95. port_obj = host.port_factory.get(options.platform, options=options)
  96. pywebsocket = websocket_server.PyWebSocket(port_obj, options.output_dir, **kwds)
  97. log_level = logging.WARN
  98. if options.verbose:
  99. log_level = logging.DEBUG
  100. logging.basicConfig(level=log_level)
  101. if 'start' == options.server:
  102. pywebsocket.start()
  103. else:
  104. pywebsocket.stop()
  105. if '__main__' == __name__:
  106. main()