[Piglit] [PATCH 3/3] piglit: Add piglit command

Dylan Baker baker.dylan.c at gmail.com
Wed Apr 30 11:18:24 PDT 2014


On Wednesday, April 30, 2014 10:28:57 Jordan Justen wrote:
> The piglit command is a wrapper command for the
> piglit-<command>.py scripts.
> 
> For example, running 'piglit run' is equivalent to piglit-run.py.
> 
> It is installed to $PREFIX/bin/piglit, and will launch the
> sub-commands either at their installed location in
> $PREFIX/lib/piglit, or in the source tree.
> 
> 'piglit help <command>' will run 'piglit-<command>.py --help'
> as expected.
> 
> 'piglit', 'piglit help' or 'piglit --help' will show the list
> of possible sub-commands.
> 
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>  CMakeLists.txt | 14 +++++++++
>  piglit.in      | 42 +++++++++++++++++++++++++
>  piglit_cmd.py  | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 152 insertions(+)
>  create mode 100755 piglit.in
>  create mode 100755 piglit_cmd.py
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index a9a602c..7561788 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -12,6 +12,9 @@ INCLUDE (FindPkgConfig)
>  
>  project (piglit)
>  
> +set(PythonInterp_FIND_VERSION 2)
> +find_package(PythonInterp REQUIRED)
> +
>  find_package(Threads)
>  find_package(X11)
>  if(X11_FOUND)
> @@ -398,6 +401,11 @@ configure_file(
>  	"${piglit_BINARY_DIR}/tests/util/config.h"
>  )
>  
> +configure_file(
> +	"${piglit_SOURCE_DIR}/piglit.in"
> +	"${piglit_BINARY_DIR}/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}"
> +)
> +
>  include(cmake/piglit_util.cmake)
>  include(cmake/piglit_glapi.cmake)
>  include(cmake/piglit_dispatch.cmake)
> @@ -420,6 +428,7 @@ install (
>  
>  install (
>  	PROGRAMS
> +		piglit_cmd.py
>  		piglit-merge-results.py
>  		piglit-print-commands.py
>  		piglit-run.py
> @@ -455,6 +464,11 @@ install (
>  	REGEX "CMakeFiles|CMakeLists" EXCLUDE
>  )
>  
> +install (
> +	PROGRAMS piglit${PIGLIT_INSTALL_VERSION_SUFFIX}
> +	DESTINATION ${CMAKE_INSTALL_BINDIR}
> +)
> +
>  
>  set (CPACK_PACKAGE_VERSION_MAJOR "1")
>  set (CPACK_PACKAGE_VERSION_MINOR "0")
> diff --git a/piglit.in b/piglit.in
> new file mode 100755
> index 0000000..1290d9f
> --- /dev/null
> +++ b/piglit.in
> @@ -0,0 +1,42 @@
> +#!@PYTHON_EXECUTABLE@
> +#
> +# Permission is hereby granted, free of charge, to any person
> +# obtaining a copy of this software and associated documentation
> +# files (the "Software"), to deal in the Software without
> +# restriction, including without limitation the rights to use,
> +# copy, modify, merge, publish, distribute, sublicense, and/or
> +# sell copies of the Software, and to permit persons to whom the
> +# Software is furnished to do so, subject to the following
> +# conditions:
> +#
> +# This permission notice shall be included in all copies or
> +# substantial portions of the Software.
> +#
> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
> +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
> +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
> +# PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR(S) BE
> +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
> +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
> +# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> +# DEALINGS IN THE SOFTWARE.
> +
> +import sys
> +import os
> +
> +piglit_source = '@piglit_SOURCE_DIR@'
> +piglit_install_full_libdir = '@PIGLIT_INSTALL_FULL_LIBDIR@'
> +
> +piglit_cmd_source_path = \
> +    os.path.realpath(os.path.join(piglit_source, 'piglit'))
> +piglit_cmd_in_source = \
> +    piglit_cmd_source_path == os.path.realpath(sys.argv[0])
> +
> +if piglit_cmd_in_source:
> +   piglit_run_dir = piglit_source
> +else:
> +   piglit_run_dir = piglit_install_full_libdir
> +
> +sys.path.insert(0, piglit_run_dir)
> +import piglit_cmd
> +piglit_cmd.run(piglit_run_dir, piglit_cmd_in_source)
> diff --git a/piglit_cmd.py b/piglit_cmd.py
> new file mode 100755
> index 0000000..50916ab
> --- /dev/null
> +++ b/piglit_cmd.py
> @@ -0,0 +1,96 @@
> +#!/usr/bin/env python
> +#
> +# Permission is hereby granted, free of charge, to any person
> +# obtaining a copy of this software and associated documentation
> +# files (the "Software"), to deal in the Software without
> +# restriction, including without limitation the rights to use,
> +# copy, modify, merge, publish, distribute, sublicense, and/or
> +# sell copies of the Software, and to permit persons to whom the
> +# Software is furnished to do so, subject to the following
> +# conditions:
> +#
> +# This permission notice shall be included in all copies or
> +# substantial portions of the Software.
> +#
> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
> +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
> +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
> +# PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR(S) BE
> +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
> +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
> +# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> +# DEALINGS IN THE SOFTWARE.
> +
> +import os
> +import subprocess
> +import sys
> +
> +class piglit_cmd:
> +   def __init__(self, base_dir, from_source):
> +      self.base_dir = base_dir
> +      self.from_source = from_source
> +      self.get_sub_commands()
> +
> +   def run(self):
> +      generic_help = False
> +      unknown_command_help = None
> +      command_help = None
> +      if len(sys.argv) <= 1:
> +         generic_help = True
> +      elif sys.argv[1] in ('help', '--help'):
> +         if len(sys.argv) > 2 and sys.argv[2] in self.cmds:
> +            command_help = sys.argv[2]
> +         else:
> +            generic_help = True
> +      elif not sys.argv[1] in self.cmds:
> +         unknown_command_help = sys.argv[1]
> +
> +      if command_help:
> +         return self.command_help(command_help)
> +      elif unknown_command_help:
> +         return self.unknown_command_help(unknown_command_help)
> +      elif generic_help:
> +         return self.generic_help()
> +      else:
> +         return self.run_command(sys.argv[1], sys.argv[2:])
> +
> +   def run_command(self, command, args):
> +      script = os.path.join(self.base_dir, 'piglit-' + command + '.py')
> +      return self.run_python(script, args)
> +
> +   def run_python(self, script, args):
> +      pargs = [ sys.executable, script ]
> +      pargs += args
> +      return subprocess.call(executable=pargs[0], args=pargs)
> +
> +   def command_help(self, command):
> +      return self.run_command(command, ('--help',))
> +
> +   def unknown_command_help(self, command):
> +      print("piglit: '%s' is not a piglit command. See 'piglit --help'." %
> +            command)
> +      return -1
> +
> +   def generic_help(self):
> +      print("usage: piglit <command> [<args>]\n")
> +
> +      print("Commands are:")
> +      for cmd in self.cmds:
> +         print("   " + cmd)
> +
> +      print("\nUse 'piglit help <command>' for subcommand help.")
> +
> +   def get_sub_commands(self):
> +      cmds = os.listdir(self.base_dir)
> +      cmds = filter(lambda p: p.endswith('.py'), cmds)
> +      cmds = map(os.path.basename, cmds)
> +      cmds = filter(lambda p: p.startswith('piglit-'), cmds)
> +      self.cmds = map(lambda p: p[7:-3], cmds)
> +      self.cmds.sort()
> +
> +def run(base_dir, from_source=True):
> +   return piglit_cmd(base_dir, from_source).run()
> +
> +if __name__ == "__main__":
> +    print("Use the 'piglit' command to run piglit")
> +    sys.exit(-1)
> 

I'm not at all happy with this approach.

I would love to see a combined piglit interface, but I'd rather see
something using argparse with subcommands and replacing the existing
piglit scripts with wrappers for that. This is a mess that will be
hard to maintain. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140430/153d927b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140430/153d927b/attachment-0001.sig>


More information about the Piglit mailing list