Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / build / generate_standalone_timeline_view.py
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import base64
6 import optparse
7 import sys
8 import os
9 import re
10
11 import tvcm
12 from trace_viewer import trace_viewer_project
13 def _sopen(filename, mode):
14   if filename != '-':
15     return open(filename, mode)
16   return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
17
18 def main(args):
19   parser = optparse.OptionParser(
20     usage="%prog --js=<filename> --css=<filename>",
21     epilog="""
22 A script to takes all of the javascript and css files that comprise trace-viewer
23 and merges them together into two giant js and css files, taking into account
24 various ordering restrictions between them.
25 """)
26   parser.add_option("--js", dest="js_file",
27                     help="Where to place generated javascript file")
28   parser.add_option("--css", dest="css_file",
29                     help="Where to place generated css file")
30   options, args = parser.parse_args(args)
31
32   if not options.js_file and not options.css_file:
33     sys.stderr.write("ERROR: Must specify one of --js=<filename> or "
34         "--css=<filename>\n\n")
35     parser.print_help()
36     return 1
37
38   project = trace_viewer_project.TraceViewerProject()
39   load_sequence = project.CalcLoadSequenceForModuleFilenames(
40       ['tracing/standalone_timeline_view.js'])
41
42   if options.js_file:
43     with _sopen(options.js_file, 'w') as f:
44       f.write(tvcm.GenerateJS(load_sequence))
45
46   if options.css_file:
47     with _sopen(options.css_file, 'w') as f:
48       f.write(tvcm.GenerateCSS(load_sequence))
49
50   return 0