Initialize Tizen 2.3
[framework/web/webkit-efl.git] / Tools / Scripts / new-run-webkit-websocketserver
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
30 """A utility script for starting and stopping the web socket server with the
31    same configuration as used in the layout tests."""
32
33 import logging
34 import optparse
35 import tempfile
36
37 from webkitpy.common.host import Host
38 from webkitpy.layout_tests.servers import websocket_server
39 from webkitpy.port import platform_options
40
41
42 def main():
43     option_parser = optparse.OptionParser()
44     option_parser.add_option('--server', type='choice',
45                              choices=['start', 'stop'], default='start',
46                              help='Server action (start|stop).')
47     option_parser.add_option('-p', '--port', dest='port',
48                              default=None, help='Port to listen on.')
49     option_parser.add_option('-r', '--root',
50                              help='Absolute path to DocumentRoot '
51                                   '(overrides layout test roots).')
52     option_parser.add_option('-t', '--tls', dest='use_tls',
53                              action='store_true',
54                              default=False, help='use TLS (wss://).')
55     option_parser.add_option('-k', '--private_key', dest='private_key',
56                              default='', help='TLS private key file.')
57     option_parser.add_option('-c', '--certificate', dest='certificate',
58                              default='', help='TLS certificate file.')
59     option_parser.add_option('--ca-certificate', dest='ca_certificate',
60                              default='', help='TLS CA certificate file for '
61                                               'client authentication.')
62     option_parser.add_option('--chromium', action='store_true',
63                              dest='chromium',
64                              default=False,
65                              help='Use the Chromium port.')
66     option_parser.add_option('--register_cygwin', action="store_true",
67                              dest="register_cygwin",
68                              help='Register Cygwin paths (on Win try bots).')
69     option_parser.add_option('--pidfile', help='path to pid file.')
70     option_parser.add_option('--output-dir', dest='output_dir',
71                              default=None, help='output directory.')
72     option_parser.add_option('-v', '--verbose', action='store_true',
73                              default=False,
74                              help='Include debug-level logging.')
75
76     option_group = optparse.OptionGroup(option_parser, "Platform options")
77     option_group.add_options(platform_options())
78     option_parser.add_option_group(option_group)
79
80     options, args = option_parser.parse_args()
81
82     if not options.port:
83         if options.use_tls:
84             # FIXME: We shouldn't grab at this private variable.
85             options.port = websocket_server._DEFAULT_WSS_PORT
86         else:
87             # FIXME: We shouldn't grab at this private variable.
88             options.port = websocket_server._DEFAULT_WS_PORT
89
90     if not options.output_dir:
91         options.output_dir = tempfile.gettempdir()
92
93     kwds = {'port': options.port, 'use_tls': options.use_tls}
94     if options.root:
95         kwds['root'] = options.root
96     if options.private_key:
97         kwds['private_key'] = options.private_key
98     if options.certificate:
99         kwds['certificate'] = options.certificate
100     if options.ca_certificate:
101         kwds['ca_certificate'] = options.ca_certificate
102     if options.pidfile:
103         kwds['pidfile'] = options.pidfile
104
105     host = Host()
106     port_obj = host.port_factory.get(options.platform, options=options)
107     pywebsocket = websocket_server.PyWebSocket(port_obj, options.output_dir, **kwds)
108
109     log_level = logging.WARN
110     if options.verbose:
111         log_level = logging.DEBUG
112     logging.basicConfig(level=log_level)
113
114     if 'start' == options.server:
115         pywebsocket.start()
116     else:
117         pywebsocket.stop()
118
119 if '__main__' == __name__:
120     main()