configs, tests: Replace optparse with argparse

JIRA: https://gem5.atlassian.net/browse/GEM5-543

Change-Id: I997d6a4e45319a74e21bd0d61d4af6118474c849
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44513
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Giacomo Travaglini
2021-04-16 17:42:34 +01:00
parent 09b9512acd
commit a2c9213a31
43 changed files with 1940 additions and 1953 deletions

View File

@@ -27,7 +27,7 @@
""" Options wrapper for simple gem5 configuration scripts
This module wraps the optparse class so that we can register options
This module wraps the argparse class so that we can register options
from each class instead of only from the configuration script.
"""
@@ -38,24 +38,20 @@ called_parse_args = False
# For fatal
import m5
# import the options parser
from optparse import OptionParser
# import the argument parser
from argparse import ArgumentParser
# add the options we want to be able to control from the command line
parser = OptionParser()
# add the args we want to be able to control from the command line
parser = ArgumentParser()
def add_option(*args, **kwargs):
"""Call "add_option" to the global options parser
"""
if (parser.has_option(args[0]) or
(len(args) > 1 and parser.has_option(args[1])) ):
m5.fatal("Duplicate option: %s" % str(args))
if called_parse_args:
m5.fatal("Can't add an option after calling SimpleOpts.parse_args")
parser.add_option(*args, **kwargs)
parser.add_argument(*args, **kwargs)
def parse_args():
global called_parse_args
@@ -63,9 +59,6 @@ def parse_args():
return parser.parse_args()
def set_usage(*args, **kwargs):
parser.set_usage(*args, **kwargs)
def print_help(*args, **kwargs):
parser.print_help(*args, **kwargs)