Commit 2d66c06a authored by Weilun Shi's avatar Weilun Shi Committed by Commit Bot

Refactor some code in tools/metrics/histograms directory

Change-Id: I67a0f21df7e3becd2e76e4971d040e9c1c4138ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354725
Commit-Queue: Weilun Shi <sweilun@chromium.org>
Auto-Submit: Weilun Shi <sweilun@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798297}
parent e76c6253
...@@ -9,7 +9,6 @@ histograms. ...@@ -9,7 +9,6 @@ histograms.
from __future__ import print_function from __future__ import print_function
import errno
import os import os
import sys import sys
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
...@@ -18,6 +17,9 @@ import extract_histograms ...@@ -18,6 +17,9 @@ import extract_histograms
import histogram_paths import histogram_paths
import merge_xml import merge_xml
sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
import path_util
def PrintOwners(root): def PrintOwners(root):
assert root.tag == 'histogram-configuration' assert root.tag == 'histogram-configuration'
...@@ -67,13 +69,14 @@ def main(): ...@@ -67,13 +69,14 @@ def main():
python histogram_ownership.py python histogram_ownership.py
""" """
if len(sys.argv) == 1: if len(sys.argv) == 1:
merged_xml_string = merge_xml.PrettyPrintMergedFiles( merged_xml_string = merge_xml.MergeFiles(
histogram_paths.ALL_XMLS) histogram_paths.ALL_XMLS).toxml()
root = ET.fromstring(merged_xml_string) root = ET.fromstring(merged_xml_string)
else: else:
rel_path = sys.argv[1] rel_path = path_util.GetInputFile(
os.path.join('tools', 'metrics', 'histograms', sys.argv[1]))
if not os.path.exists(rel_path): if not os.path.exists(rel_path):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT)) raise ValueError("A histograms.xml file does not exist in %s" % rel_path)
tree = ET.parse(rel_path) tree = ET.parse(rel_path)
root = tree.getroot() root = tree.getroot()
......
...@@ -7,7 +7,6 @@ Splits nodes according to the first camelcase part of their name attribute. ...@@ -7,7 +7,6 @@ Splits nodes according to the first camelcase part of their name attribute.
Intended to be used to split up the large histograms.xml or enums.xml file. Intended to be used to split up the large histograms.xml or enums.xml file.
""" """
import errno
import logging import logging
import os import os
import sys import sys
...@@ -40,8 +39,7 @@ def _ParseHistogramsXMLFile(base_dir): ...@@ -40,8 +39,7 @@ def _ParseHistogramsXMLFile(base_dir):
FileNotFoundError if histograms.xml not found in |base_dir|. FileNotFoundError if histograms.xml not found in |base_dir|.
""" """
if HISTOGRAMS_XML not in os.listdir(base_dir): if HISTOGRAMS_XML not in os.listdir(base_dir):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), raise ValueError(HISTOGRAMS_XML + 'is not in %s' % base_dir)
HISTOGRAMS_XML)
dom = minidom.parse(os.path.join(base_dir, HISTOGRAMS_XML)) dom = minidom.parse(os.path.join(base_dir, HISTOGRAMS_XML))
comments = [] comments = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment