MCPcopy Index your code
hub / github.com/algorithmiaio/algorithmia-python / CLI

Class CLI

Algorithmia/CLI.py:9–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import shutil
8
9class CLI:
10 def __init__(self):
11 self.client = Algorithmia.client()
12 # algo auth
13 def auth(self, apiaddress, apikey="", cacert="", profile="default", bearer=""):
14
15 # store api key in local config file and read from it each time a client needs to be created
16 key = self.getconfigfile()
17 config = toml.load(key)
18
19 if ('profiles' in config.keys()):
20 if (profile in config['profiles'].keys()):
21 config['profiles'][profile]['api_key'] = apikey
22 config['profiles'][profile]['api_server'] = apiaddress
23 config['profiles'][profile]['ca_cert'] = cacert
24 config['profiles'][profile]['bearer_token'] = bearer
25
26 else:
27 config['profiles'][profile] = {'api_key':apikey,'api_server':apiaddress,'ca_cert':cacert,'bearer_token':bearer}
28 else:
29 config['profiles'] = {profile:{'api_key':apikey,'api_server':apiaddress,'ca_cert':cacert,'bearer_token':bearer }}
30
31 with open(key, "w") as key:
32 toml.dump(config,key)
33
34 self.ls(path = None,client = CLI().getClient(profile))
35
36 # algo run <algo> <args..> run the the specified algo
37 def runalgo(self, options, client):
38 algo_input = None
39
40 algo = client.algo(options.algo)
41 url = client.apiAddress + algo.url
42 result = None
43 content = None
44
45 algo.set_options(timeout=options.timeout, stdout=options.debug)
46
47 # handle input type flags
48 if (options.data != None):
49 # data
50 algo_input = options.data
51
52 result = algo.pipe(algo_input)
53
54 elif (options.text != None):
55 # text
56 algo_input = options.text
57 key = self.getAPIkey(options.profile)
58 content = 'text/plain'
59 algo_input = algo_input.encode('utf-8')
60
61 elif (options.json != None):
62 # json
63 algo_input = options.json
64 key = self.getAPIkey(options.profile)
65 content = 'application/json'
66

Callers 15

mainFunction · 0.90
test_runMethod · 0.90
test_run_tokenMethod · 0.90
setUpMethod · 0.90
test_lsMethod · 0.90
test_mkdirMethod · 0.90
test_rmdirMethod · 0.90
test_catMethod · 0.90
test_get_build_logsMethod · 0.90
test_cp_L2RMethod · 0.90
test_cp_R2RMethod · 0.90
test_cp_R2LMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_runMethod · 0.72
test_run_tokenMethod · 0.72
setUpMethod · 0.72
test_lsMethod · 0.72
test_mkdirMethod · 0.72
test_rmdirMethod · 0.72
test_catMethod · 0.72
test_get_build_logsMethod · 0.72
test_cp_L2RMethod · 0.72
test_cp_R2RMethod · 0.72
test_cp_R2LMethod · 0.72
test_authMethod · 0.72