#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import optparse
import parse_deps
import sys
import os

srcdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))

js_warning_message = """/**
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

* WARNING: This file is generated by generate_standalone_timeline_view.py
*
*        Do not edit directly.
*/
"""

css_warning_message = """/**
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file. */

* WARNING: This file is generated by generate_standalone_timeline_view.py
*
*        Do not edit directly.
*/
"""

def generate_css(filenames):
  load_sequence = parse_deps.calc_load_sequence(filenames)

  style_sheet_chunks = [css_warning_message, '\n']
  for module in load_sequence:
    for style_sheet in module.style_sheets:
      style_sheet_chunks.append("""%s\n""" % style_sheet.timeline_view)

  return ''.join(style_sheet_chunks)

def generate_js(filenames):
  load_sequence = parse_deps.calc_load_sequence(filenames)

  js_chunks = [js_warning_message, '\n']
  js_chunks.append("window.FLATTENED = {};\n")

  for module in load_sequence:
    js_chunks.append( "window.FLATTENED['%s'] = true;\n" % module.name)

  for module in load_sequence:
    js_chunks.append(module.timeline_view)
    js_chunks.append("\n")

  return ''.join(js_chunks)

def main(args):
  parser = optparse.OptionParser()
  parser.add_option("--js", dest="js_file",
                    help="Where to place generated javascript file")
  parser.add_option("--css", dest="css_file",
                    help="Where to place generated css file")
  options, args = parser.parse_args(args)

  if not options.js_file and not options.css_file:
    print "Must specify one, or both of --js and --css"
    return 1

  input_filenames = [os.path.join(srcdir, f)
                     for f in ['base.js', 'timeline_view.js']]
  if options.js_file:
    with open(options.js_file, 'w') as f:
      f.write(generate_js(input_filenames))

  if options.css_file:
    with open(options.css_file, 'w') as f:
      f.write(generate_css(input_filenames))

  return 0


if __name__ == "__main__":
  sys.exit(main(sys.argv))

Add script to generate a standalone timeline view.