• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5import optparse
6import parse_deps
7import sys
8import os
9
10srcdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))
11
12js_warning_message = """/**
13// Copyright (c) 2012 The Chromium Authors. All rights reserved.
14// Use of this source code is governed by a BSD-style license that can be
15// found in the LICENSE file.
16
17* WARNING: This file is generated by generate_standalone_timeline_view.py
18*
19*        Do not edit directly.
20*/
21"""
22
23css_warning_message = """/**
24/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
25 * Use of this source code is governed by a BSD-style license that can be
26 * found in the LICENSE file. */
27
28* WARNING: This file is generated by generate_standalone_timeline_view.py
29*
30*        Do not edit directly.
31*/
32"""
33
34py_warning_message = """#!/usr/bin/env python
35#
36# Copyright (c) 2012 The Chromium Authors. All rights reserved.
37# Use of this source code is governed by a BSD-style license that can be
38# found in the LICENSE file. */
39#
40# WARNING: This file is generated by generate_standalone_timeline_view.py
41#
42#        Do not edit directly.
43#
44"""
45
46def _get_input_filenames():
47  return [os.path.join(srcdir, f)
48          for f in ['base.js', 'timeline_view.js']]
49
50def generate_css():
51  filenames = _get_input_filenames()
52  load_sequence = parse_deps.calc_load_sequence(filenames)
53
54  style_sheet_chunks = [css_warning_message, '\n']
55  for module in load_sequence:
56    for style_sheet in module.style_sheets:
57      style_sheet_chunks.append("""%s\n""" % style_sheet.contents)
58
59  return ''.join(style_sheet_chunks)
60
61def generate_js():
62  filenames = _get_input_filenames()
63  load_sequence = parse_deps.calc_load_sequence(filenames)
64
65  js_chunks = [js_warning_message, '\n']
66  js_chunks.append("window.FLATTENED = {};\n")
67
68  for module in load_sequence:
69    js_chunks.append( "window.FLATTENED['%s'] = true;\n" % module.name)
70
71  for module in load_sequence:
72    js_chunks.append(module.contents)
73    js_chunks.append("\n")
74
75  return ''.join(js_chunks)
76
77def main(args):
78  parser = optparse.OptionParser()
79  parser.add_option("--js", dest="js_file",
80                    help="Where to place generated javascript file")
81  parser.add_option("--css", dest="css_file",
82                    help="Where to place generated css file")
83  options, args = parser.parse_args(args)
84
85  if not options.js_file and not options.css_file:
86    print "Must specify one or both of --js or --css"
87    return 1
88
89  if options.js_file:
90    with open(options.js_file, 'w') as f:
91      f.write(generate_js())
92
93  if options.css_file:
94    with open(options.css_file, 'w') as f:
95      f.write(generate_css())
96
97  return 0
98
99
100if __name__ == "__main__":
101  sys.exit(main(sys.argv))
102