[Piglit] [PATCH 4/4] piglit-summary-junit.py: Convert optparse to argparse

Kenneth Graunke kenneth at whitecape.org
Sun Apr 21 14:19:07 PDT 2013


On 04/19/2013 09:16 PM, Dylan Baker wrote:
> Optparse has been deprecated in favor of argparse upstream (PEP 389
> http://www.python.org/dev/peps/pep-0389/), and since we are using
> argparse already in the other modules, it makes sense to replace
> optparse and use only one parsing method in all piglit.
>
> Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
> ---
>   piglit-summary-junit.py | 31 ++++++++++++++-----------------
>   1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/piglit-summary-junit.py b/piglit-summary-junit.py
> index 6520888..5b29c7e 100755
> --- a/piglit-summary-junit.py
> +++ b/piglit-summary-junit.py
> @@ -24,7 +24,7 @@
>   # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
>
>
> -import optparse
> +import argparse
>   import os
>   import sys
>
> @@ -109,25 +109,22 @@ class Writer:
>
>
>   def main():
> -	optparser = optparse.OptionParser(
> -		usage="\n\t%prog [options] test.results",
> -		version="%%prog")
> -	optparser.add_option(
> -		'-o', '--output', metavar='FILE',
> -		type="string", dest="output", default='piglit.xml',
> -		help="output filename")
> -	(options, args) = optparser.parse_args(sys.argv[1:])
> +	parser = argparse.ArgumentParser()
> +	parser.add_argument("-o", "--output",
> +						metavar = "<Output File>",
> +						action  = "store",
> +						dest    = "output",
> +						default = "piglit.xml",
> +						help    = "Output filename")
> +	parser.add_argument("testResults",
> +						metavar = "<Input Files>",
> +						help    = "JSON results file to be converted")
> +	args = parser.parse_args()
>
> -	if len(args) != 1:
> -		optparser.error('need to specify one test result')
> -		usage()
>
> -	writer = Writer(options.output)
> -	writer.write(args[0])
> +	writer = Writer(args.output)
> +	writer.write(args.testResults)
>
>
>   if __name__ == "__main__":
>   	main()
> -
> -
> -# vim:set sw=4 ts=4 noet:

This last bit is unrelated.


More information about the Piglit mailing list