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

Unified Diff: tools/metrics/common/pretty_print_xml.py

Issue 2894833005: Make histogram_suffixes separators and enum labels required. (Closed)
Patch Set: Rebase, and improve the error reporting logic Created 3 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
« no previous file with comments | « tools/metrics/actions/print_style.py ('k') | tools/metrics/histograms/enums.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/metrics/common/pretty_print_xml.py
diff --git a/tools/metrics/common/pretty_print_xml.py b/tools/metrics/common/pretty_print_xml.py
index ea65778954f7935c8bbb1861e354ea62273d88c4..0ad3f4f7ce8912351e84b371e4e7d9d6aa46f980 100644
--- a/tools/metrics/common/pretty_print_xml.py
+++ b/tools/metrics/common/pretty_print_xml.py
@@ -66,10 +66,11 @@ def SplitParagraphs(text):
class XmlStyle(object):
"""A class that stores all style specification for an output xml file."""
- def __init__(self, attribute_order, tags_that_have_extra_newline,
- tags_that_dont_indent, tags_that_allow_single_line,
- tags_alphabetization_rules):
+ def __init__(self, attribute_order, required_attributes,
+ tags_that_have_extra_newline, tags_that_dont_indent,
+ tags_that_allow_single_line, tags_alphabetization_rules):
self.attribute_order = attribute_order
+ self.required_attributes = required_attributes
self.tags_that_have_extra_newline = tags_that_have_extra_newline
self.tags_that_dont_indent = tags_that_dont_indent
self.tags_that_allow_single_line = tags_that_allow_single_line
@@ -199,8 +200,27 @@ class XmlStyle(object):
if not node.childNodes:
closing_chars = 2
- # Pretty-print the attributes.
attributes = node.attributes.keys()
+ required_attributes = [attribute for attribute in self.required_attributes
+ if attribute in self.attribute_order[node.tagName]]
+ missing_attributes = [attribute for attribute in required_attributes
+ if attribute not in attributes]
+
+ for attribute in missing_attributes:
+ logging.error(
+ 'Missing attribute "%s" in tag "%s"', attribute, node.tagName)
+ if missing_attributes:
+ missing_attributes_str = (
+ ', '.join('"%s"' % attribute for attribute in missing_attributes))
+ present_attributes = [
+ ' {0}="{1}"'.format(name, value)
+ for name, value in node.attributes.items()]
+ node_str = '<{0}{1}>'.format(node.tagName, ''.join(present_attributes))
+ raise Error(
+ 'Missing attributes {0} in tag "{1}"'.format(
+ missing_attributes_str, node_str))
+
+ # Pretty-print the attributes.
if attributes:
# Reorder the attributes.
unrecognized_attributes = (
« no previous file with comments | « tools/metrics/actions/print_style.py ('k') | tools/metrics/histograms/enums.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698