[Piglit] [PATCH v2 4/4] piglit-print-commands: Add --format option

Dylan Baker dylan at pnwbakers.com
Mon May 9 19:42:57 UTC 2016


This option allows the format of the output string to be modified by
passing a command line argument. This allows for specialized formats to
be printed for other uses than the original usage that print-commands
was designed for.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>

v2: - Make help message for --format option better.

---
 framework/programs/print_commands.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/framework/programs/print_commands.py b/framework/programs/print_commands.py
index 8330d55..033ca87 100644
--- a/framework/programs/print_commands.py
+++ b/framework/programs/print_commands.py
@@ -18,7 +18,12 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-"""Print each test's command in a consumable format."""
+"""Print each test's command in a user-defined consumable format.
+
+This is meant to provide a mechanism to export piglit commands to other tools,
+or to create lists of tests to be consumed via "piglit run --test-list"
+
+"""
 
 from __future__ import (
     absolute_import, division, print_function, unicode_literals
@@ -65,6 +70,17 @@ def main(input_):
                         metavar="<regex>",
                         help="Exclude matching tests (can be used more than "
                              "once)")
+    parser.add_argument("--format",
+                        dest="format_string",
+                        default="{name} ::: {command}",
+                        action="store",
+                        help="A template string that defines the output "
+                             "format. It has two replacement tokens that can "
+                             "be provided, along with any arbitrary text, "
+                             "which will be printed verbatim. The two tokens "
+                             "are '{name}', which will be replaced with the "
+                             "name of the test; and '{command}', which will "
+                             "be replaced with the command to run the test.")
     parser.add_argument("testProfile",
                         metavar="<Path to testfile>",
                         help="Path to results folder")
@@ -82,4 +98,6 @@ def main(input_):
     profile_._prepare_test_list()
     for name, test in six.iteritems(profile_.test_list):
         assert isinstance(test, Test)
-        print(name, ':::', get_command(test, piglit_dir))
+        print(args.format_string.format(
+            name=name,
+            command=get_command(test, piglit_dir)))
-- 
2.8.2



More information about the Piglit mailing list