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

Side by Side Diff: tools/metrics/ukm/model.py

Issue 2769223005: Create a UKM descriptions XML file (Closed)
Patch Set: Update Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(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 logging
rkaplow 2017/04/03 03:12:51 also unneeded import
Steven Holte 2017/04/04 18:20:51 Done.
7 import operator
8 import os
9 import re
10 import sys
11
12 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
13 import models
14
15 # Model definitions for ukm.xml content
16 _OBSOLETE_TYPE = models.TextNodeType('obsolete')
17 _OWNER_TYPE = models.TextNodeType('owner', single_line=True)
18 _SUMMARY_TYPE = models.TextNodeType('summary')
19
20 _LOWERCASE_NAME_FN = lambda n: n.attributes['name'].value.lower()
21
22 _METRIC_TYPE = models.ObjectNodeType(
23 'metric',
24 attributes=[('name', unicode)],
25 children=[
26 models.ChildType('obsolete', _OBSOLETE_TYPE, False),
27 models.ChildType('owners', _OWNER_TYPE, True),
28 models.ChildType('summary', _SUMMARY_TYPE, False),
29 ])
30
31 _EVENT_TYPE = models.ObjectNodeType(
32 'event',
33 alphabetization=('metric', _LOWERCASE_NAME_FN),
34 attributes=[('name', unicode)],
35 extra_newlines=(1, 1, 1),
36 children=[
37 models.ChildType('obsolete', _OBSOLETE_TYPE, False),
38 models.ChildType('owners', _OWNER_TYPE, True),
39 models.ChildType('summary', _SUMMARY_TYPE, False),
40 models.ChildType('metrics', _METRIC_TYPE, True),
41 ])
42
43 _UKM_CONFIGURATION_TYPE = models.ObjectNodeType(
44 'ukm-configuration',
45 extra_newlines=(2, 1, 1),
46 indent=False,
47 children=[
48 models.ChildType('events', _EVENT_TYPE, True),
49 ])
50
51 UKM_XML_TYPE = models.DocumentType(_UKM_CONFIGURATION_TYPE)
52
53 def UpdateXML(original_xml):
54 """Parses the original xml and return a pretty printed version.
55
56 Args:
57 original_xml: A string containing the original xml file contents.
58
59 Returns:
60 A pretty-printed xml string, or None if the config contains errors.
61 """
62 config = UKM_XML_TYPE.Parse(original_xml)
63
64 return UKM_XML_TYPE.PrettyPrint(config)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698