Index: tools/metrics/actions/print_style.py |
diff --git a/tools/memory_inspector/run_tests b/tools/metrics/actions/print_style.py |
old mode 100755 |
new mode 100644 |
similarity index 13% |
copy from tools/memory_inspector/run_tests |
copy to tools/metrics/actions/print_style.py |
index a073ee1ab0e7118de2cd66a710d4c932f1aba189..905066b83e609601fed75034049eb2f7c830ad27 |
--- a/tools/memory_inspector/run_tests |
+++ b/tools/metrics/actions/print_style.py |
@@ -1,35 +1,41 @@ |
-#!/usr/bin/env python |
# Copyright 2014 The Chromium Authors. All rights reserved. |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-import logging |
+"""Holds the constants for pretty printing actions.xml.""" |
+ |
import os |
import sys |
-import unittest |
- |
- |
-if __name__ == '__main__': |
- cur_dir = os.path.abspath(os.path.dirname(__file__)) |
- chromium_dir = os.path.abspath(os.path.join(cur_dir, os.pardir, os.pardir)) |
- |
- sys.path += [ |
- cur_dir, |
- |
- # Include all dependencies. |
- os.path.join(chromium_dir, 'build', 'android'), # For pylib. |
- ] |
- |
- logging.basicConfig( |
- level=logging.DEBUG if '-v' in sys.argv else logging.WARNING, |
- format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
- |
- suite = unittest.TestSuite() |
- loader = unittest.TestLoader() |
- suite.addTests(loader.discover(start_dir=cur_dir, pattern='*_unittest.py')) |
- res = unittest.TextTestRunner(verbosity=2).run(suite) |
- if res.wasSuccessful(): |
- sys.exit(0) |
- else: |
- sys.exit(1) |
+# Import the metrics/common module for pretty print xml. |
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
+import pretty_print_xml |
+ |
+# Desired order for tag and tag attributes. |
+# { tag_name: [attribute_name, ...] } |
+ATTRIBUTE_ORDER = { |
+ 'action': ['name'], |
+ 'owners': [], |
+ 'owner':[], |
+ 'description': [], |
+} |
+ |
+# Tag names for top-level nodes whose children we don't want to indent. |
+TAGS_THAT_DONT_INDENT = ['actions'] |
+ |
+# Extra vertical spacing rules for special tag names. |
+# {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)} |
+TAGS_THAT_HAVE_EXTRA_NEWLINE = { |
+ 'actions': (2, 1, 1), |
+ 'action': (1, 1, 1), |
+} |
+ |
+# Tags that we allow to be squished into a single line for brevity. |
+TAGS_THAT_ALLOW_SINGLE_LINE = ['owner', 'description'] |
+ |
+def GetPrintStyle(): |
+ """Returns an XmlStyle object for pretty printing actions.""" |
+ return pretty_print_xml.XmlStyle(ATTRIBUTE_ORDER, |
+ TAGS_THAT_HAVE_EXTRA_NEWLINE, |
+ TAGS_THAT_DONT_INDENT, |
+ TAGS_THAT_ALLOW_SINGLE_LINE) |