Skip to content

Commit

Permalink
Merge pull request #153 from galaxyproject/user-show
Browse files Browse the repository at this point in the history
User Show
  • Loading branch information
ksuderman authored Oct 18, 2022
2 parents fbd28b7 + da9e6ad commit 7df3006
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
10 changes: 9 additions & 1 deletion abm/lib/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,19 @@
- name: [api_key, apikey, key]
help: obtain the API key for the specified user
handler: users.api_key
params: EMAIL
params: "[NAME|EMAIL]"
- name: [create, new]
help: create a new user on the Galaxy instance
handler: users.create
params: NAME EMAIL PASSWORD
- name: [ show ]
help: show details about the given user
handler: users.show
params: "[NAME|EMAIL]"
- name: [ usage ]
help: show details about the given user
handler: users.usage
params: "[NAME|EMAIL]"
- name: [experiment, exp, ex]
help: execute benchmarking runs on various clouds
standalone: true
Expand Down
55 changes: 55 additions & 0 deletions abm/lib/users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json

from pprint import pprint

from bioblend.galaxy import GalaxyInstance

from common import Context, connect


Expand Down Expand Up @@ -64,3 +67,55 @@ def create(context: Context, args:list):
'key': key
}
print(json.dumps(result, indent=4))


def show(context: Context, args:list):
if len(args) == 0:
print("ERROR: no user email given")
return

# TODO the master API key needs to be parameterized or specified in a config file.
context.API_KEY = "galaxypassword"
gi = connect(context)
id = _get_user_id(gi, args[0])
if id is None:
return
result = gi.users.show_user(id)
print(json.dumps(result, indent=4))


def usage(context:Context, args:list):
if len(args) == 0:
print("ERROR: no user email given")
return

# TODO the master API key needs to be parameterized or specified in a config file.
context.API_KEY = "galaxypassword"
gi = connect(context)
id = _get_user_id(gi, args[0])
if id is None:
return
user_data = gi.users.show_user(id)
usage = user_data['total_disk_usage']
MB = 1048576
GB = 1073741824
if usage < MB:
num = usage / 1024
unit = 'K'
elif usage < GB:
num = usage / MB
unit = 'M'
else:
num = usage / GB
unit = 'G'
print(f"{num:.2f}{unit}")


def _get_user_id(gi: GalaxyInstance, name_or_email: str) -> str:
user_list = gi.users.get_users(f_email=name_or_email)
if user_list is None or len(user_list) == 0:
print("WARNING: no such user")
return None
if len(user_list) > 1:
print("WARNING: more than one user with that email address. Returning the first")
return user_list[0]['id']

0 comments on commit 7df3006

Please sign in to comment.