Skip to content

Commit

Permalink
Fix sonic-db-cli script to be compatible with python3 and python2.7 (s…
Browse files Browse the repository at this point in the history
…onic-net#66)

* Fix sonic-db-cli script to be compatible with python3 and python2.7
* Review comments
* Removed space between function name and parentheses
  • Loading branch information
rajendra-dendukuri authored Apr 15, 2020
1 parent d1a1512 commit 154f381
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/swsssdk/scripts/sonic-db-cli
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
from __future__ import print_function
import sys
import swsssdk
import redis
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit 154f381

Please sign in to comment.