Skip to content

Commit

Permalink
WIP on subcommand argparse. W00t
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtaylor committed Jun 9, 2015
1 parent 4a24f11 commit 2bbecfd
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/scripts/agora.py
Expand Up @@ -45,7 +45,7 @@ def get_documentation(docsFile):
print docsFile
return read_entire_file(docsFile)
else:
return "FOOBAR"
return ""



Expand Down Expand Up @@ -84,14 +84,14 @@ def get_user_synopsis():
# Posts the method to agora /methods endpoint. Fails on non-200 responses.
def method_post(namespace, name, synopsis, documentation, payload, agoraUrl):
requestUrl = "/methods"
addRequest = {"namespace": namespace, "name": name, "synopsis": synopsis, "documentation": documentation, "payload": payload}
addRequest = {"namespace": namespace, "name": name, "synopsis": synopsis, "documentation": documentation, "entityType": "Workflow","payload": payload}
requestBody = json.dumps(addRequest)
conn = httplib.HTTPSConnection(agoraUrl)
headers = {'Cookie': auth, 'Content-type': "application/json"}
conn.request("POST", requestUrl, requestBody, headers=headers)
r1 = conn.getresponse()
data = r1.read()
if r1.status != 200:
if r1.status != 201:
print "ERROR! Unable to POST method ", namespace, "/", name
print "Request:"
print addRequest
Expand All @@ -103,6 +103,11 @@ def method_post(namespace, name, synopsis, documentation, payload, agoraUrl):

# Given program arguments, including a payload WDL file, pushes a method to agora
def push_method(namespace, name, docsFile, payloadFile, agoraUrl):
if not namespace:
namespace = getpass.getuser()
if not name:
base = os.path.basename(payloadFile)
name = os.path.splitext(base)[0]
payload = read_entire_file(payloadFile)
synopsis = get_user_synopsis()
documentation = get_documentation(docsFile)
Expand All @@ -112,10 +117,22 @@ def push_method(namespace, name, docsFile, payloadFile, agoraUrl):
if __name__ == "__main__":
parser = ArgumentParser(description="CLI for accessing the AGORA methods store. Currently only handles method add")
parser.add_argument('-a', '--auth', dest='auth', action='store', help='Oath token key=value pair for passing in request cookies')
parser.add_argument('-s', '--namespace', dest='namespace', action='store', help='The namespace for method addition. Default value is your user login name')
parser.add_argument('-n', '--name', dest='name', action='store', help='The method name to provide for method addition. Default is the name of the PAYLOAD_FILE file.')
parser.add_argument('-d', '--documentation', dest='docs', action='store', help='A file containing user documentation. Must be <10kb. May be plain text. Marking languages such as HTML or Github markdown are also supported')
parser.add_argument('PAYLOAD_FILE', help='A file containing the method description in WDL format')
subparsers = parser.add_subparsers(help='Agora Methods Repository actions', dest='actions')

push_parser = subparsers.add_parser('push', description='Push a method to the Agora Methods Repository', help='Push a method to the Agora Methods Repository')
push_parser.add_argument('-s', '--namespace', dest='namespace', action='store', help='The namespace for method addition. Default value is your user login name')
push_parser.add_argument('-n', '--name', dest='name', action='store', help='The method name to provide for method addition. Default is the name of the PAYLOAD_FILE file.')
push_parser.add_argument('-d', '--documentation', dest='docs', action='store', help='A file containing user documentation. Must be <10kb. May be plain text. Marking languages such as HTML or Github markdown are also supported')
push_parser.add_argument('PAYLOAD_FILE', help='A file containing the method description in WDL format')

pull_parser = subparsers.add_parser('pull', description='Get a specific method snapshot from the Agora Methods Repository', help='Get a specific method snapshot from the Agora Methods Repository')
# TODO

search_parser = subparsers.add_parser('search', description='List methods in the Agora Methods Repository based on metadata', help='List methods in the Agora Methods Repository based on metadata')
# TODO



args = parser.parse_args()

agoraUrl="agora-ci.broadinstitute.org"
Expand All @@ -130,14 +147,10 @@ def push_method(namespace, name, docsFile, payloadFile, agoraUrl):
payloadFile = args.PAYLOAD_FILE

# Provide defaults arguments if necessary
if not args.namespace:
namespace = getpass.getuser()
if not name:
base = os.path.basename(payloadFile)
name = os.path.splitext(base)[0]


# Perform the actual method upload
push_method(namespace, name, docsFile, payloadFile, agoraUrl)
print push_method(namespace, name, docsFile, payloadFile, agoraUrl)



Expand Down

0 comments on commit 2bbecfd

Please sign in to comment.