-#!/usr/bin/env python2.7
+#!/usr/bin/env python
-# Copyright (c) 2012-2013,2015-2016 ARM Limited
+# Copyright (c) 2012-2013,2015-2016, 2020 ARM Limited
# All rights reserved
#
# The license below extends only to copyright in the software and shall
# upgrader. This can be especially valuable when maintaining private
# upgraders in private branches.
+from __future__ import print_function
-import ConfigParser
+from six.moves import configparser
import glob, types, sys, os
import os.path as osp
if not verbose_print:
return
for arg in args:
- print arg,
- print
+ print(arg, end=' ')
+ print("\n")
class Upgrader:
tag_set = set()
legacy = {}
def __init__(self, filename):
self.filename = filename
- execfile(filename, {}, self.__dict__)
+ exec(open(filename).read(), {}, self.__dict__)
if not hasattr(self, 'tag'):
self.tag = osp.basename(filename)[:-3]
self.depends = [self.depends]
if not isinstance(self.depends, list):
- print "Error: 'depends' for %s is the wrong type" % self.tag
+ print("Error: 'depends' for {} is the wrong type".format(self.tag))
sys.exit(1)
if hasattr(self, 'fwd_depends'):
self.fwd_depends = []
if not isinstance(self.fwd_depends, list):
- print "Error: 'fwd_depends' for %s is the wrong type" % self.tag
+ print("Error: 'fwd_depends' for {} is the wrong type".format(
+ self.tag))
sys.exit(1)
if hasattr(self, 'upgrader'):
if not isinstance(self.upgrader, types.FunctionType):
- print "Error: 'upgrader' for %s is %s, not function" \
- % (self.tag, type(self))
+ print("Error: 'upgrader' for {} is {}, not function".format(
+ self.tag, type(self)))
sys.exit(1)
Upgrader.tag_set.add(self.tag)
elif hasattr(self, 'downgrader'):
if not isinstance(self.downgrader, types.FunctionType):
- print "Error: 'downgrader' for %s is %s, not function" \
- % (self.tag, type(self))
+ print("Error: 'downgrader' for {} is {}, not function".format(
+ self.tag, type(self)))
sys.exit(1)
Upgrader.untag_set.add(self.tag)
else:
- print "Error: no upgrader or downgrader method for", self.tag
+ print("Error: no upgrader or downgrader method for".format(
+ self.tag))
sys.exit(1)
if hasattr(self, 'legacy_version'):
for tag, upg in Upgrader.by_tag.items():
for fd in upg.fwd_depends:
if fd not in Upgrader.by_tag:
- print "Error: '%s' cannot (forward) depend on "\
- "nonexistent tag '%s'" % (fd, tag)
+ print("Error: '{}' cannot (forward) depend on "
+ "nonexistent tag '{}'".format(fd, tag))
sys.exit(1)
Upgrader.by_tag[fd].depends.append(tag)
for dep in upg.depends:
if dep not in Upgrader.by_tag:
- print "Error: '%s' cannot depend on "\
- "nonexistent tag '%s'" % (tag, dep)
+ print("Error: '{}' cannot depend on "
+ "nonexistent tag '{}'".format(tag, dep))
sys.exit(1)
def process_file(path, **kwargs):
import shutil
shutil.copyfile(path, path + '.bak')
- cpt = ConfigParser.SafeConfigParser()
+ cpt = configparser.SafeConfigParser()
# gem5 is case sensitive with paramaters
cpt.optionxform = str
elif cpt.has_option('Globals','version_tags'):
tags = set((''.join(cpt.get('Globals','version_tags'))).split())
else:
- print "fatal: no version information in checkpoint"
+ print("fatal: no version information in checkpoint")
exit(1)
verboseprint("has tags", ' '.join(tags))
# simulator support for its changes.
unknown_tags = tags - (Upgrader.tag_set | Upgrader.untag_set)
if unknown_tags:
- print "warning: upgrade script does not recognize the following "\
- "tags in this checkpoint:", ' '.join(unknown_tags)
+ print("warning: upgrade script does not recognize the following "
+ "tags in this checkpoint:", ' '.join(unknown_tags))
# Apply migrations for tags not in checkpoint and tags present for which
# downgraders are present, respecting dependences
while to_apply:
ready = set([ t for t in to_apply if Upgrader.get(t).ready(tags) ])
if not ready:
- print "could not apply these upgrades:", ' '.join(to_apply)
- print "update dependences impossible to resolve; aborting"
+ print("could not apply these upgrades:", ' '.join(to_apply))
+ print("update dependences impossible to resolve; aborting")
exit(1)
for tag in ready:
Upgrader.load_all()
if options.get_cc_file:
- print "// this file is auto-generated by util/cpt_upgrader.py"
- print "#include <string>"
- print "#include <set>"
+ print("// this file is auto-generated by util/cpt_upgrader.py")
+ print("#include <string>")
+ print("#include <set>")
print
- print "std::set<std::string> version_tags = {"
+ print("std::set<std::string> version_tags = {")
for tag in Upgrader.tag_set:
- print " \"%s\"," % tag
- print "};"
+ print(" \"{}\",".format(tag))
+ print("};")
exit(0)
elif len(args) != 1:
parser.error("You must specify a checkpoint file to modify or a "\
elif osp.isfile(cpt_file):
process_file(cpt_file, **vars(options))
else:
- print "Error: checkpoint file not found at in %s " % path,
- print "and recurse not specified"
+ print("Error: checkpoint file not found in {} ".format(path))
+ print("and recurse not specified")
sys.exit(1)
sys.exit(0)