#!/usr/bin/env python
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""A utility script for starting and stopping the HTTP server with the
   same configuration as used in the layout tests."""

#
# FIXME: currently this code only works with the Chromium ports and LigHTTPd.
# It should be made to work on all ports.
#
# This script is also used by Chromium's ui_tests to run http layout tests
# in a browser.
#
import optparse
import os
import sys
import tempfile

scripts_directory = os.path.dirname(os.path.abspath(sys.argv[0]))
webkitpy_directory = os.path.join(scripts_directory, "webkitpy")
sys.path.append(os.path.join(webkitpy_directory, "layout_tests"))

import port
from port import http_server

def run(options):
    if not options.server:
        print ('Usage: %s --server {start|stop} [--root=root_dir]'
               ' [--port=port_number]' % sys.argv[0])
    else:
        if (options.root is None) and (options.port is not None):
            # specifying root but not port means we want httpd on default
            # set of ports that LayoutTest use, but pointing to a different
            # source of tests. Specifying port but no root does not seem
            # meaningful.
            raise 'Specifying port requires also a root.'
        port_obj = port.get(None, options)
        httpd = http_server.Lighttpd(port_obj,
                                     tempfile.gettempdir(),
                                     port=options.port,
                                     root=options.root,
                                     run_background=options.run_background,
                                     layout_tests_dir=options.layout_tests_dir)
        if options.server == 'start':
            httpd.start()
        else:
            httpd.stop(force=True)


def main():
    option_parser = optparse.OptionParser()
    option_parser.add_option('-k', '--server',
        help='Server action (start|stop)')
    option_parser.add_option('-p', '--port',
        help='Port to listen on (overrides layout test ports)')
    option_parser.add_option('-r', '--root',
        help='Absolute path to DocumentRoot (overrides layout test roots)')
    option_parser.add_option('--register_cygwin', action="store_true",
        dest="register_cygwin", help='Register Cygwin paths (on Win try bots)')
    option_parser.add_option('--run_background', action="store_true",
        dest="run_background",
        help='Run on background (for running as UI test)')
    option_parser.add_option('--layout_tests_dir',
        dest="layout_tests_dir",
        help='Absolute path to LayoutTests root')
    options, args = option_parser.parse_args()

    # FIXME: Make this work with other ports as well.
    options.chromium = True

    run(options)


if '__main__' == __name__:
    main()
