Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / tracing / generate_trace_viewer_grd.py
blobacc7355cf6e96743af61d1a22098fa9114229839
1 #!/usr/bin/env python
2 # Copyright 2013 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.
6 """Creates a grd file for packaging the trace-viewer files.
8 This file is modified from the devtools generate_devtools_grd.py file.
9 """
11 import errno
12 import os
13 import shutil
14 import sys
15 from xml.dom import minidom
17 kTracingResourcePrefix = 'IDR_TRACING_'
18 kGrdTemplate = '''<?xml version="1.0" encoding="UTF-8"?>
19 <grit latest_public_release="0" current_release="1">
20 <outputs>
21 <output filename="grit/tracing_resources.h" type="rc_header">
22 <emit emit_type='prepend'></emit>
23 </output>
24 <output filename="tracing_resources.pak" type="data_package" />
25 </outputs>
26 <release seq="1">
27 <includes>
28 <if expr="not is_android"></if>
29 </includes>
30 </release>
31 </grit>
33 '''
36 class ParsedArgs:
37 def __init__(self, source_files, output_filename):
38 self.source_files = source_files
39 self.output_filename = output_filename
42 def parse_args(argv):
43 output_position = argv.index('--output')
44 source_files = argv[:output_position]
45 return ParsedArgs(source_files, argv[output_position + 1])
48 def make_name_from_filename(filename):
49 return kTracingResourcePrefix + (os.path.splitext(filename)[1][1:]).upper()
52 def add_file_to_grd(grd_doc, filename):
53 includes_node = grd_doc.getElementsByTagName('if')[0]
54 includes_node.appendChild(grd_doc.createTextNode('\n '))
56 new_include_node = grd_doc.createElement('include')
57 new_include_node.setAttribute('name', make_name_from_filename(filename))
58 new_include_node.setAttribute('file', filename)
59 new_include_node.setAttribute('type', 'BINDATA')
60 new_include_node.setAttribute('flattenhtml', 'true')
61 if filename.endswith('.html'):
62 new_include_node.setAttribute('allowexternalscript', 'true')
63 includes_node.appendChild(new_include_node)
66 def main(argv):
67 parsed_args = parse_args(argv[1:])
69 output_directory = os.path.dirname(parsed_args.output_filename)
71 doc = minidom.parseString(kGrdTemplate)
72 for filename in parsed_args.source_files:
73 add_file_to_grd(doc, os.path.basename(filename))
75 with open(parsed_args.output_filename, 'w') as output_file:
76 output_file.write(doc.toxml(encoding='UTF-8'))
79 if __name__ == '__main__':
80 sys.exit(main(sys.argv))