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

Side by Side Diff: tools/metrics/histograms/pretty_print.py

Issue 163473008: Make pretty_print.py look for a histograms.xml in the current working directory first. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« 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 2013 The Chromium Authors. All rights reserved. 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 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 """Pretty-prints the histograms.xml file, alphabetizing tags, wrapping text 6 """Pretty-prints the histograms.xml file, alphabetizing tags, wrapping text
7 at 80 chars, enforcing standard attribute ordering, and standardizing 7 at 80 chars, enforcing standard attribute ordering, and standardizing
8 indentation. 8 indentation.
9 9
10 This is quite a bit more complicated than just calling tree.toprettyxml(); 10 This is quite a bit more complicated than just calling tree.toprettyxml();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 316
317 def main(): 317 def main():
318 logging.basicConfig(level=logging.INFO) 318 logging.basicConfig(level=logging.INFO)
319 319
320 presubmit = ('--presubmit' in sys.argv) 320 presubmit = ('--presubmit' in sys.argv)
321 321
322 histograms_filename = 'histograms.xml' 322 histograms_filename = 'histograms.xml'
323 histograms_backup_filename = 'histograms.before.pretty-print.xml' 323 histograms_backup_filename = 'histograms.before.pretty-print.xml'
324 324
325 script_dir = path_utils.ScriptDir() 325 # If there is a histograms.xml in the current working directory, use that.
326 # Otherwise, use the one residing in the same directory as this script.
327 histograms_dir = os.getcwd()
328 if not os.path.isfile(os.path.join(histograms_dir, histograms_filename)):
329 histograms_dir = path_utils.ScriptDir()
326 330
327 histograms_pathname = os.path.join(script_dir, histograms_filename) 331 histograms_pathname = os.path.join(histograms_dir, histograms_filename)
328 histograms_backup_pathname = os.path.join(script_dir, 332 histograms_backup_pathname = os.path.join(histograms_dir,
329 histograms_backup_filename) 333 histograms_backup_filename)
330 334
331 logging.info('Loading %s...' % histograms_filename) 335 logging.info('Loading %s...' % os.path.relpath(histograms_pathname))
332 with open(histograms_pathname, 'rb') as f: 336 with open(histograms_pathname, 'rb') as f:
333 xml = f.read() 337 xml = f.read()
334 338
335 # Check there are no CR ('\r') characters in the file. 339 # Check there are no CR ('\r') characters in the file.
336 if '\r' in xml: 340 if '\r' in xml:
337 logging.info('DOS-style line endings (CR characters) detected - these are ' 341 logging.info('DOS-style line endings (CR characters) detected - these are '
338 'not allowed. Please run dos2unix %s' % histograms_filename) 342 'not allowed. Please run dos2unix %s' % histograms_filename)
339 sys.exit(1) 343 sys.exit(1)
340 344
341 logging.info('Pretty-printing...') 345 logging.info('Pretty-printing...')
(...skipping 19 matching lines...) Expand all
361 logging.info('Creating backup file %s' % histograms_backup_filename) 365 logging.info('Creating backup file %s' % histograms_backup_filename)
362 shutil.move(histograms_pathname, histograms_backup_pathname) 366 shutil.move(histograms_pathname, histograms_backup_pathname)
363 367
364 logging.info('Writing new %s file' % histograms_filename) 368 logging.info('Writing new %s file' % histograms_filename)
365 with open(histograms_pathname, 'wb') as f: 369 with open(histograms_pathname, 'wb') as f:
366 f.write(pretty) 370 f.write(pretty)
367 371
368 372
369 if __name__ == '__main__': 373 if __name__ == '__main__':
370 main() 374 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