Skip to content

Improve environment printing format #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
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
24 changes: 19 additions & 5 deletions Algorithmia/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,30 @@ def cp(self, src, dest, client):

def get_environment_by_language(self,language,client):
response = client.get_environment(language)
if "error" in response:
return json.dumps(response)
return json.dumps(response['environments'],indent=1)

table = []
if "error" not in response:
# extract properties of interest for faster sort
subset_props = []
for env in response['environments']:
subset_props.append(
(env['display_name'], env['environment_specification_id']))
# sort environments by display_name
subset_props = sorted(subset_props, key=lambda tup: tup[0] )
table.append("{:<45} {:<40}".format('Display Name', 'Specification ID'))
table.append('*' * 80)
for tup in subset_props:
table.append("{:<45} {:<40}".format(
tup[0], tup[1]))
else:
table.append(json.dumps(response))
return table

def list_languages(self, client):
response = client.get_supported_languages()
table = []
if "error" not in response:
table.append("{:<25} {:<35}".format('Name','Description'))
table.append("{:<25} {:<35}".format('Name','Display Name'))
table.append('*' * 80)
for lang in response:
table.append("{:<25} {:<35}".format(lang['name'],lang['display_name']))
else:
Expand Down
11 changes: 6 additions & 5 deletions Algorithmia/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,19 @@ def main():

elif args.cmd == 'cat':
print(CLI().cat(args.path, client))

elif args.cmd == 'languages':
response = CLI().list_languages(client)
for line in response:
print(line)

elif args.cmd == 'template':
CLI().get_template(args.envid,args.dest,client)
CLI().get_template(args.envid,args.dest, client)

elif args.cmd == 'environment':
response = CLI().get_environment_by_language(args.language,client)
print(response)
response = CLI().get_environment_by_language(args.language, client)
for line in response:
print(line)

elif args.cmd == 'builds':
print(CLI().getBuildLogs(args.user, args.algo, client))
Expand All @@ -225,4 +226,4 @@ def main():

if __name__ == '__main__':
#main()
main()
main()
2 changes: 1 addition & 1 deletion Test/CLI_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_get_environment(self):
print(result)
if("error" in result):
print(result)
self.assertTrue(result is not None and "display_name" in result)
self.assertTrue(result is not None and "Python 2.7" in result)

def test_list_languages(self):
result = CLI().list_languages(self.client)
Expand Down