def normalise_toolshed_url(toolshed): """ Return complete URL for a tool shed Arguments: toolshed (str): partial or full URL for a toolshed server Returns: str: full URL for toolshed, including leading protocol. """ if toolshed.startswith('http://') or \ toolshed.startswith('https://'): return toolshed return "https://%s" % toolshed
def installed_repositories(gi,name=None, toolshed=None, owner=None, include_deleted=False, only_updateable=False): """ Fetch a list of installed repository revisions Arguments: gi (bioblend.galaxy.GalaxyInstance): Galaxy instance name (str): optional, only list tool repositiories which match this string (can include wildcards) toolshed (str): optional, only list tool repositories from toolsheds that match this string (can include wildcards) owner (str): optional, only list tool repositiories with owners who match this string (can include wildcards) list_tools (bool): if True then also list the tools provided by the repository include_deleted (bool): if True then also include repository revisions that are marked as deleted (default is to only show those which are not deleted) only_updateable (bool): if True then only report repositories that have uninstalled updates or upgrades available (default is to show all repositories and revisions) Returns: List: a list of tuples consisting of three items (repository,revision,tools), where - 'repository' is a populated Repository instance - 'revision' is a populated RepositoryRevision - 'tools' is a list of Tool instances """ # Get the list of installed repos installed_repos = [] repos = get_repositories(gi) # Filter on name if name: name = name.lower() repos = filter(lambda r: fnmatch.fnmatch(r.name.lower(),name), repos) # Filter on toolshed if toolshed: # Strip leading http(s):// for protocol in ('https://','http://'): if toolshed.startswith(protocol): toolshed = toolshed[len(protocol):] repos = filter(lambda r: fnmatch.fnmatch(r.tool_shed,toolshed), repos) # Filter on owner if owner: repos = filter(lambda r: fnmatch.fnmatch(r.owner,owner),repos) # Get list of tools tools = get_tools(gi) for repo in repos: # Check each revision for revision in repo.revisions(): # Exclude deleted revisions if not include_deleted and revision.deleted: continue # Exclude revisions that don't need updating if only_updateable and \ (revision.newer_revision_installed() or \ revision.latest_revision): continue # Fetch tools associated with this revision repo_tools = filter(lambda t: t.tool_repo == repo.id and t.tool_changeset == revision.installed_changeset_revision, tools) # Append to the list installed_repos.append((repo,revision,repo_tools)) # Finished return installed_repos