util: Replace optparse with argparse
JIRA: https://gem5.atlassian.net/browse/GEM5-543 Change-Id: Id270ed29f14199f4f8eb6eb5739451a43d100484 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44512 Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -260,26 +260,31 @@ def process_file(path, **kwargs):
|
||||
cpt.write(open(path, 'w'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
from optparse import OptionParser, SUPPRESS_HELP
|
||||
parser = OptionParser("usage: %prog [options] <filename or directory>")
|
||||
parser.add_option("-r", "--recurse", action="store_true",
|
||||
help="Recurse through all subdirectories modifying "\
|
||||
"each checkpoint that is found")
|
||||
parser.add_option("-N", "--no-backup", action="store_false",
|
||||
dest="backup", default=True,
|
||||
help="Do no backup each checkpoint before modifying it")
|
||||
parser.add_option("-v", "--verbose", action="store_true",
|
||||
help="Print out debugging information as")
|
||||
parser.add_option("--get-cc-file", action="store_true",
|
||||
# used during build; generate src/sim/tags.cc and exit
|
||||
help=SUPPRESS_HELP)
|
||||
from argparse import ArgumentParser, SUPPRESS
|
||||
parser = ArgumentParser(usage="%(prog)s [args] <filename or directory>")
|
||||
parser.add_argument(
|
||||
"-r", "--recurse", action="store_true",
|
||||
help="Recurse through all subdirectories modifying "\
|
||||
"each checkpoint that is found")
|
||||
parser.add_argument(
|
||||
"-N", "--no-backup", action="store_false",
|
||||
dest="backup", default=True,
|
||||
help="Do no backup each checkpoint before modifying it")
|
||||
parser.add_argument(
|
||||
"-v", "--verbose", action="store_true",
|
||||
help="Print out debugging information as")
|
||||
parser.add_argument(
|
||||
"--get-cc-file", action="store_true",
|
||||
# used during build; generate src/sim/tags.cc and exit
|
||||
help=SUPPRESS)
|
||||
parser.add_argument("checkpoint", nargs='?')
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
verbose_print = options.verbose
|
||||
args = parser.parse_args()
|
||||
verbose_print = args.verbose
|
||||
|
||||
Upgrader.load_all()
|
||||
|
||||
if options.get_cc_file:
|
||||
if args.get_cc_file:
|
||||
print("// this file is auto-generated by util/cpt_upgrader.py")
|
||||
print("#include <string>")
|
||||
print("#include <set>")
|
||||
@@ -289,30 +294,30 @@ if __name__ == '__main__':
|
||||
print(" \"{}\",".format(tag))
|
||||
print("};")
|
||||
exit(0)
|
||||
elif len(args) != 1:
|
||||
parser.error("You must specify a checkpoint file to modify or a "\
|
||||
elif not args.checkpoint:
|
||||
parser.error("You must specify a checkpoint file to modify or a "
|
||||
"directory of checkpoints to recursively update")
|
||||
|
||||
# Deal with shell variables and ~
|
||||
path = osp.expandvars(osp.expanduser(args[0]))
|
||||
path = osp.expandvars(osp.expanduser(args.checkpoint))
|
||||
|
||||
# Process a single file if we have it
|
||||
if osp.isfile(path):
|
||||
process_file(path, **vars(options))
|
||||
process_file(path, **vars(args))
|
||||
# Process an entire directory
|
||||
elif osp.isdir(path):
|
||||
cpt_file = osp.join(path, 'm5.cpt')
|
||||
if options.recurse:
|
||||
if args.recurse:
|
||||
# Visit very file and see if it matches
|
||||
for root,dirs,files in os.walk(path):
|
||||
for name in files:
|
||||
if name == 'm5.cpt':
|
||||
process_file(osp.join(root,name), **vars(options))
|
||||
process_file(osp.join(root,name), **vars(args))
|
||||
for dir in dirs:
|
||||
pass
|
||||
# Maybe someone passed a cpt.XXXXXXX directory and not m5.cpt
|
||||
elif osp.isfile(cpt_file):
|
||||
process_file(cpt_file, **vars(options))
|
||||
process_file(cpt_file, **vars(args))
|
||||
else:
|
||||
print("Error: checkpoint file not found in {} ".format(path))
|
||||
print("and recurse not specified")
|
||||
|
||||
Reference in New Issue
Block a user