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

Unified Diff: tools/metrics/histograms/update_histogram_enum.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, 7 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 side-by-side diff with in-line comments
Download patch
Index: tools/metrics/histograms/update_histogram_enum.py
diff --git a/tools/metrics/histograms/update_histogram_enum.py b/tools/metrics/histograms/update_histogram_enum.py
index fc2c1b84d90b572a393d7b5b77c2ec5975aa8354..ba975996719ce541a07445cf4a3a4c4cefb4cd23 100644
--- a/tools/metrics/histograms/update_histogram_enum.py
+++ b/tools/metrics/histograms/update_histogram_enum.py
@@ -9,14 +9,16 @@ If the file was pretty-printed, the updated version is pretty-printed too.
import logging
import os
-import print_style
import re
import sys
from xml.dom import minidom
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
-from diff_util import PromptUserToAcceptDiff
+import diff_util
+import path_util
+
+import print_style
class UserError(Exception):
def __init__(self, message):
@@ -32,11 +34,15 @@ def Log(message):
def ReadHistogramValues(filename, start_marker, end_marker):
- """Reads in values from |filename|, returning a dictionary mapping value to
- label corresponding to the enum framed by |start_marker| and |end_marker|.
+ """Returns a dictionary of enum values, read from a C++ file.
+
+ Args:
+ filename: The unix-style path (relative to src/) of the file to open.
+ start_marker: A regex that signifies the start of the enum values.
+ end_marker: A regex that signifies the end of the enum values.
"""
# Read the file as a list of lines
- with open(filename) as f:
+ with open(path_util.GetInputFile(filename)) as f:
content = f.readlines()
START_REGEX = re.compile(start_marker)
@@ -143,9 +149,7 @@ def UpdateHistogramFromDict(histogram_enum_name, source_enum_values,
to histograms.xml citing that the values in |histogram_enum_name| were
sourced from |source_enum_path|.
"""
- # TODO(ahernandez.miralles): The line below is present in nearly every
- # file in this directory; factor out into a central location
- HISTOGRAMS_PATH = 'histograms.xml'
+ HISTOGRAMS_PATH = path_util.GetHistogramsFile()
Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH))
with open(HISTOGRAMS_PATH, 'rb') as f:
@@ -159,7 +163,7 @@ def UpdateHistogramFromDict(histogram_enum_name, source_enum_values,
Log('Writing out new histograms file.')
new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc)
- if not PromptUserToAcceptDiff(
+ if not diff_util.PromptUserToAcceptDiff(
xml, new_xml, 'Is the updated version acceptable?'):
Log('Cancelled.')
return
@@ -172,9 +176,14 @@ def UpdateHistogramFromDict(histogram_enum_name, source_enum_values,
def UpdateHistogramEnum(histogram_enum_name, source_enum_path,
start_marker, end_marker):
- """Updates |histogram_enum_name| enum in histograms.xml file with values
- read from |source_enum_path|, where |start_marker| and |end_marker| indicate
- the beginning and end of the source enum definition, respectively.
+ """Reads a C++ enum from a .h file and updates histograms.xml to match.
+
+ Args:
+ histogram_enum_name: The name of the XML <enum> attribute to update.
+ source_enum_path: A unix-style path, relative to src/, giving
+ the C++ header file from which to read the enum.
+ start_marker: A regular expression that matches the start of the C++ enum.
+ end_marker: A regular expression that matches the end of the C++ enum.
"""
Log('Reading histogram enum definition from "{0}".'.format(source_enum_path))
« no previous file with comments | « tools/metrics/histograms/update_extension_permission.py ('k') | tools/metrics/histograms/update_net_error_codes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698