Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Support python3 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
41 changes: 24 additions & 17 deletions globusonline/transfer/api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

See https://transfer.api.globusonline.org for API documentation.
"""
from __future__ import print_function
import os.path
import os
import sys
Expand All @@ -42,8 +43,14 @@
import urllib
import time
import ssl
from urlparse import urlparse
from httplib import BadStatusLine
try:
from urlparse import urlparse
except:
from urllib.parse import urlparse
try:
from httplib import BadStatusLine
except:
from http.client import BadStatusLine
from datetime import datetime, timedelta

from globusonline.transfer.api_client.verified_https \
Expand Down Expand Up @@ -230,14 +237,14 @@ def _request(self, method, path, body=None, content_type=None):
headers["Content-Type"] = content_type

if self.print_request:
print
print ">>>REQUEST>>>:"
print "%s %s" % (method, url)
print("")
print(">>>REQUEST>>>:")
print("%s %s" % (method, url))
for h in headers.iteritems():
print "%s: %s" % h
print
print("%s: %s" % h)
print("")
if body:
print body
print(body)

if self.goauth:
headers["Authorization"] = "Globus-Goauthtoken %s" % self.goauth
Expand All @@ -253,7 +260,7 @@ def do_request():
response_body = r.read()
return r, response_body

for attempt in xrange(self.max_attempts):
for attempt in range(self.max_attempts):
r = None
try:
try:
Expand Down Expand Up @@ -298,13 +305,13 @@ def do_request():
time.sleep(RETRY_WAIT_SECONDS)

if self.print_response:
print
print "<<<RESPONSE<<<:"
print r.status, r.reason
print("")
print("<<<RESPONSE<<<:")
print(r.status, r.reason)
for h in r.getheaders():
print "%s: %s" % h
print
print response_body
print("%s: %s" % h)
print("")
print(response_body)

return r, response_body

Expand Down Expand Up @@ -875,7 +882,7 @@ def set_submit_type(self, type):
self.req_list = [req for req in self.req_list if req["type"] == type]
# remap
keys = [r["type"] + "." + r["name"] for r in self.req_list]
self.index_map = dict(zip(keys, xrange(len(keys))))
self.index_map = dict(zip(keys, range(len(keys))))

def as_json(self):
return json.dumps(self.json_data)
Expand Down Expand Up @@ -1118,7 +1125,7 @@ def process_args(args=None, parser=None):
parser.error(auth_method_error)
username = args[0]
success = False
for i in xrange(5):
for i in range(5):
try:
result = get_access_token(username=username)
args[0] = result.username
Expand Down
7 changes: 4 additions & 3 deletions globusonline/transfer/api_client/examples/add-endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

For a full list of options, run with -h.
"""
from __future__ import print_function
import sys
import inspect
from optparse import OptionParser
Expand Down Expand Up @@ -81,9 +82,9 @@ def main():
_, _, data = api.endpoint_create(args[1], **kw)
setup_key = data.get("globus_connect_setup_key")
if setup_key:
print "GC Setup Key: %s" % setup_key
print "Endpoint Name: %s" % data["canonical_name"]
print data["message"]
print("GC Setup Key: %s" % setup_key)
print("Endpoint Name: %s" % data["canonical_name"])
print(data["message"])


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions globusonline/transfer/api_client/examples/create_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
transfer_api meant for delegate_proxy activation. This can be useful
for testing.
"""

from __future__ import print_function
import sys

from globusonline.transfer.api_client import create_proxy_from_file

if __name__ == '__main__':
if len(sys.argv) != 4:
print "usage: %s proxy_file pubkey_file lifetime_hours" % sys.argv[0]
print("usage: %s proxy_file pubkey_file lifetime_hours" % sys.argv[0])
sys.exit(1)

proxy_file, pubkey_file = sys.argv[1:3]
Expand All @@ -35,4 +35,4 @@
public_key = f.read()

proxy_pem = create_proxy_from_file(proxy_file, public_key, lifetime)
print proxy_pem
print(proxy_pem)
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
ep = args[0]
cred_file = args[1]

print "Using x509_proxy implementation '%s'" % x509_proxy.implementation
print("Using x509_proxy implementation '%s'" % x509_proxy.implementation)

_, _, reqs = api.endpoint_activation_requirements(ep,
type="delegate_proxy")
Expand All @@ -72,4 +72,4 @@
reqs.set_requirement_value("delegate_proxy", "proxy_chain", proxy)

result = api.endpoint_activate(ep, reqs)
print result
print(result)
97 changes: 49 additions & 48 deletions globusonline/transfer/api_client/examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

python example.py USERNAME -k ~/.globus/userkey.pem -c ~/.globus/usercert.pem
"""
from __future__ import print_function
import time
from datetime import datetime, timedelta

Expand All @@ -38,18 +39,18 @@ def tutorial():
Uses module global API client instance.
"""
# See what is in the account before we make any submissions.
print "=== Before tutorial ==="
display_tasksummary(); print
display_task_list(); print
display_endpoint_list(); print
print("=== Before tutorial ===")
display_tasksummary(); print("")
display_task_list(); print("")
display_endpoint_list(); print("")

# auto activate the endpoint, and display before/after.
display_activation("go#ep1")
display_activation("go#ep2")

print "=== Before transfer ==="
display_ls("go#ep1"); print
display_ls("go#ep2"); print
print("=== Before transfer ===")
display_ls("go#ep1"); print("")
display_ls("go#ep2"); print("")

# submit a transfer
code, message, data = api.transfer_submission_id()
Expand All @@ -61,9 +62,9 @@ def tutorial():
task_id = data["task_id"]

# see the new transfer show up
print "=== After submit ==="
display_tasksummary(); print
display_task(task_id, False); print
print("=== After submit ===")
display_tasksummary(); print("")
display_task(task_id, False); print("")

# wait for the task to complete, and see the tasks and
# endpoint ls change
Expand All @@ -76,36 +77,36 @@ def tutorial():
# endpoints is having problems or the user already has a bunch
# of other active tasks (there is a limit to the
# number of concurrent active tasks a user can have).
print "WARNING: task did not complete before timeout!"
print("WARNING: task did not complete before timeout!")
else:
print "Task %s complete with status %s" % (task_id, status)
print "=== After completion ==="
display_tasksummary(); print
display_task(task_id); print
display_ls("go#ep2"); print
print("Task %s complete with status %s" % (task_id, status))
print("=== After completion ===")
display_tasksummary(); print("")
display_task(task_id); print("")
display_ls("go#ep2"); print("")


def display_activation(endpoint_name):
print "=== Endpoint pre-activation ==="
print("=== Endpoint pre-activation ===")
display_endpoint(endpoint_name)
print
print("")
code, reason, result = api.endpoint_autoactivate(endpoint_name,
if_expires_in=600)
if result["code"].startswith("AutoActivationFailed"):
print "Auto activation failed, ls and transfers will likely fail!"
print "result: %s (%s)" % (result["code"], result["message"])
print "=== Endpoint post-activation ==="
print("Auto activation failed, ls and transfers will likely fail!")
print("result: %s (%s)" % (result["code"], result["message"]))
print("=== Endpoint post-activation ===")
display_endpoint(endpoint_name)
print
print("")


def display_tasksummary():
code, reason, data = api.tasksummary()
print "Task Summary for %s:" % api.username
print("Task Summary for %s:" % api.username)
for k, v in data.iteritems():
if k == "DATA_TYPE":
continue
print "%3d %s" % (int(v), k.upper().ljust(9))
print("%3d %s" % (int(v), k.upper().ljust(9)))


def display_task_list(max_age=None):
Expand All @@ -121,9 +122,9 @@ def display_task_list(max_age=None):
kwargs["request_time"] = "%s," % min_request_time

code, reason, task_list = api.task_list(**kwargs)
print "task_list for %s:" % api.username
print("task_list for %s:" % api.username)
for task in task_list["DATA"]:
print "Task %s:" % task["task_id"]
print("Task %s:" % task["task_id"])
_print_task(task)


Expand All @@ -133,21 +134,21 @@ def _print_task(data, indent_level=0):
for k, v in data.iteritems():
if k in ("DATA_TYPE", "LINKS"):
continue
print indent + "%s: %s" % (k, v)
print(indent + "%s: %s" % (k, v))


def display_task(task_id, show_successful_transfers=True):
code, reason, data = api.task(task_id)
print "Task %s:" % task_id
print("Task %s:" % task_id)
_print_task(data, 0)

if show_successful_transfers:
code, reason, data = api.task_successful_transfers(task_id)
transfer_list = data["DATA"]
print "Successful Transfers (src -> dst)"
print("Successful Transfers (src -> dst)")
for t in transfer_list:
print " %s -> %s" % (t[u'source_path'],
t[u'destination_path'])
print(" %s -> %s" % (t[u'source_path'],
t[u'destination_path']))


def wait_for_task(task_id, timeout=120, poll_interval=30):
Expand Down Expand Up @@ -175,8 +176,8 @@ def wait_for_task(task_id, timeout=120, poll_interval=30):

def display_endpoint_list():
code, reason, endpoint_list = api.endpoint_list(limit=100)
print "Found %d endpoints for user %s:" \
% (endpoint_list["length"], api.username)
print("Found %d endpoints for user %s:" \
% (endpoint_list["length"], api.username))
for ep in endpoint_list["DATA"]:
_print_endpoint(ep)

Expand All @@ -188,30 +189,30 @@ def display_endpoint(endpoint_name):

def _print_endpoint(ep):
name = ep["canonical_name"]
print name
print(name)
if ep["activated"]:
print " activated (expires: %s)" % ep["expire_time"]
print(" activated (expires: %s)" % ep["expire_time"])
else:
print " not activated"
print(" not activated")
if ep["public"]:
print " public"
print(" public")
else:
print " not public"
print(" not public")
if ep["myproxy_server"]:
print " default myproxy server: %s" % ep["myproxy_server"]
print(" default myproxy server: %s" % ep["myproxy_server"])
else:
print " no default myproxy server"
print(" no default myproxy server")
servers = ep.get("DATA", ())
print " servers:"
print(" servers:")
for s in servers:
uri = s["uri"]
if not uri:
uri = "GC endpoint, no uri available"
print " " + uri,
print(" " + uri,)
if s["subject"]:
print " (%s)" % s["subject"]
print(" (%s)" % s["subject"])
else:
print
print("")


def display_ls(endpoint_name, path=""):
Expand All @@ -222,13 +223,13 @@ def display_ls(endpoint_name, path=""):
# and will be mapped to the user's default directory (typically
# their home directory) by the Transfer API.
path = data["path"]
print "Contents of %s on %s:" % (path, endpoint_name)
print("Contents of %s on %s:" % (path, endpoint_name))
headers = "name, type, permissions, size, user, group, last_modified"
headers_list = headers.split(", ")
print headers
print(headers)
for file_or_dir in data["DATA"]:
print ", ".join([unicode(file_or_dir[field])
for field in headers_list])
print(", ".join([unicode(file_or_dir[field])
for field in headers_list]))


if __name__ == '__main__':
Expand Down
14 changes: 7 additions & 7 deletions globusonline/transfer/api_client/examples/myproxy_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
The endpoint name may contain a # which is a shell comment, so be sure to
quote the endpoint name.
"""

from __future__ import print_function
import sys
from getpass import getpass

Expand All @@ -47,8 +47,8 @@ def input_default(field_name, default, private=False):
if default:
value = default
else:
print "Error: %s is required, please enter a value" \
% field_name
print("Error: %s is required, please enter a value" \
% field_name)
return value


Expand Down Expand Up @@ -79,8 +79,8 @@ def prompt_requirement(reqs, req_name, private=False):

try:
_, _, result = api.endpoint_activate(ep, reqs)
print "Activation successful"
print "Subject:", result["subject"]
print "Expires:", result["expire_time"]
print("Activation successful")
print("Subject:", result["subject"])
print("Expires:", result["expire_time"])
except APIError as e:
print "Error: %s" % e.message
print("Error: %s" % e.message)
Loading