Commit e5e54f01 authored by Ira Burak's avatar Ira Burak Committed by Commit Bot

Added handling of expiry dates to validating.

Bug:744672

Change-Id: Iccb9cfade3b5e39e489adbeb0c2b6a2509240afc
Reviewed-on: https://chromium-review.googlesource.com/576063
Commit-Queue: Ira Burak <iburak@google.com>
Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487570}
parent ec1948f6
# Copyright 2013 The Chromium Authors. All rights reserved. # Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Extract histogram names from the description XML file. """Extract histogram names from the description XML file.
For more information on the format of the XML file, which is self-documenting, For more information on the format of the XML file, which is self-documenting,
...@@ -55,6 +54,7 @@ XML below will generate the following five histograms: ...@@ -55,6 +54,7 @@ XML below will generate the following five histograms:
""" """
import bisect import bisect
import datetime
import copy import copy
import logging import logging
import xml.dom.minidom import xml.dom.minidom
...@@ -67,6 +67,8 @@ MAX_HISTOGRAM_SUFFIX_DEPENDENCY_DEPTH = 5 ...@@ -67,6 +67,8 @@ MAX_HISTOGRAM_SUFFIX_DEPENDENCY_DEPTH = 5
DEFAULT_BASE_HISTOGRAM_OBSOLETE_REASON = ( DEFAULT_BASE_HISTOGRAM_OBSOLETE_REASON = (
'Base histogram. Use suffixes of this histogram instead.') 'Base histogram. Use suffixes of this histogram instead.')
EXPIRY_DATE_PATTERN = "%Y/%m/%d"
class Error(Exception): class Error(Exception):
pass pass
...@@ -167,8 +169,8 @@ def _ExpandHistogramNameWithSuffixes(suffix_name, histogram_name, ...@@ -167,8 +169,8 @@ def _ExpandHistogramNameWithSuffixes(suffix_name, histogram_name,
logging.error( logging.error(
'Prefix histogram_suffixes expansions require histogram names which ' 'Prefix histogram_suffixes expansions require histogram names which '
'include a dot separator. Histogram name is %s, histogram_suffixes is ' 'include a dot separator. Histogram name is %s, histogram_suffixes is '
'%s, and placment is %d', '%s, and placment is %d', histogram_name,
histogram_name, histogram_suffixes_node.getAttribute('name'), placement) histogram_suffixes_node.getAttribute('name'), placement)
raise Error() raise Error()
cluster = '.'.join(sections[0:placement]) + '.' cluster = '.'.join(sections[0:placement]) + '.'
...@@ -186,8 +188,8 @@ def _ExtractEnumsFromXmlTree(tree): ...@@ -186,8 +188,8 @@ def _ExtractEnumsFromXmlTree(tree):
for enum in tree.getElementsByTagName('enum'): for enum in tree.getElementsByTagName('enum'):
name = enum.getAttribute('name') name = enum.getAttribute('name')
if last_name is not None and name.lower() < last_name.lower(): if last_name is not None and name.lower() < last_name.lower():
logging.error('Enums %s and %s are not in alphabetical order', logging.error('Enums %s and %s are not in alphabetical order', last_name,
last_name, name) name)
have_errors = True have_errors = True
last_name = name last_name = name
...@@ -226,8 +228,8 @@ def _ExtractEnumsFromXmlTree(tree): ...@@ -226,8 +228,8 @@ def _ExtractEnumsFromXmlTree(tree):
else: else:
left_int_value = enum_int_values[left_item_index - 1] left_int_value = enum_int_values[left_item_index - 1]
left_label = enum_dict['values'][left_int_value]['label'] left_label = enum_dict['values'][left_int_value]['label']
logging.warning('Insert value %d after %d ("%s")', logging.warning('Insert value %d after %d ("%s")', int_value,
int_value, left_int_value, left_label) left_int_value, left_label)
else: else:
last_int_value = int_value last_int_value = int_value
...@@ -250,6 +252,17 @@ def _ExtractOwners(xml_node): ...@@ -250,6 +252,17 @@ def _ExtractOwners(xml_node):
return owners return owners
def _GetDateFromString(date_str):
"""Converts |date_str| to datetime.date object if the string matches
'YYYY/MM/DD' format. Otherwise returns None.
"""
try:
date = datetime.datetime.strptime(date_str, EXPIRY_DATE_PATTERN).date()
except ValueError:
date = None
return date
def _ProcessBaseHistogramAttribute(node, histogram_entry): def _ProcessBaseHistogramAttribute(node, histogram_entry):
if node.hasAttribute('base'): if node.hasAttribute('base'):
is_base = node.getAttribute('base').lower() == 'true' is_base = node.getAttribute('base').lower() == 'true'
...@@ -278,6 +291,18 @@ def _ExtractHistogramsFromXmlTree(tree, enums): ...@@ -278,6 +291,18 @@ def _ExtractHistogramsFromXmlTree(tree, enums):
continue continue
histograms[name] = histogram_entry = {} histograms[name] = histogram_entry = {}
# Handle expiry dates.
if histogram.hasAttribute('expiry_date'):
expiry_date_str = histogram.getAttribute('expiry_date')
expiry_date = _GetDateFromString(expiry_date_str)
if expiry_date is None:
logging.error(
'Expiry date of histogram %s does not match expected format: "%s",'
' found %s.',
name, EXPIRY_DATE_PATTERN, expiry_date_str)
have_errors = True
histograms[expiry_date] = expiry_date
# Find <owner> tag. # Find <owner> tag.
owners = _ExtractOwners(histogram) owners = _ExtractOwners(histogram)
if owners: if owners:
...@@ -366,6 +391,7 @@ def _UpdateHistogramsWithSuffixes(tree, histograms): ...@@ -366,6 +391,7 @@ def _UpdateHistogramsWithSuffixes(tree, histograms):
# queue. histogram_suffixes whose dependencies have not yet been processed # queue. histogram_suffixes whose dependencies have not yet been processed
# will get relegated to the back of the queue to be processed later. # will get relegated to the back of the queue to be processed later.
reprocess_queue = [] reprocess_queue = []
def GenerateHistogramSuffixes(): def GenerateHistogramSuffixes():
for f in tree.getElementsByTagName(histogram_suffix_tag): for f in tree.getElementsByTagName(histogram_suffix_tag):
yield 0, f yield 0, f
...@@ -410,11 +436,11 @@ def _UpdateHistogramsWithSuffixes(tree, histograms): ...@@ -410,11 +436,11 @@ def _UpdateHistogramsWithSuffixes(tree, histograms):
last_histogram_name = None last_histogram_name = None
for affected_histogram in affected_histograms: for affected_histogram in affected_histograms:
histogram_name = affected_histogram.getAttribute('name') histogram_name = affected_histogram.getAttribute('name')
if (last_histogram_name is not None if (last_histogram_name is not None and
and histogram_name.lower() < last_histogram_name.lower()): histogram_name.lower() < last_histogram_name.lower()):
logging.error('Affected histograms %s and %s of histogram_suffixes %s ' logging.error('Affected histograms %s and %s of histogram_suffixes %s '
'are not in alphabetical order', 'are not in alphabetical order', last_histogram_name,
last_histogram_name, histogram_name, name) histogram_name, name)
have_errors = True have_errors = True
last_histogram_name = histogram_name last_histogram_name = histogram_name
with_suffixes = affected_histogram.getElementsByTagName(with_tag) with_suffixes = affected_histogram.getElementsByTagName(with_tag)
...@@ -435,8 +461,8 @@ def _UpdateHistogramsWithSuffixes(tree, histograms): ...@@ -435,8 +461,8 @@ def _UpdateHistogramsWithSuffixes(tree, histograms):
# histograms. # histograms.
if new_histogram.get('base', False): if new_histogram.get('base', False):
del new_histogram['base'] del new_histogram['base']
if (new_histogram.get('obsolete', '') == if (new_histogram.get(
DEFAULT_BASE_HISTOGRAM_OBSOLETE_REASON): 'obsolete', '') == DEFAULT_BASE_HISTOGRAM_OBSOLETE_REASON):
del new_histogram['obsolete'] del new_histogram['obsolete']
histograms[new_histogram_name] = new_histogram histograms[new_histogram_name] = new_histogram
......
...@@ -19,7 +19,7 @@ ATTRIBUTE_ORDER = { ...@@ -19,7 +19,7 @@ ATTRIBUTE_ORDER = {
'details': [], 'details': [],
'enum': ['name'], 'enum': ['name'],
'enums': [], 'enums': [],
'histogram': ['base', 'name', 'enum', 'units'], 'histogram': ['base', 'name', 'enum', 'units', 'expiry_date'],
'histogram-configuration': ['logsource'], 'histogram-configuration': ['logsource'],
'histogram_suffixes': ['name', 'separator', 'ordering'], 'histogram_suffixes': ['name', 'separator', 'ordering'],
'histogram_suffixes_list': [], 'histogram_suffixes_list': [],
......
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