From 154f3814077bdfe9b89dde00744c03180fa2bf2f Mon Sep 17 00:00:00 2001 From: rajendra-dendukuri <47423477+rajendra-dendukuri@users.noreply.github.com> Date: Wed, 15 Apr 2020 16:29:07 -0400 Subject: [PATCH] Fix sonic-db-cli script to be compatible with python3 and python2.7 (#66) * Fix sonic-db-cli script to be compatible with python3 and python2.7 * Review comments * Removed space between function name and parentheses --- src/swsssdk/scripts/sonic-db-cli | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/swsssdk/scripts/sonic-db-cli b/src/swsssdk/scripts/sonic-db-cli index 50e03afbff54..fa04a8eb9a77 100755 --- a/src/swsssdk/scripts/sonic-db-cli +++ b/src/swsssdk/scripts/sonic-db-cli @@ -1,4 +1,5 @@ #!/usr/bin/python +from __future__ import print_function import sys import swsssdk import redis @@ -28,10 +29,10 @@ def ping_all_instances(): if rsp != 'PONG': msg.append(rsp) if msg: - print '\n'.join(msg) + print('\n'.join(msg)) sys.exit(1) else: - print 'PONG' + print('PONG') sys.exit(0) def execute_cmd(dbname, cmd): @@ -40,7 +41,7 @@ def execute_cmd(dbname, cmd): dbconn.connect(dbname) except RuntimeError: msg = "Invalid database name input : '{}'".format(dbname) - print >> sys.stderr, msg + print(msg, file=sys.stderr) sys.exit(1) else: client = dbconn.get_redis_client(dbname) @@ -51,11 +52,11 @@ def execute_cmd(dbname, cmd): with these changes, it is enough for us to mimic redis-cli in SONiC so far since no application uses tty mode redis-cli output """ if resp is None: - print "" + print() elif isinstance(resp, list): - print "\n".join(resp) + print("\n".join(resp)) else: - print resp + print(resp) sys.exit(0) def main():