From 9a9fc9e2dbbaf691bdb0fa64c56a45112f419c76 Mon Sep 17 00:00:00 2001 From: Stephen Fox Date: Sat, 15 Sep 2018 14:59:48 -0500 Subject: [PATCH] Add compatibility for Python3 --- bin/jarvice_cli | 24 +++++++++++++++--------- jarviceclient/JarviceAPI.py | 5 +++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/bin/jarvice_cli b/bin/jarvice_cli index d2a05e8..c068ddc 100755 --- a/bin/jarvice_cli +++ b/bin/jarvice_cli @@ -30,12 +30,18 @@ # # Author: Stephen Fox (stephen.fox@nimbix.net) +from __future__ import print_function import argparse import sys import pprint import os import time -import ConfigParser +try: + # Python2 + import ConfigParser +except ModuleNotFoundError: + # Python3 + from configparser import ConfigParser import simplejson as json from collections import OrderedDict @@ -127,7 +133,7 @@ def cli_ls(parser): args = subparser.parse_args() result = utils.ls(config['username'], config['apikey'], args.directory) for i in result: - print i + print(i) def cli_download(parser): @@ -257,11 +263,11 @@ def _call_jarvice_api(parser, command, method, *args, **kwargs): if args.command not in ['jobs', 'submit', 'shutdown_all', 'terminate_all', 'apps', 'machines']: if not args.name and not args.number: - print "Argument Error: -name or -number is required" + print("Argument Error: -name or -number is required") subparser.print_help() sys.exit(1) elif args.name and args.number: - print "Argument Error: Only one of -name and -number can be input" + print("Argument Error: Only one of -name and -number can be input") subparser.print_help() sys.exit(1) @@ -289,11 +295,11 @@ def cli_wait_for(parser): args = subparser.parse_args() if not args.name and not args.number: - print "Argument Error: -name or -number is required" + print("Argument Error: -name or -number is required") subparser.print_help() sys.exit(1) elif args.name and args.number: - print "Argument Error: Only one of -name and -number can be input" + print("Argument Error: Only one of -name and -number can be input") subparser.print_help() sys.exit(1) @@ -326,7 +332,7 @@ def cli_jarvice(args, api_args, parser): if errors: print_output(errors) if command in ['tail', 'output']: - print result + print(result) else: print_output(result) elif command == 'download': @@ -348,12 +354,12 @@ def cli_jarvice(args, api_args, parser): elif command == 'wait_for': cli_wait_for(parser) else: - print 'Cannot find command %s' % command + print('Cannot find command %s' % command) def print_output(result): if isinstance(result, dict) or isinstance(result, list): - print json.dumps(result, indent=4) + print(json.dumps(result, indent=4)) else: pprint.pprint(result, indent=4) diff --git a/jarviceclient/JarviceAPI.py b/jarviceclient/JarviceAPI.py index 1943ebb..a19b42c 100644 --- a/jarviceclient/JarviceAPI.py +++ b/jarviceclient/JarviceAPI.py @@ -30,6 +30,7 @@ # # Author: Stephen Fox (stephen.fox@nimbix.net) +from __future__ import print_function import requests import json import logging @@ -362,5 +363,5 @@ def shutdown_all(self, *args, **kwargs): if __name__ == '__main__': - print "Jarvice API Python Client for running on-demand HPC work flows." - print "This client calls https://api.jarvice.com" + print("Jarvice API Python Client for running on-demand HPC work flows.") + print("This client calls https://api.jarvice.com")