Skip to content

Commit a2cfd8c

Browse files
authored
Merge pull request #209 from wltrimbl/master
Fix argument-parsing bug, fix unicode encoding bug
2 parents ed61176 + fcc0fae commit a2cfd8c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mglib/mglib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def body_from_url(url, accept, auth=None, data=None, debug=False, method=None):
7272

7373
# return python struct from JSON output of MG-RAST or Shock API
7474
def obj_from_url(url, auth=None, data=None, debug=False, method=None):
75+
if type(data) is str:
76+
data=data.encode("utf8")
7577
try:
7678
result = body_from_url(url, 'application/json', auth=auth, data=data, debug=debug, method=method)
7779
read = result.read()
@@ -100,7 +102,7 @@ def obj_from_url(url, auth=None, data=None, debug=False, method=None):
100102
sys.stderr.write("ERROR: %s\n" %obj['ERROR'])
101103
sys.exit(1)
102104
if ('error' in obj) and obj['error']:
103-
if isinstance(obj['error'], basestring):
105+
if isinstance(obj['error'], str):
104106
sys.stderr.write("ERROR:\n%s\n" %obj['error'])
105107
else:
106108
sys.stderr.write("ERROR: %s\n" %obj['error'][0])

scripts/mg-submit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def main(args):
460460
parser.add_argument("--tmp_dir", dest="tmp_dir", default="", help="Temp dir to download too if using json_in option, default is current working dir")
461461
parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose STDOUT")
462462
parser.add_argument("--debug", dest="debug", action="store_true", default=False, help="Submit in debug mode")
463-
parser.add_argument("action", type=str, default=False, help="Action. One of "+ ",".join(valid_actions))
463+
parser.add_argument("action", type=str, default=False, help="Action. One of "+ ",".join(valid_actions), nargs='+')
464464
# parser.add_argument("subaction", type=str, default=False, help="Action word 2", default=None)
465465

466466
# get inputs
@@ -474,7 +474,7 @@ def main(args):
474474
if len(opts.action) < 1:
475475
sys.stderr.write("ERROR: missing action\n")
476476
return 1
477-
action = opts.action
477+
action = opts.action[0]
478478
args = opts.action
479479
API_URL = opts.mgrast_url
480480
SHOCK_URL = opts.shock_url
@@ -494,9 +494,9 @@ def main(args):
494494
sys.stderr.write("ERROR: invalid submit, must have one of project_id, project_name, or metadata\n")
495495
return 1
496496
if (len(args) < 2) or (args[1] not in submit_types):
497-
sys.stderr.write("ERROR: invalid submit option. use one of: %s\n"%", ".join(submit_types))
497+
sys.stderr.write("ERROR: invalid submit option '%s'. use one of: %s\n"%( args[1], ", ".join(submit_types)))
498498
return 1
499-
if ((args[1] == "simple") and (len(args) < 3) or
499+
if ( ((args[1] == "simple") and (len(args) < 3)) or
500500
((args[1] == "batch") and (len(args) != 3)) or
501501
((args[1] == "demultiplex") and (len(args) < 3)) or
502502
((args[1] == "pairjoin") and (len(args) != 4)) or

0 commit comments

Comments
 (0)