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

Side by Side Diff: tools/metrics/common/presubmit_util.py

Issue 1143323006: Histograms.xml python script housekeeping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bad_message
Patch Set: Fix imports (sadface) Created 5 years, 6 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 | « tools/metrics/common/path_util.py ('k') | tools/metrics/histograms/find_unmapped_histograms.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import sys 6 import sys
7 import logging 7 import logging
8 import shutil 8 import shutil
9 9
10 sys.path.insert(1, os.path.join(sys.path[0], '..', '..', 'python'))
11 import google.path_utils
12
10 import diff_util 13 import diff_util
11 14
12 sys.path.insert(1, os.path.join(sys.path[0], '..', '..', 'python'))
13 from google import path_utils
14
15 def DoPresubmitMain(argv, original_filename, backup_filename, script_name, 15 def DoPresubmitMain(argv, original_filename, backup_filename, script_name,
16 prettyFn): 16 prettyFn):
17 """Execute presubmit/pretty printing for the target file. 17 """Execute presubmit/pretty printing for the target file.
18 18
19 Args: 19 Args:
20 argv: command line arguments 20 argv: command line arguments
21 original_filename: The filename to read from. 21 original_filename: The filename to read from.
22 backup_filename: When pretty printing, move the old file contents here. 22 backup_filename: When pretty printing, move the old file contents here.
23 script_name: The name of the script to run for pretty printing. 23 script_name: The name of the script to run for pretty printing.
24 prettyFn: A function which takes the original xml content and produces 24 prettyFn: A function which takes the original xml content and produces
25 pretty printed xml. 25 pretty printed xml.
26 26
27 Returns: 27 Returns:
28 An exit status. Non-zero indicates errors. 28 An exit status. Non-zero indicates errors.
29 """ 29 """
30 logging.basicConfig(level=logging.INFO) 30 logging.basicConfig(level=logging.INFO)
31 presubmit = ('--presubmit' in argv) 31 presubmit = ('--presubmit' in argv)
32 32
33 # If there is a description xml in the current working directory, use that. 33 # If there is a description xml in the current working directory, use that.
34 # Otherwise, use the one residing in the same directory as this script. 34 # Otherwise, use the one residing in the same directory as this script.
35 xml_dir = os.getcwd() 35 xml_dir = os.getcwd()
36 if not os.path.isfile(os.path.join(xml_dir, original_filename)): 36 if not os.path.isfile(os.path.join(xml_dir, original_filename)):
37 xml_dir = path_utils.ScriptDir() 37 xml_dir = google.path_utils.ScriptDir()
38 38
39 xml_path = os.path.join(xml_dir, original_filename) 39 xml_path = os.path.join(xml_dir, original_filename)
40 40
41 # Save the original file content. 41 # Save the original file content.
42 logging.info('Loading %s...', os.path.relpath(xml_path)) 42 logging.info('Loading %s...', os.path.relpath(xml_path))
43 with open(xml_path, 'rb') as f: 43 with open(xml_path, 'rb') as f:
44 original_xml = f.read() 44 original_xml = f.read()
45 45
46 # Check there are no CR ('\r') characters in the file. 46 # Check there are no CR ('\r') characters in the file.
47 if '\r' in original_xml: 47 if '\r' in original_xml:
(...skipping 22 matching lines...) Expand all
70 sys.exit(1) 70 sys.exit(1)
71 71
72 logging.info('Creating backup file: %s', backup_filename) 72 logging.info('Creating backup file: %s', backup_filename)
73 shutil.move(xml_path, os.path.join(xml_dir, backup_filename)) 73 shutil.move(xml_path, os.path.join(xml_dir, backup_filename))
74 74
75 with open(xml_path, 'wb') as f: 75 with open(xml_path, 'wb') as f:
76 f.write(pretty) 76 f.write(pretty)
77 logging.info('Updated %s. Don\'t forget to add it to your changelist', 77 logging.info('Updated %s. Don\'t forget to add it to your changelist',
78 xml_path) 78 xml_path)
79 sys.exit(0) 79 sys.exit(0)
OLDNEW
« no previous file with comments | « tools/metrics/common/path_util.py ('k') | tools/metrics/histograms/find_unmapped_histograms.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698