Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tracing/bin/valueset2html

Issue 2429223003: Add --html --json args to valueset2html. (Closed)
Patch Set: fixed Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import codecs 7 import codecs
8 import json
8 import sys 9 import sys
9 import os 10 import os
10 11
11 tracing_path = os.path.abspath(os.path.join( 12 tracing_path = os.path.abspath(os.path.join(
12 os.path.dirname(os.path.realpath(__file__)), '..')) 13 os.path.dirname(os.path.realpath(__file__)), '..'))
13 sys.path.append(tracing_path) 14 sys.path.append(tracing_path)
14 from tracing import results_renderer 15 from tracing import results_renderer
15 16
16 17
17 def main(): 18 def main():
18 parser = argparse.ArgumentParser(description='Upgrade a results2 instance or ' 19 parser = argparse.ArgumentParser(description='Upgrade a results2 instance or '
19 'add a new ValueSet JSON.', add_help=False) 20 'add a new ValueSet JSON.', add_help=False)
20 parser.add_argument('html_path', metavar='HTML_PATH', 21 parser.add_argument('html_path', metavar='HTML_PATH',
21 help='HTML file path (output).') 22 help='HTML file path (output).')
22 parser.add_argument('-h', '--help', action='help', 23 parser.add_argument('-h', '--help', action='help',
23 help='Show this help message and exit.') 24 help='Show this help message and exit.')
25 parser.add_argument('--html', nargs='+', default=[],
26 help='Zero or more HTML file paths (input).')
27 parser.add_argument('--json', nargs='+', default=[],
28 help='Zero or more JSON file paths (input).')
24 args = parser.parse_args() 29 args = parser.parse_args()
25 30
31 histograms = []
32
33 for html_path in args.html:
34 histograms.extend(results_renderer.ReadExistingResults(
35 open(html_path, 'r')))
36
37 for json_path in args.json:
38 histograms.extend(json.load(open(json_path, 'r')))
39
26 open(args.html_path, 'a').close() # Create file if it doesn't exist. 40 open(args.html_path, 'a').close() # Create file if it doesn't exist.
27 with codecs.open(args.html_path, 41 with codecs.open(args.html_path,
28 mode='r+', encoding='utf-8') as output_stream: 42 mode='r+', encoding='utf-8') as output_stream:
29 results_renderer.RenderHTMLView([], output_stream) 43 results_renderer.RenderHTMLView(histograms, output_stream)
30 44
31 if __name__ == '__main__': 45 if __name__ == '__main__':
32 sys.exit(main()) 46 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698