def login_cmd(force): """Perform a globus login. If forced, start the flow regardless of if they are already logged in. Args: force (bool): Whether or not to force the login. """ get_dlhub_client(force)
def describe_cmd(owner, name): """Use DLHub to get a description of the servable. Args: owner (string): The owner of the servable name (string): The name of the servable Returns: (dict) a set of information regarding the servable """ # Check if owner contains both if name == "": temp = owner.split("/") if len(temp) != 2: raise click.BadArgumentUsage('Model name missing') owner, name = temp # Retrieve the metadata client = get_dlhub_client() res = client.describe_servable(owner, name) # Clean up the metadata fields _preprocess_metadata(res) # Print it to screen format_output(yaml.dump(res)) return res
def run_cmd(servable, input): """Invoke a servable. The input data will be read with json.loads(input) and passed to the servable. Args: servable (string): The servable to invoke, e.g., "ryan_globusid/noop" input (dict): Input to pass into the servable Returns: (dict) resulting data. The output from executing the servable. """ if not any([servable, input]): format_output(HELP_STR) return client = get_dlhub_client() data = json.loads(input) namespace = servable.split("/")[0] model = servable.split("/")[1] res = client.run(namespace, model, data) format_output(res) return res
def methods_cmd(name, method): """Print out the methods of a servable Args: name (string): DLHub name of the servable of the form <user>/<servable_name> method (str): Name of the method (optional) """ # Check if name is proper format if len(name.split("/")) < 2: raise click.BadArgumentUsage('Please enter name in the form <user>/<servable_name>') if name.split("/")[0] == "" or name.split("/")[1] == "": raise click.BadArgumentUsage('Please enter name in the form <user>/<servable_name>') # If the method name is blank, make it None (for compatibility with client) if method == '': method = None # Get the DLHub client client = get_dlhub_client() # Get the method details method_details = client.describe_methods(name, method) # Print them in YAML format format_output(yaml.dump(method_details, default_flow_style=False))
def logout_cmd(): """Logout of the dlhub client. Returns: (None) None """ client = get_dlhub_client() client.logout()
def servables_cmd(): """List the available servables. Returns: (dict) the list of available servables as (uuid, name) pairs. """ client = get_dlhub_client() res = client.list_servables() format_output("{0}".format(res)) return res
def search_cmd(owner, name, all_versions, author, domain, doi, query): """Search command See above for argument details """ # Get the client client = get_dlhub_client() # Start the query object query = DLHubSearchHelper(client._search_client, q="(" + " ".join(query), advanced=True) # Add the filters query.match_owner(owner) query.match_servable(servable_name=name) query.match_authors(author) query.match_domains(domain) query.match_doi(doi) # If no query strings are given, return an error if not query.initialized: click.echo('Error: No query specified. For options, call: dlhub search --help') click.get_current_context().exit(1) # Perform the query results = query.search() # If no results, return nothing if len(results) == 0: click.echo('No results') return # If desired, filter the entries if not all_versions: results = filter_latest(results) # Get only a subset of the data and print it as a table results_df = pd.DataFrame([{ 'Owner': r['dlhub']['owner'], 'Model Name': r['dlhub']['name'], 'Publication Date': datetime.fromtimestamp(int(r['dlhub']['publication_date']) / 1000).strftime('%Y-%m-%d %H:%M'), 'Type': r['servable']['type'] } for r in results]) results_df.sort_values(['Owner', 'Model Name', 'Publication Date'], ascending=[True, True, False], inplace=True) click.echo(tabulate(results_df.values, headers=results_df.columns))
def methods_cmd(owner, name, method): """Print out the methods of a servable Args: owner (str): Name of the servable's owner name (str): Name of the servable method (str): Name of the method (optional) """ # Check if the owner sent model information in owner/model format if '/' in owner: # Get the owner and model name temp = owner.split('/') if len(temp) != 2: raise click.BadArgumentUsage( 'Expected owner_name/model_name format') # If "name" is provided, it is actually the method name if name != '': method = name owner, name = temp # Make sure the name was provided if name == '': raise click.BadArgumentUsage('Model name not provided') # If the method name is blank, make it None (for compatibility with client) if method == '': method = None # Get the DLHub client client = get_dlhub_client() # Get the method details method_details = client.describe_methods(owner, name, method) # Print them in YAML format format_output(yaml.dump(method_details, default_flow_style=False))
def describe_cmd(name): """Use DLHub to get a description of the servable. Args: name (string): DLHub name of the servable of the form <user>/<servable_name> Returns: (dict) a set of information regarding the servable """ # Check if name is proper format if len(name.split("/")) < 2: raise click.BadArgumentUsage('Please enter name in the form <user>/<servable_name>') # Retrieve the metadata client = get_dlhub_client() res = client.describe_servable(name) # Clean up the metadata fields _preprocess_metadata(res) # Print it to screen format_output(yaml.dump(res)) return res
def whoami_cmd(): client = get_dlhub_client() click.echo(client.get_username())