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

Side by Side Diff: tools/metrics/actions/print_style.py

Issue 149503005: Change actions.txt to actions.xml (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review comments. Created 6 years, 9 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
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 3 # found in the LICENSE file.
5 4
6 import logging 5 """Holds the constants for pretty printing actions.xml."""
6
7 import os 7 import os
8 import sys 8 import sys
9 import unittest
10 9
10 # Import the metrics/common module for pretty print xml.
11 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
12 import pretty_print_xml
11 13
12 if __name__ == '__main__': 14 # Desired order for tag and tag attributes.
13 cur_dir = os.path.abspath(os.path.dirname(__file__)) 15 # { tag_name: [attribute_name, ...] }
14 chromium_dir = os.path.abspath(os.path.join(cur_dir, os.pardir, os.pardir)) 16 ATTRIBUTE_ORDER = {
17 'action': ['name'],
18 'owners': [],
19 'owner':[],
20 'description': [],
21 }
15 22
16 sys.path += [ 23 # Tag names for top-level nodes whose children we don't want to indent.
17 cur_dir, 24 TAGS_THAT_DONT_INDENT = ['actions']
18 25
19 # Include all dependencies. 26 # Extra vertical spacing rules for special tag names.
20 os.path.join(chromium_dir, 'build', 'android'), # For pylib. 27 # {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)}
21 ] 28 TAGS_THAT_HAVE_EXTRA_NEWLINE = {
29 'actions': (2, 1, 1),
30 'action': (1, 1, 1),
31 }
22 32
23 logging.basicConfig( 33 # Tags that we allow to be squished into a single line for brevity.
24 level=logging.DEBUG if '-v' in sys.argv else logging.WARNING, 34 TAGS_THAT_ALLOW_SINGLE_LINE = ['owner', 'description']
25 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s')
26 35
27 suite = unittest.TestSuite() 36 def GetPrintStyle():
28 loader = unittest.TestLoader() 37 """Returns an XmlStyle object for pretty printing actions."""
29 suite.addTests(loader.discover(start_dir=cur_dir, pattern='*_unittest.py')) 38 return pretty_print_xml.XmlStyle(ATTRIBUTE_ORDER,
30 39 TAGS_THAT_HAVE_EXTRA_NEWLINE,
31 res = unittest.TextTestRunner(verbosity=2).run(suite) 40 TAGS_THAT_DONT_INDENT,
32 if res.wasSuccessful(): 41 TAGS_THAT_ALLOW_SINGLE_LINE)
33 sys.exit(0)
34 else:
35 sys.exit(1)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698