Example #1
0
def get_tool_dependencies(app, tool_shed_url, repository_name,
                          repository_owner, changeset_revision):
    tool_dependencies = []
    tool_shed_accessible = True
    params = dict(name=repository_name,
                  owner=repository_owner,
                  changeset_revision=changeset_revision)
    pathspec = ['repository', 'get_tool_dependencies']
    try:
        text = util.url_get(
            tool_shed_url,
            auth=app.tool_shed_registry.url_auth(tool_shed_url),
            pathspec=pathspec,
            params=params)
        tool_shed_accessible = True
    except Exception as e:
        tool_shed_accessible = False
        log.warning(
            "The URL\n%s\nraised the exception:\n%s\n",
            util.build_url(tool_shed_url, pathspec=pathspec, params=params), e)
    if tool_shed_accessible:
        if text:
            tool_dependencies_dict = encoding_util.tool_shed_decode(text)
            for requirements_dict in tool_dependencies_dict.values():
                tool_dependency_name = requirements_dict['name']
                tool_dependency_version = requirements_dict['version']
                tool_dependency_type = requirements_dict['type']
                tool_dependencies.append(
                    (tool_dependency_name, tool_dependency_version,
                     tool_dependency_type))
    return tool_shed_accessible, tool_dependencies
Example #2
0
def get_repository_dependencies(app, tool_shed_url, repository_name,
                                repository_owner, changeset_revision):
    repository_dependencies_dict = {}
    tool_shed_accessible = True
    params = dict(name=repository_name,
                  owner=repository_owner,
                  changeset_revision=changeset_revision)
    pathspec = ['repository', 'get_repository_dependencies']
    try:
        raw_text = util.url_get(
            tool_shed_url,
            auth=app.tool_shed_registry.url_auth(tool_shed_url),
            pathspec=pathspec,
            params=params)
        tool_shed_accessible = True
    except Exception as e:
        tool_shed_accessible = False
        log.warning(
            "The URL\n%s\nraised the exception:\n%s\n",
            util.build_url(tool_shed_url, pathspec=pathspec, params=params), e)
    if tool_shed_accessible:
        if len(raw_text) > 2:
            encoded_text = json.loads(util.unicodify(raw_text))
            repository_dependencies_dict = encoding_util.tool_shed_decode(
                encoded_text)
    return tool_shed_accessible, repository_dependencies_dict
Example #3
0
    def category(self, trans, **kwd):
        """
        GET /api/tool_shed/category

        Display a list of repositories in the selected category.

        :param tool_shed_url: the url of the toolshed to get repositories from
        :param category_id: the category to get repositories from
        """
        tool_shed_url = urlunquote(kwd.get('tool_shed_url', ''))
        category_id = kwd.get('category_id', '')
        params = dict(installable=True)
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(trans.app, tool_shed_url)
        url = util.build_url(tool_shed_url, pathspec=['api', 'categories', category_id, 'repositories'], params=params)
        repositories = []
        return_json = json.loads(util.url_get(url))
        for repository in return_json['repositories']:
            api_url = web.url_for(controller='api/tool_shed',
                                  action='repository',
                                  tool_shed_url=urlquote(tool_shed_url),
                                  repository_id=repository['id'],
                                  qualified=True)
            repository['url'] = api_url
            repositories.append(repository)
        return_json['repositories'] = repositories
        return return_json
Example #4
0
 def get_repository_dependencies_for_installed_tool_shed_repository(
         self, app, repository):
     """
     Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
     for the received repository which is installed into Galaxy.  This method is called only from Galaxy.
     """
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
         app, str(repository.tool_shed))
     params = dict(name=str(repository.name),
                   owner=str(repository.owner),
                   changeset_revision=str(repository.changeset_revision))
     pathspec = ['repository', 'get_repository_dependencies']
     try:
         raw_text = url_get(
             tool_shed_url,
             password_mgr=app.tool_shed_registry.url_auth(tool_shed_url),
             pathspec=pathspec,
             params=params)
     except Exception:
         log.exception(
             "Error while trying to get URL: %s",
             build_url(tool_shed_url, pathspec=pathspec, params=params))
         return ''
     if len(raw_text) > 2:
         encoded_text = json.loads(raw_text)
         text = encoding_util.tool_shed_decode(encoded_text)
     else:
         text = ''
     return text
Example #5
0
    def show(self, trans, **kwd):
        """
        GET /api/tool_shed/contents

        Display a list of categories in the selected toolshed.

        :param tool_shed_url: the url of the toolshed to get categories from
        """
        tool_shed_url = urlunquote(kwd.get('tool_shed_url', ''))
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
            trans.app, tool_shed_url)
        url = util.build_url(tool_shed_url, pathspec=['api', 'categories'])
        categories = []
        try:
            for category in json.loads(util.url_get(url)):
                api_url = web.url_for(controller='api/tool_shed',
                                      action='category',
                                      tool_shed_url=urlquote(tool_shed_url),
                                      category_id=category['id'],
                                      qualified=True)
                category['url'] = api_url
                categories.append(category)
        except Exception:
            raise exceptions.ObjectNotFound("Tool Shed %s is not responding." %
                                            tool_shed_url)
        return categories
Example #6
0
    def shed_categories( self, trans, **kwd ):
        """
        GET /api/tool_shed_repositories/shed_categories

        Display a list of categories in the selected toolshed.

        :param tool_shed_url: the url of the toolshed to get categories from
        """
        tool_shed_url = kwd.get( 'tool_shed_url', '' )
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed_url )
        url = util.build_url( tool_shed_url, pathspec=[ 'api', 'categories' ] )
        categories = json.loads( util.url_get( url ) )
        repositories = []
        url = util.build_url( tool_shed_url, pathspec=[ 'api', 'repositories' ] )
        for repo in json.loads( util.url_get( url ) ):
            repositories.append( dict( value=repo[ 'id' ], label='%s/%s' % ( repo[ 'owner' ], repo[ 'name' ] ) ) )
        return { 'categories': categories, 'repositories': repositories }
Example #7
0
def generate_clone_url_from_repo_info_tup(app, repo_info_tup):
    """Generate the URL for cloning a repository given a tuple of toolshed, name, owner, changeset_revision."""
    # Example tuple: ['http://localhost:9009', 'blast_datatypes', 'test', '461a4216e8ab', False]
    toolshed, name, owner, changeset_revision, prior_installation_required, only_if_compiling_contained_td = \
        parse_repository_dependency_tuple(repo_info_tup)
    tool_shed_url = get_tool_shed_url_from_tool_shed_registry(app, toolshed)
    # Don't include the changeset_revision in clone urls.
    return util.build_url(tool_shed_url, pathspec=['repos', owner, name])
Example #8
0
def generate_clone_url_from_repo_info_tup(app, repo_info_tup):
    """Generate the URL for cloning a repository given a tuple of toolshed, name, owner, changeset_revision."""
    # Example tuple: ['http://localhost:9009', 'blast_datatypes', 'test', '461a4216e8ab', False]
    toolshed, name, owner, changeset_revision, prior_installation_required, only_if_compiling_contained_td = \
        parse_repository_dependency_tuple(repo_info_tup)
    tool_shed_url = get_tool_shed_url_from_tool_shed_registry(app, toolshed)
    # Don't include the changeset_revision in clone urls.
    return util.build_url(tool_shed_url, pathspec=['repos', owner, name])
Example #9
0
def generate_clone_url_for_installed_repository(app, repository):
    """Generate the URL for cloning a repository that has been installed into a Galaxy instance."""
    tool_shed_url = get_tool_shed_url_from_tool_shed_registry(
        app, str(repository.tool_shed))
    return util.build_url(
        tool_shed_url,
        pathspec=['repos',
                  str(repository.owner),
                  str(repository.name)])
Example #10
0
def get_api_url( base, parts=[], params=None ):
    """Compose and return a URL for the Tool Shed API."""
    if 'api' in parts and parts.index( 'api' ) != 0:
        parts.pop( parts.index( 'api' ) )
        parts.insert( 0, 'api' )
    elif 'api' not in parts:
        parts.insert( 0, 'api' )
    url = util.build_url( base, pathspec=parts, params=params )
    return url
Example #11
0
def get_api_url(base, parts=[], params=None):
    """Compose and return a URL for the Tool Shed API."""
    if 'api' in parts and parts.index('api') != 0:
        parts.pop(parts.index('api'))
        parts.insert(0, 'api')
    elif 'api' not in parts:
        parts.insert(0, 'api')
    url = util.build_url(base, pathspec=parts, params=params)
    return url
Example #12
0
    def shed_categories(self, trans, **kwd):
        """
        GET /api/tool_shed_repositories/shed_categories

        Display a list of categories in the selected toolshed.

        :param tool_shed_url: the url of the toolshed to get categories from
        """
        tool_shed_url = kwd.get('tool_shed_url', '')
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
            trans.app, tool_shed_url)
        url = util.build_url(tool_shed_url, pathspec=['api', 'categories'])
        categories = json.loads(util.url_get(url))
        repositories = []
        url = util.build_url(tool_shed_url, pathspec=['api', 'repositories'])
        for repo in json.loads(util.url_get(url)):
            repositories.append(
                dict(value=repo['id'],
                     label='%s/%s' % (repo['owner'], repo['name'])))
        return {'categories': categories, 'repositories': repositories}
Example #13
0
def get_tool_dependencies( app, tool_shed_url, repository_name, repository_owner, changeset_revision ):
    tool_dependencies = []
    tool_shed_accessible = True
    params = dict( name=repository_name, owner=repository_owner, changeset_revision=changeset_revision )
    pathspec = [ 'repository', 'get_tool_dependencies' ]
    try:
        text = util.url_get( tool_shed_url, password_mgr=app.tool_shed_registry.url_auth( tool_shed_url ), pathspec=pathspec, params=params )
        tool_shed_accessible = True
    except Exception, e:
        tool_shed_accessible = False
        log.warn( "The URL\n%s\nraised the exception:\n%s\n", util.build_url( tool_shed_url, pathspec=pathspec, params=params ), e )
Example #14
0
    def shed_category( self, trans, **kwd ):
        """
        GET /api/tool_shed_repositories/shed_category

        Display a list of repositories in the selected category.

        :param tool_shed_url: the url of the toolshed to get repositories from
        :param category_id: the category to get repositories from
        """
        tool_shed_url = kwd.get( 'tool_shed_url', '' )
        category_id = kwd.get( 'category_id', '' )
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed_url )
        url = util.build_url( tool_shed_url, pathspec=[ 'api', 'categories', category_id, 'repositories' ] )
        category = json.loads( util.url_get( url ) )
        return category
Example #15
0
def get_repository_dependencies(app, tool_shed_url, repository_name, repository_owner, changeset_revision):
    repository_dependencies_dict = {}
    tool_shed_accessible = True
    params = dict(name=repository_name, owner=repository_owner, changeset_revision=changeset_revision)
    pathspec = ['repository', 'get_repository_dependencies']
    try:
        raw_text = util.url_get(tool_shed_url, password_mgr=app.tool_shed_registry.url_auth(tool_shed_url), pathspec=pathspec, params=params)
        tool_shed_accessible = True
    except Exception as e:
        tool_shed_accessible = False
        log.warning("The URL\n%s\nraised the exception:\n%s\n", util.build_url(tool_shed_url, pathspec=pathspec, params=params), e)
    if tool_shed_accessible:
        if len(raw_text) > 2:
            encoded_text = json.loads(raw_text)
            repository_dependencies_dict = encoding_util.tool_shed_decode(encoded_text)
    return tool_shed_accessible, repository_dependencies_dict
Example #16
0
    def shed_category(self, trans, **kwd):
        """
        GET /api/tool_shed_repositories/shed_category

        Display a list of repositories in the selected category.

        :param tool_shed_url: the url of the toolshed to get repositories from
        :param category_id: the category to get repositories from
        """
        tool_shed_url = kwd.get('tool_shed_url', '')
        category_id = kwd.get('category_id', '')
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
            trans.app, tool_shed_url)
        url = util.build_url(
            tool_shed_url,
            pathspec=['api', 'categories', category_id, 'repositories'])
        category = json.loads(util.url_get(url))
        return category
Example #17
0
def get_tool_dependencies(app, tool_shed_url, repository_name, repository_owner, changeset_revision):
    tool_dependencies = []
    tool_shed_accessible = True
    params = dict(name=repository_name, owner=repository_owner, changeset_revision=changeset_revision)
    pathspec = ['repository', 'get_tool_dependencies']
    try:
        text = util.url_get(tool_shed_url, password_mgr=app.tool_shed_registry.url_auth(tool_shed_url), pathspec=pathspec, params=params)
        tool_shed_accessible = True
    except Exception as e:
        tool_shed_accessible = False
        log.warning("The URL\n%s\nraised the exception:\n%s\n", util.build_url(tool_shed_url, pathspec=pathspec, params=params), e)
    if tool_shed_accessible:
        if text:
            tool_dependencies_dict = encoding_util.tool_shed_decode(text)
            for requirements_dict in tool_dependencies_dict.values():
                tool_dependency_name = requirements_dict['name']
                tool_dependency_version = requirements_dict['version']
                tool_dependency_type = requirements_dict['type']
                tool_dependencies.append((tool_dependency_name, tool_dependency_version, tool_dependency_type))
    return tool_shed_accessible, tool_dependencies
Example #18
0
    def show(self, trans, **kwd):
        """
        GET /api/tool_shed/contents

        Display a list of categories in the selected toolshed.

        :param tool_shed_url: the url of the toolshed to get categories from
        """
        tool_shed_url = urlunquote(kwd.get('tool_shed_url', ''))
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(trans.app, tool_shed_url)
        url = util.build_url(tool_shed_url, pathspec=['api', 'categories'])
        categories = []
        for category in json.loads(util.url_get(url)):
            api_url = web.url_for(controller='api/tool_shed',
                                  action='category',
                                  tool_shed_url=urlquote(tool_shed_url),
                                  category_id=category['id'],
                                  qualified=True)
            category['url'] = api_url
            categories.append(category)
        return categories
 def get_repository_dependencies_for_installed_tool_shed_repository(self, app, repository):
     """
     Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
     for the received repository which is installed into Galaxy.  This method is called only from Galaxy.
     """
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(app, str(repository.tool_shed))
     params = dict(name=str(repository.name),
                   owner=str(repository.owner),
                   changeset_revision=str(repository.changeset_revision))
     pathspec = ['repository', 'get_repository_dependencies']
     try:
         raw_text = url_get(tool_shed_url, password_mgr=app.tool_shed_registry.url_auth(tool_shed_url), pathspec=pathspec, params=params)
     except Exception as e:
         log.error("The URL\n%s\nraised the exception:\n%s\n", build_url(tool_shed_url, pathspec=pathspec, params=params), str(e))
         return ''
     if len(raw_text) > 2:
         encoded_text = json.loads(raw_text)
         text = encoding_util.tool_shed_decode(encoded_text)
     else:
         text = ''
     return text
Example #20
0
    def category(self, trans, **kwd):
        """
        GET /api/tool_shed/category

        Display a list of repositories in the selected category.

        :param tool_shed_url: the url of the toolshed to get repositories from
        :param category_id: the category to get repositories from
        :param sort_key: the field by which the repositories should be sorted
        :param sort_order: ascending or descending sort
        :param page: the page number to return
        """
        sort_order = kwd.get('sort_order', 'asc')
        sort_key = kwd.get('sort_key', 'name')
        page = kwd.get('page', 1)
        tool_shed_url = urlunquote(kwd.get('tool_shed_url', ''))
        category_id = kwd.get('category_id', '')
        params = dict(installable=True,
                      sort_order=sort_order,
                      sort_key=sort_key,
                      page=page)
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
            trans.app, tool_shed_url)
        url = util.build_url(
            tool_shed_url,
            pathspec=['api', 'categories', category_id, 'repositories'],
            params=params)
        repositories = []
        return_json = json.loads(util.url_get(url))
        for repository in return_json['repositories']:
            api_url = web.url_for(controller='api/tool_shed',
                                  action='repository',
                                  tool_shed_url=urlquote(tool_shed_url),
                                  repository_id=repository['id'],
                                  qualified=True)
            repository['url'] = api_url
            repositories.append(repository)
        return_json['repositories'] = repositories
        return return_json
 def get_repository_dependencies_for_installed_tool_shed_repository(
         self, app, repository):
     """
     Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
     for the received repository which is installed into Galaxy.  This method is called only from Galaxy.
     """
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
         app, str(repository.tool_shed))
     params = dict(name=str(repository.name),
                   owner=str(repository.owner),
                   changeset_revision=str(repository.changeset_revision))
     pathspec = ['repository', 'get_repository_dependencies']
     try:
         raw_text = url_get(
             tool_shed_url,
             password_mgr=app.tool_shed_registry.url_auth(tool_shed_url),
             pathspec=pathspec,
             params=params)
     except Exception, e:
         log.error(
             "The URL\n%s\nraised the exception:\n%s\n",
             build_url(tool_shed_url, pathspec=pathspec, params=params),
             str(e))
         return ''
Example #22
0
def build_citable_url(host, repository):
    return build_url(
        host, pathspec=['view', repository.user.username, repository.name])
def build_citable_url( host, repository ):
    return build_url( host, pathspec=[ 'view', repository.user.username, repository.name ] )
Example #24
0
def generate_clone_url_for_installed_repository(app, repository):
    """Generate the URL for cloning a repository that has been installed into a Galaxy instance."""
    tool_shed_url = get_tool_shed_url_from_tool_shed_registry(app, str(repository.tool_shed))
    return util.build_url(tool_shed_url, pathspec=['repos', str(repository.owner), str(repository.name)])
Example #25
0
 def get_required_repo_info_dicts(self, tool_shed_url, repo_info_dicts):
     """
     Inspect the list of repo_info_dicts for repository dependencies and append a repo_info_dict for each of
     them to the list.  All repository_dependency entries in each of the received repo_info_dicts includes
     all required repositories, so only one pass through this method is required to retrieve all repository
     dependencies.
     """
     all_required_repo_info_dict = {}
     all_repo_info_dicts = []
     if repo_info_dicts:
         # We'll send tuples of ( tool_shed, repository_name, repository_owner, changeset_revision ) to the tool
         # shed to discover repository ids.
         required_repository_tups = []
         for repo_info_dict in repo_info_dicts:
             if repo_info_dict not in all_repo_info_dicts:
                 all_repo_info_dicts.append(repo_info_dict)
             for repository_name, repo_info_tup in repo_info_dict.items():
                 description, \
                     repository_clone_url, \
                     changeset_revision, \
                     ctx_rev, \
                     repository_owner, \
                     repository_dependencies, \
                     tool_dependencies = \
                     repository_util.get_repo_info_tuple_contents(repo_info_tup)
                 if repository_dependencies:
                     for key, val in repository_dependencies.items():
                         if key in ['root_key', 'description']:
                             continue
                         repository_components_tuple = get_components_from_key(
                             key)
                         components_list = repository_util.extract_components_from_tuple(
                             repository_components_tuple)
                         # Skip listing a repository dependency if it is required only to compile a tool dependency
                         # defined for the dependent repository since in this case, the repository dependency is really
                         # a dependency of the dependent repository's contained tool dependency, and only if that
                         # tool dependency requires compilation.
                         # For backward compatibility to the 12/20/12 Galaxy release.
                         only_if_compiling_contained_td = 'False'
                         if len(components_list) == 4:
                             only_if_compiling_contained_td = 'False'
                         elif len(components_list) == 5:
                             only_if_compiling_contained_td = 'False'
                         if not asbool(only_if_compiling_contained_td):
                             if components_list not in required_repository_tups:
                                 required_repository_tups.append(
                                     components_list)
                         for components_list in val:
                             try:
                                 only_if_compiling_contained_td = components_list[
                                     5]
                             except IndexError:
                                 only_if_compiling_contained_td = 'False'
                             # Skip listing a repository dependency if it is required only to compile a tool dependency
                             # defined for the dependent repository (see above comment).
                             if not asbool(only_if_compiling_contained_td):
                                 if components_list not in required_repository_tups:
                                     required_repository_tups.append(
                                         components_list)
                 else:
                     # We have a single repository with no dependencies.
                     components_list = [
                         tool_shed_url, repository_name, repository_owner,
                         changeset_revision
                     ]
                     required_repository_tups.append(components_list)
             if required_repository_tups:
                 # The value of required_repository_tups is a list of tuples, so we need to encode it.
                 encoded_required_repository_tups = []
                 for required_repository_tup in required_repository_tups:
                     # Convert every item in required_repository_tup to a string.
                     required_repository_tup = [
                         str(item) for item in required_repository_tup
                     ]
                     encoded_required_repository_tups.append(
                         encoding_util.encoding_sep.join(
                             required_repository_tup))
                 encoded_required_repository_str = encoding_util.encoding_sep2.join(
                     encoded_required_repository_tups)
                 encoded_required_repository_str = encoding_util.tool_shed_encode(
                     encoded_required_repository_str)
                 if repository_util.is_tool_shed_client(self.app):
                     # Handle secure / insecure Tool Shed URL protocol changes and port changes.
                     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
                         self.app, tool_shed_url)
                 pathspec = ['repository', 'get_required_repo_info_dict']
                 url = build_url(tool_shed_url, pathspec=pathspec)
                 # Fix for handling 307 redirect not being handled nicely by urlopen() when the Request() has data provided
                 try:
                     url = _urlopen(url).geturl()
                 except HTTPError as e:
                     if e.code == 502:
                         pass
                     else:
                         raise
                 payload = urlencode(
                     dict(encoded_str=encoded_required_repository_str))
                 response = _urlopen(url, payload).read()
                 if response:
                     try:
                         required_repo_info_dict = json.loads(
                             unicodify(response))
                     except Exception as e:
                         log.exception(e)
                         return all_repo_info_dicts
                     required_repo_info_dicts = []
                     for k, v in required_repo_info_dict.items():
                         if k == 'repo_info_dicts':
                             encoded_dict_strings = required_repo_info_dict[
                                 'repo_info_dicts']
                             for encoded_dict_str in encoded_dict_strings:
                                 decoded_dict = encoding_util.tool_shed_decode(
                                     encoded_dict_str)
                                 required_repo_info_dicts.append(
                                     decoded_dict)
                         else:
                             if k not in all_required_repo_info_dict:
                                 all_required_repo_info_dict[k] = v
                             else:
                                 if v and not all_required_repo_info_dict[k]:
                                     all_required_repo_info_dict[k] = v
                         if required_repo_info_dicts:
                             for required_repo_info_dict in required_repo_info_dicts:
                                 # Each required_repo_info_dict has a single entry, and all_repo_info_dicts is a list
                                 # of dictionaries, each of which has a single entry.  We'll check keys here rather than
                                 # the entire dictionary because a dictionary entry in all_repo_info_dicts will include
                                 # lists of discovered repository dependencies, but these lists will be empty in the
                                 # required_repo_info_dict since dependency discovery has not yet been performed for these
                                 # dictionaries.
                                 required_repo_info_dict_key = next(
                                     iter(required_repo_info_dict))
                                 all_repo_info_dicts_keys = [
                                     next(iter(d))
                                     for d in all_repo_info_dicts
                                 ]
                                 if required_repo_info_dict_key not in all_repo_info_dicts_keys:
                                     all_repo_info_dicts.append(
                                         required_repo_info_dict)
                                 else:
                                     # required_repo_info_dict_key corresponds to the repo name.
                                     # A single install transaction might require the installation of 2 or more repos
                                     # with the same repo name but different owners or versions.
                                     # Therefore, if required_repo_info_dict_key is already in all_repo_info_dicts,
                                     # check that the tool id is already present. If it is not, we are dealing with the same repo name,
                                     # but a different owner/changeset revision or version and we add the repo to the list of repos to be installed.
                                     tool_id = required_repo_info_dict[
                                         required_repo_info_dict_key][1]
                                     is_present = False
                                     for repo_info_dict in all_repo_info_dicts:
                                         for k, v in repo_info_dict.items():
                                             if required_repo_info_dict_key == k:
                                                 if tool_id == v[1]:
                                                     is_present = True
                                                     break
                                     if not is_present:
                                         all_repo_info_dicts.append(
                                             required_repo_info_dict)
                     all_required_repo_info_dict[
                         'all_repo_info_dicts'] = all_repo_info_dicts
     return all_required_repo_info_dict
 def get_required_repo_info_dicts(self, tool_shed_url, repo_info_dicts):
     """
     Inspect the list of repo_info_dicts for repository dependencies and append a repo_info_dict for each of
     them to the list.  All repository_dependency entries in each of the received repo_info_dicts includes
     all required repositories, so only one pass through this method is required to retrieve all repository
     dependencies.
     """
     all_required_repo_info_dict = {}
     all_repo_info_dicts = []
     if repo_info_dicts:
         # We'll send tuples of ( tool_shed, repository_name, repository_owner, changeset_revision ) to the tool
         # shed to discover repository ids.
         required_repository_tups = []
         for repo_info_dict in repo_info_dicts:
             if repo_info_dict not in all_repo_info_dicts:
                 all_repo_info_dicts.append(repo_info_dict)
             for repository_name, repo_info_tup in repo_info_dict.items():
                 description, \
                     repository_clone_url, \
                     changeset_revision, \
                     ctx_rev, \
                     repository_owner, \
                     repository_dependencies, \
                     tool_dependencies = \
                     repository_util.get_repo_info_tuple_contents(repo_info_tup)
                 if repository_dependencies:
                     for key, val in repository_dependencies.items():
                         if key in ['root_key', 'description']:
                             continue
                         repository_components_tuple = container_util.get_components_from_key(key)
                         components_list = repository_util.extract_components_from_tuple(repository_components_tuple)
                         # Skip listing a repository dependency if it is required only to compile a tool dependency
                         # defined for the dependent repository since in this case, the repository dependency is really
                         # a dependency of the dependent repository's contained tool dependency, and only if that
                         # tool dependency requires compilation.
                         # For backward compatibility to the 12/20/12 Galaxy release.
                         only_if_compiling_contained_td = 'False'
                         if len(components_list) == 4:
                             only_if_compiling_contained_td = 'False'
                         elif len(components_list) == 5:
                             only_if_compiling_contained_td = 'False'
                         if not asbool(only_if_compiling_contained_td):
                             if components_list not in required_repository_tups:
                                 required_repository_tups.append(components_list)
                         for components_list in val:
                             try:
                                 only_if_compiling_contained_td = components_list[5]
                             except:
                                 only_if_compiling_contained_td = 'False'
                             # Skip listing a repository dependency if it is required only to compile a tool dependency
                             # defined for the dependent repository (see above comment).
                             if not asbool(only_if_compiling_contained_td):
                                 if components_list not in required_repository_tups:
                                     required_repository_tups.append(components_list)
                 else:
                     # We have a single repository with no dependencies.
                     components_list = [tool_shed_url, repository_name, repository_owner, changeset_revision]
                     required_repository_tups.append(components_list)
             if required_repository_tups:
                 # The value of required_repository_tups is a list of tuples, so we need to encode it.
                 encoded_required_repository_tups = []
                 for required_repository_tup in required_repository_tups:
                     # Convert every item in required_repository_tup to a string.
                     required_repository_tup = [str(item) for item in required_repository_tup]
                     encoded_required_repository_tups.append(encoding_util.encoding_sep.join(required_repository_tup))
                 encoded_required_repository_str = encoding_util.encoding_sep2.join(encoded_required_repository_tups)
                 encoded_required_repository_str = encoding_util.tool_shed_encode(encoded_required_repository_str)
                 if repository_util.is_tool_shed_client(self.app):
                     # Handle secure / insecure Tool Shed URL protocol changes and port changes.
                     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(self.app, tool_shed_url)
                 pathspec = ['repository', 'get_required_repo_info_dict']
                 url = build_url(tool_shed_url, pathspec=pathspec)
                 # Fix for handling 307 redirect not being handled nicely by urlopen() when the Request() has data provided
                 url = _urlopen(url).geturl()
                 response = _urlopen(url, urlencode(dict(encoded_str=encoded_required_repository_str))).read()
                 if response:
                     try:
                         required_repo_info_dict = json.loads(response)
                     except Exception as e:
                         log.exception(e)
                         return all_repo_info_dicts
                     required_repo_info_dicts = []
                     for k, v in required_repo_info_dict.items():
                         if k == 'repo_info_dicts':
                             encoded_dict_strings = required_repo_info_dict['repo_info_dicts']
                             for encoded_dict_str in encoded_dict_strings:
                                 decoded_dict = encoding_util.tool_shed_decode(encoded_dict_str)
                                 required_repo_info_dicts.append(decoded_dict)
                         else:
                             if k not in all_required_repo_info_dict:
                                 all_required_repo_info_dict[k] = v
                             else:
                                 if v and not all_required_repo_info_dict[k]:
                                     all_required_repo_info_dict[k] = v
                         if required_repo_info_dicts:
                             for required_repo_info_dict in required_repo_info_dicts:
                                 # Each required_repo_info_dict has a single entry, and all_repo_info_dicts is a list
                                 # of dictionaries, each of which has a single entry.  We'll check keys here rather than
                                 # the entire dictionary because a dictionary entry in all_repo_info_dicts will include
                                 # lists of discovered repository dependencies, but these lists will be empty in the
                                 # required_repo_info_dict since dependency discovery has not yet been performed for these
                                 # dictionaries.
                                 required_repo_info_dict_key = next(iter(required_repo_info_dict))
                                 all_repo_info_dicts_keys = [next(iter(d)) for d in all_repo_info_dicts]
                                 if required_repo_info_dict_key not in all_repo_info_dicts_keys:
                                     all_repo_info_dicts.append(required_repo_info_dict)
                                 else:
                                     # required_repo_info_dict_key corresponds to the repo name.
                                     # A single install transaction might require the installation of 2 or more repos
                                     # with the same repo name but different owners or versions.
                                     # Therefore, if required_repo_info_dict_key is already in all_repo_info_dicts,
                                     # check that the tool id is already present. If it is not, we are dealing with the same repo name,
                                     # but a different owner/changeset revision or version and we add the repo to the list of repos to be installed.
                                     tool_id = required_repo_info_dict[required_repo_info_dict_key][1]
                                     is_present = False
                                     for repo_info_dict in all_repo_info_dicts:
                                         for k, v in repo_info_dict.items():
                                             if required_repo_info_dict_key == k:
                                                 if tool_id == v[1]:
                                                     is_present = True
                                                     break
                                     if not is_present:
                                         all_repo_info_dicts.append(required_repo_info_dict)
                     all_required_repo_info_dict['all_repo_info_dicts'] = all_repo_info_dicts
     return all_required_repo_info_dict