Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for Python3 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions bin/jarvice_cli
Original file line number Diff line number Diff line change
@@ -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)

5 changes: 3 additions & 2 deletions jarviceclient/JarviceAPI.py
Original file line number Diff line number Diff line change
@@ -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")