3 # Copyright (C) 2011 Google Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
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
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.
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.
31 """Creates a zip file containing the web inspector files for debugging.
33 The zip file contains all the .html, .js, .css and image files used by the
34 web inspector. The js files and css files are not concatenated and are not
37 from __future__ import with_statement
44 import concatenate_css_files
45 import concatenate_js_files
46 import generate_devtools_html
50 def __init__(self, inspector_html, devtools_files, search_dirs,
51 image_search_dirs, output_filename):
52 self.inspector_html = inspector_html
53 self.devtools_files = devtools_files
54 self.search_dirs = search_dirs
55 self.image_search_dirs = image_search_dirs
56 self.output_filename = output_filename
60 inspector_html = argv[0]
62 devtools_files_position = argv.index('--devtools-files')
63 search_path_position = argv.index('--search-path')
64 image_search_path_position = argv.index('--image-search-path')
65 output_position = argv.index('--output')
67 devtools_files = argv[devtools_files_position + 1:search_path_position]
68 search_dirs = argv[search_path_position + 1:image_search_path_position]
69 image_search_dirs = argv[image_search_path_position + 1:output_position]
71 return ParsedArgs(inspector_html, devtools_files, search_dirs,
72 image_search_dirs, argv[output_position + 1])
76 parsed_args = parse_args(argv[1:])
78 devtools_html = StringIO.StringIO()
79 with open(parsed_args.inspector_html, 'r') as inspector_file:
80 generate_devtools_html.write_devtools_html(
81 inspector_file, devtools_html, True, parsed_args.devtools_files)
83 zip = zipfile.ZipFile(parsed_args.output_filename, 'w', zipfile.ZIP_DEFLATED)
84 zip.writestr("devtools.html", devtools_html.getvalue())
86 css_extractor = concatenate_css_files.OrderedCSSFilesExtractor(
87 devtools_html.getvalue())
88 js_extractor = concatenate_js_files.OrderedJSFilesExtractor(
89 devtools_html.getvalue())
91 expander = concatenate_css_files.PathExpander(parsed_args.search_dirs)
92 files = css_extractor.ordered_css_files + js_extractor.ordered_js_files
93 for input_file_name in set(files):
94 full_path = expander.expand(input_file_name)
96 raise Exception('File %s referenced in %s not found on any source paths, '
97 'check source tree for consistency' %
98 (input_file_name, 'devtools.html'))
99 zip.write(full_path, os.path.basename(full_path))
101 for dirname in parsed_args.image_search_dirs:
102 for filename in os.listdir(dirname):
103 if not filename.endswith('.png') and not filename.endswith('.gif'):
105 zip.write(os.path.join(dirname, filename),
106 os.path.join('Images', filename))
108 # It would be nice to use the with statement to scope closing the archive,
109 # but that wasn't added until python 2.7.
113 if '__main__' == __name__:
114 sys.exit(main(sys.argv))