| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 # """Model objects for ukm.xml contents.""" |
| 5 |
| 6 import os |
| 7 import sys |
| 8 |
| 9 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
| 10 import models |
| 11 |
| 12 # Model definitions for ukm.xml content |
| 13 _OBSOLETE_TYPE = models.TextNodeType('obsolete') |
| 14 _OWNER_TYPE = models.TextNodeType('owner', single_line=True) |
| 15 _SUMMARY_TYPE = models.TextNodeType('summary') |
| 16 |
| 17 _LOWERCASE_NAME_FN = lambda n: n.attributes['name'].value.lower() |
| 18 |
| 19 _METRIC_TYPE = models.ObjectNodeType( |
| 20 'metric', |
| 21 attributes=[('name', unicode)], |
| 22 children=[ |
| 23 models.ChildType('obsolete', _OBSOLETE_TYPE, False), |
| 24 models.ChildType('owners', _OWNER_TYPE, True), |
| 25 models.ChildType('summary', _SUMMARY_TYPE, False), |
| 26 ]) |
| 27 |
| 28 _EVENT_TYPE = models.ObjectNodeType( |
| 29 'event', |
| 30 alphabetization=('metric', _LOWERCASE_NAME_FN), |
| 31 attributes=[('name', unicode)], |
| 32 extra_newlines=(1, 1, 1), |
| 33 children=[ |
| 34 models.ChildType('obsolete', _OBSOLETE_TYPE, False), |
| 35 models.ChildType('owners', _OWNER_TYPE, True), |
| 36 models.ChildType('summary', _SUMMARY_TYPE, False), |
| 37 models.ChildType('metrics', _METRIC_TYPE, True), |
| 38 ]) |
| 39 |
| 40 _UKM_CONFIGURATION_TYPE = models.ObjectNodeType( |
| 41 'ukm-configuration', |
| 42 extra_newlines=(2, 1, 1), |
| 43 indent=False, |
| 44 children=[ |
| 45 models.ChildType('events', _EVENT_TYPE, True), |
| 46 ]) |
| 47 |
| 48 UKM_XML_TYPE = models.DocumentType(_UKM_CONFIGURATION_TYPE) |
| 49 |
| 50 def UpdateXML(original_xml): |
| 51 """Parses the original xml and return a pretty printed version. |
| 52 |
| 53 Args: |
| 54 original_xml: A string containing the original xml file contents. |
| 55 |
| 56 Returns: |
| 57 A pretty-printed xml string, or None if the config contains errors. |
| 58 """ |
| 59 config = UKM_XML_TYPE.Parse(original_xml) |
| 60 |
| 61 return UKM_XML_TYPE.PrettyPrint(config) |
| OLD | NEW |