Skip to content

Commit

Permalink
Updated jsoncli and rmtscript.py to python3 (#41)
Browse files Browse the repository at this point in the history
Added a version independent input method to support python 2 and 3
  • Loading branch information
MidgetAteMyMom authored and stewilliams-extr committed Jul 25, 2018
1 parent 4170212 commit ac806d6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
38 changes: 23 additions & 15 deletions EXOS/Python/jsoncli/jsoncli.py
Expand Up @@ -100,7 +100,10 @@

import argparse
import json
import readline
import sys
# import readline
# readline is never used but imported. readline is a linux-library and prevents this script from running on a windows machine.


#
# This class contains the specifics of constructing a JSONRPC message and
Expand Down Expand Up @@ -188,17 +191,22 @@ def get_params():
args = parser.parse_args()
return args


def version_independent_input( str ):
# This Script needs to keep support for Python 2 so this function will allways use the right input method
if sys.version_info[0] == 2 :
return raw_input(str)
else:
return input(str)

def main():
import getpass
args = get_params()
if args.ipaddress is None:
# prompt for ip address of the remote system
args.ipaddress = raw_input('Enter remote system IP address: ')

args.ipaddress = version_independent_input('Enter remote system IP address: ')
if args.username is None:
# prompt for username
args.username = raw_input('Enter remote system username: ')
args.username = version_independent_input('Enter remote system username: ')
# also get password
args.password = getpass.getpass('Remote system password: ')

Expand All @@ -208,7 +216,7 @@ def main():
# start a CLI prompt loop for the user to enter EXOS commands
while True:
# prompt the user for an EXOS command
cmd = raw_input('Enter EXOS cli: ')
cmd = version_independent_input('Enter EXOS cli: ')
if cmd in ['q','quit','exit']:
break

Expand All @@ -217,9 +225,9 @@ def main():
response = jsonrpc.send(cmd)

# print headers
print 'JSONRPC Response for:', cmd
print '*' * 80
print json.dumps(response, indent=2, sort_keys=True)
print ('JSONRPC Response for:', cmd)
print ('*' * 80)
print (json.dumps(response, indent=2, sort_keys=True))

# dump the JSONRPC response to the user in a pretty format
# first the data stuctures
Expand All @@ -230,16 +238,16 @@ def main():
if result is not None:
cli_output = result[0].get('CLIoutput')
if cli_output is not None:
print '\nFormatted CLIoutput Display'
print '*' * 80
print cli_output
print '*' * 80
print ('\nFormatted CLIoutput Display')
print ('*' * 80)
print (cli_output)
print ('*' * 80)
except:
pass
except Exception as msg:
print msg
print (msg)

try:
main()
except KeyboardInterrupt:
pass
pass
24 changes: 16 additions & 8 deletions EXOS/Python/rmtscript/rmtscript.py
Expand Up @@ -58,10 +58,12 @@
import json
import requests
import getpass
try:
import readline
except:
pass
import sys
# Readline is never used.
# try:
# import readline
# except:
# pass

#
# This class contains the specifics of constructing a JSONRPC message and
Expand Down Expand Up @@ -149,16 +151,22 @@ def get_params():
args = parser.parse_args()
return args

def version_independent_input( str ):
# This Script needs to keep support for Python 2 so this function will allways use the right input method
if sys.version_info[0] == 2 :
return raw_input(str)
else:
return input(str)

def main():
args = get_params()
if args.ipaddress is None:
# prompt for ip address of the remote system
args.ipaddress = raw_input('Enter remote system IP address: ')
args.ipaddress = version_independent_input('Enter remote system IP address: ')

if args.username is None:
# prompt for username
args.username = raw_input('Enter remote system username: ')
args.username = version_independent_input('Enter remote system username: ')
# also get password
args.password = getpass.getpass('Remote system password: ')

Expand All @@ -167,7 +175,7 @@ def main():

while True:
# prompt the user for an EXOS command
cmd = raw_input('run script <file> [args]: ')
cmd = version_independent_input('run script <file> [args]: ')
if cmd in ['q','quit','exit']:
break

Expand Down Expand Up @@ -212,4 +220,4 @@ def main():
try:
main()
except KeyboardInterrupt:
pass
pass

0 comments on commit ac806d6

Please sign in to comment.