Commit f409df5e authored by Tanner Prestegard's avatar Tanner Prestegard

Adding Python 3.4+ compatibility to CLI

parent 2661890a
......@@ -42,13 +42,13 @@ def output(*message):
def defaultAccess(e,a):
if a.find('.') < 0:
return str(e.get(a,""))
return repr(e.get(a,""))
rv = e
attrs = a.split('.')
while attrs and rv:
rv = rv.get(attrs[0],"")
attrs = attrs[1:]
return str(rv)
return repr(rv)
#-----------------------------------------------------------------
# HTTP upload encoding
......@@ -99,6 +99,9 @@ def derive_client(ClientBase=GraceDb):
if not hasattr(destfile, 'read'):
if destfile == '-':
destfile = sys.stdout
# Python 2/3 compatibility
if hasattr(destfile, 'buffer'):
destfile = destfile.buffer
else:
destfile = open(destfile, "wb")
shutil.copyfileobj(response, destfile)
......@@ -399,7 +402,7 @@ Longer strings will be truncated.""" % {
tagDispName = args[4]
graceid = args[1]
logN = args[2]
response = client.createTag(graceid, logN, tagName, tagDispName)
response = client.addTag(graceid, logN, tagName, tagDispName)
elif args[0] == 'delete_tag':
error("len args = %s" % len(args))
error("args = %s" % args)
......@@ -413,7 +416,7 @@ Longer strings will be truncated.""" % {
tagName = args[3]
graceid = args[1]
logN = args[2]
response = client.deleteTag(graceid, logN, tagName)
response = client.removeTag(graceid, logN, tagName)
elif args[0] == 'label':
if len(args) != 3:
op.error("wrong number of arguments for label")
......@@ -449,7 +452,7 @@ Longer strings will be truncated.""" % {
else:
accessFun = {
"labels" : lambda e: \
",".join(list(e['labels'].keys())),
",".join(list(e['labels'])),
"dataurl" : lambda e: e['links']['files'],
}
......@@ -513,7 +516,7 @@ Longer strings will be truncated.""" % {
except:
rv = response
try:
rv = json.loads(rv)
rv = json.loads(rv.decode())
except:
pass
......@@ -538,9 +541,9 @@ Longer strings will be truncated.""" % {
rv = response
try:
responseBody = json.loads(rv)
responseBody = json.loads(rv.decode())
except:
responseBody = rv
responseBody = rv.decode()
if status >= 400:
exitCode=1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment