• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright (C) 2010 Google Inc. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9#         * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11#         * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15#         * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30#
31
32import os.path
33import sys
34
35
36def generate_include_tag(resource_path):
37    if (resource_path.endswith('.js')):
38        return '    <script type="text/javascript" src="%s"></script>\n' % resource_path
39    elif (resource_path.endswith('.css')):
40        return '    <link rel="stylesheet" type="text/css" href="%s">\n' % resource_path
41    else:
42        assert resource_path
43
44
45def write_devtools_html(inspector_file, devtools_file, debug):
46    for line in inspector_file:
47        if not debug:
48            if '<script ' in line or '<link ' in line:
49                continue
50            if '</head>' in line:
51                devtools_file.write(generate_include_tag("inspector.css"))
52                devtools_file.write(generate_include_tag("main/Main.js"))
53        devtools_file.write(line)
54
55
56def main(argv):
57
58    if len(argv) < 4:
59        print('usage: %s inspector_html devtools_html debug' % argv[0])
60        return 1
61
62    # The first argument is ignored. We put 'web.gyp' in the inputs list
63    # for this script, so every time the list of script gets changed, our html
64    # file is rebuilt.
65    inspector_html_name = argv[1]
66    devtools_html_name = argv[2]
67    debug = argv[3] != '0'
68    inspector_html = open(inspector_html_name, 'r')
69    devtools_html = open(devtools_html_name, 'w')
70
71    write_devtools_html(inspector_html, devtools_html, debug)
72
73    devtools_html.close()
74    inspector_html.close()
75
76    # Touch output file directory to make sure that Xcode will copy
77    # modified resource files.
78    if sys.platform == 'darwin':
79        output_dir_name = os.path.dirname(devtools_html_name)
80        os.utime(output_dir_name, None)
81
82if __name__ == '__main__':
83    sys.exit(main(sys.argv))
84