dist/common/scripts: pass format variables to colorprint()

When we use str.format() to pass variables on the message it will always
causes Exception like "KeyError: 'red'", since the message contains color
variables but it's not passed to str.format().
To avoid the error we need to pass all format variables to colorprint()
and run str.format() inside the function.

Fixes #3649

Signed-off-by: Takuya ASADA <syuu@scylladb.com>
Message-Id: <20180803015216.14328-1-syuu@scylladb.com>
This commit is contained in:
Takuya ASADA
2018-08-03 10:52:16 +09:00
committed by Avi Kivity
parent d6b0c4dda4
commit ad7bc313f7
3 changed files with 6 additions and 4 deletions

View File

@@ -43,7 +43,7 @@ if __name__ == '__main__':
driver = match.group(1)
if not en:
colorprint('{red}{instance_class} doesn\'t support enahanced networking!{nocolor}'.format(instance_class))
colorprint('{red}{instance_class} doesn\'t support enahanced networking!{nocolor}', instance_class=instance_class)
print('''To enable enhanced networking, please use the instance type which supports it.
More documentation available at:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking''')

View File

@@ -102,7 +102,7 @@ def run_setup_script(name, script):
res = run(script, exception=False)
if res != 0:
if interactive:
colorprint('{red}{name} setup failed. Press any key to continue...{nocolor}'.format(name=name))
colorprint('{red}{name} setup failed. Press any key to continue...{nocolor}', name=name)
input()
else:
print('{} setup failed.'.format(name))

View File

@@ -350,8 +350,10 @@ def is_unused_disk(dev):
return False
CONCOLORS = {'green':'\033[1;32m', 'red':'\033[1;31m', 'nocolor':'\033[0m'}
def colorprint(msg):
print(msg.format(**CONCOLORS))
def colorprint(msg, **kwargs):
fmt = dict(CONCOLORS)
fmt.update(kwargs)
print(msg.format(**fmt))
def get_mode_cpuset(nic, mode):
try: