'GET /api/repositories
Displays a collection of repositories with optional criteria.
:param q:        (optional)if present search on the given query will be performed
:type  q:        str
:param page:     (optional)requested page of the search
:type  page:     int
:param page_size:     (optional)requested page_size of the search
:type  page_size:     int
:param jsonp:    (optional)flag whether to use jsonp format response, defaults to False
:type  jsonp:    bool
:param callback: (optional)name of the function to wrap callback in
used only when jsonp is true, defaults to \'callback\'
:type  callback: str
:param deleted:  (optional)displays repositories that are or are not set to deleted.
:type  deleted:  bool
:param owner:    (optional)the owner\'s public username.
:type  owner:    str
:param name:     (optional)the repository name.
:type  name:     str
:param tool_ids:  (optional) a tool GUID to find the repository for
:param tool_ids:  str
:returns dict:   object containing list of results
Examples:
GET http://localhost:9009/api/repositories
GET http://localhost:9009/api/repositories?q=fastq'

@expose_api_raw_anonymous_and_sessionless
def index(self, trans, deleted=False, owner=None, name=None, **kwd):

    repository_dicts = []
    deleted = util.asbool(deleted)
    q = kwd.get('q', '')
    if q:
        page = kwd.get('page', 1)
        page_size = kwd.get('page_size', 10)
        try:
            page = int(page)
            page_size = int(page_size)
        except ValueError:
            raise RequestParameterInvalidException('The    "page"    and    "page_size"    parameters    have    to    be    integers.')
        return_jsonp = util.asbool(kwd.get('jsonp', False))
        callback = kwd.get('callback', 'callback')
        search_results = self._search(trans, q, page, page_size)
        if return_jsonp:
            response = str(('%s(%s);' % (callback, json.dumps(search_results))))
        else:
            response = json.dumps(search_results)
        return response
    tool_ids = kwd.get('tool_ids', None)
    if (tool_ids is not None):
        tool_ids = util.listify(tool_ids)
        repository_found = []
        all_metadata = dict()
        for tool_id in tool_ids:
            (shed, _, owner, name, tool, version) = tool_id.split('/')
            clause_list = [and_((self.app.model.Repository.table.c.deprecated == false()), (self.app.model.Repository.table.c.deleted == false()), (self.app.model.Repository.table.c.name == name), (self.app.model.User.table.c.username == owner), (self.app.model.Repository.table.c.user_id == self.app.model.User.table.c.id))]
            repository = trans.sa_session.query(self.app.model.Repository).filter(*clause_list).first()
            for (changeset, changehash) in repository.installable_revisions(self.app):
                metadata = metadata_util.get_current_repository_metadata_for_changeset_revision(self.app, repository, changehash)
                tools = metadata.metadata['tools']
                for tool in tools:
                    if (tool['guid'] in tool_ids):
                        repository_found.append(('%d:%s' % (int(changeset), changehash)))
                metadata = metadata_util.get_current_repository_metadata_for_changeset_revision(self.app, repository, changehash)
                if (metadata is None):
                    continue
                metadata_dict = metadata.to_dict(value_mapper={'id': self.app.security.encode_id, 'repository_id': self.app.security.encode_id})
                metadata_dict['repository'] = repository.to_dict(value_mapper={'id': self.app.security.encode_id})
                if metadata.has_repository_dependencies:
                    metadata_dict['repository_dependencies'] = metadata_util.get_all_dependencies(self.app, metadata, processed_dependency_links=[])
                else:
                    metadata_dict['repository_dependencies'] = []
                if metadata.includes_tool_dependencies:
                    metadata_dict['tool_dependencies'] = repository.get_tool_dependencies(self.app, changehash)
                else:
                    metadata_dict['tool_dependencies'] = {}
                if metadata.includes_tools:
                    metadata_dict['tools'] = metadata.metadata['tools']
                all_metadata[('%s:%s' % (int(changeset), changehash))] = metadata_dict
        if (repository_found is not None):
            all_metadata['current_changeset'] = repository_found[0]
            return json.dumps(all_metadata)
        return '{}'
    clause_list = [and_((self.app.model.Repository.table.c.deprecated == false()), (self.app.model.Repository.table.c.deleted == deleted))]
    if (owner is not None):
        clause_list.append(and_((self.app.model.User.table.c.username == owner), (self.app.model.Repository.table.c.user_id == self.app.model.User.table.c.id)))
    if (name is not None):
        clause_list.append((self.app.model.Repository.table.c.name == name))
    for repository in trans.sa_session.query(self.app.model.Repository).filter(*clause_list).order_by(self.app.model.Repository.table.c.name):
        repository_dict = repository.to_dict(view='collection', value_mapper=self.__get_value_mapper(trans))
        repository_dict['category_ids'] = [trans.security.encode_id(x.category.id) for x in repository.categories]
        repository_dicts.append(repository_dict)
    return json.dumps(repository_dicts)
