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 codecs 6 import argparse 7 import os 8 import sys 9 10 import py_vulcanize 11 12 import tracing_project 13 14 15 def Main(args): 16 parser = argparse.ArgumentParser(usage='%(prog)s --outdir=<directory>') 17 parser.add_argument('--outdir', dest='out_dir', 18 help='Where to place generated content') 19 parser.add_argument('--no-min', default=False, action='store_true', 20 help='Skip minification') 21 args = parser.parse_args(args) 22 23 if not args.out_dir: 24 sys.stderr.write('ERROR: Must specify --outdir=<directory>') 25 parser.print_help() 26 return 1 27 28 names = ['tracing.ui.extras.about_tracing.about_tracing'] 29 project = tracing_project.TracingProject() 30 31 vulcanizer = project.CreateVulcanizer() 32 load_sequence = vulcanizer.CalcLoadSequenceForModuleNames(names) 33 34 olddir = os.getcwd() 35 try: 36 if not os.path.exists(args.out_dir): 37 os.makedirs(args.out_dir) 38 o = codecs.open(os.path.join(args.out_dir, 'about_tracing.html'), 'w', 39 encoding='utf-8') 40 try: 41 py_vulcanize.GenerateStandaloneHTMLToFile( 42 o, 43 load_sequence, 44 title='chrome://tracing', 45 flattened_js_url='tracing.js', 46 minify=not args.no_min) 47 except py_vulcanize.module.DepsException, ex: 48 sys.stderr.write('Error: %s\n\n' % str(ex)) 49 return 255 50 o.close() 51 52 o = codecs.open(os.path.join(args.out_dir, 'about_tracing.js'), 'w', 53 encoding='utf-8') 54 assert o.encoding == 'utf-8' 55 py_vulcanize.GenerateJSToFile( 56 o, 57 load_sequence, 58 use_include_tags_for_scripts=False, 59 dir_for_include_tag_root=args.out_dir, 60 minify=not args.no_min) 61 o.close() 62 63 finally: 64 os.chdir(olddir) 65 66 return 0 67