示例#1
0
def info_repository_specs(galaxy_context,
                          api,
                          repository_spec_strings,
                          display_callback=None,
                          offline=None):

    online = not offline

    display_callback = display_callback or display.display_callback

    offline = offline or False

    irdb = installed_repository_db.InstalledRepositoryDatabase(galaxy_context)

    labels_to_match = []

    all_labels_to_match = []
    for repository_spec_string in repository_spec_strings:
        galaxy_namespace, repository_name, content_name = parse_repository_name(
            repository_spec_string)

        log.debug('showing info for repository spec: %s',
                  repository_spec_string)

        repository_name = repository_name or content_name

        if online:
            remote_data = api.lookup_repo_by_name(galaxy_namespace,
                                                  repository_name)
            if remote_data:
                display_callback(_repr_remote_repo(remote_data))

        label_to_match = '%s.%s' % (galaxy_namespace, repository_name)
        all_labels_to_match.append(label_to_match)

        labels_to_match.append(label_to_match)

    matcher = matchers.MatchRepositorySpec(
        [label_and_spec[1] for label_and_spec in labels_to_match])
    matcher = matchers.MatchLabels(labels_to_match)

    matched_repositories = irdb.select(repository_spec_match_filter=matcher)

    remote_data = False

    matched_labels = []
    for matched_repository in matched_repositories:
        display_callback(_repr_installed_repository(matched_repository))
        matched_labels.append(matched_repository.repository_spec.label)

    unmatched_labels = set(all_labels_to_match).difference(set(matched_labels))

    if unmatched_labels:
        display_callback('These repositories were not found:')

        for unmatched_label in sorted(unmatched_labels):
            display_callback(_repr_unmatched_label(unmatched_label))

    return
示例#2
0
文件: list.py 项目: ansible/mazer
def _list(galaxy_context,
          repository_spec_match_filter=None,
          list_content=False,
          output_format=None,
          display_callback=None):

    output_format = output_format or OutputFormat.HUMAN

    log.debug('list_content: %s', list_content)

    all_repository_match = repository_spec_match_filter or matchers.MatchAll()

    # We search for installed repos to list, and then display all the content in those installed repos
    icidb = installed_content_item_db.InstalledContentItemDatabase(
        galaxy_context)

    irdb = installed_repository_db.InstalledRepositoryDatabase(galaxy_context)

    # accumulate for api return
    repo_list = []

    for installed_repository in irdb.select(
            repository_spec_match_filter=all_repository_match):
        log.debug('installed_repo: %s', installed_repository)

        content_items = collections.defaultdict(list)

        # Find all the content items for this particular repo
        repository_match = matchers.MatchRepositorySpec(
            [installed_repository.repository_spec])

        for content_info in icidb.select(
                repository_spec_match_filter=repository_match):
            content_dict = content_info.copy()

            content_item_type = content_dict['content_data'].content_item_type

            # revisit this output format once we get some feedback
            content_dict.update({
                'type': content_item_type,
                'name': content_dict['content_data'].name,
                'is_plugin': content_dict['content_data'].is_plugin,
                # 'installed_repo_namespace': repo.namespace,
                # 'installed_repo_name': repo.name,
                # 'installed_repo_path': repo.path,
                # 'installed_repo_id': repo.repository_spec.label,
                'installed_repository': installed_repository,
            })

            content_items[content_item_type].append(content_dict)
            # content_item_list.append(content_dict)

        repo_dict = {
            'content_items': content_items,
            'installed_repository': installed_repository
        }
        repo_list.append(repo_dict)

    if output_format == OutputFormat.LOCKFILE:
        output = format_as_lockfile(repo_list, lockfile_freeze=False)
        display_callback(output)

    elif output_format == OutputFormat.LOCKFILE_FREEZE:
        output = format_as_lockfile(repo_list, lockfile_freeze=True)
        display_callback(output)

    elif output_format == OutputFormat.FULLY_QUALIFIED:
        display_fully_qualified(repo_list, list_content, display_callback)
    else:
        display_for_human(repo_list, list_content, display_callback)

    return repo_list
示例#3
0
def _list(galaxy_context,
          repository_spec_match_filter=None,
          list_content=False,
          display_callback=None):

    log.debug('list_content: %s', list_content)

    all_repository_match = repository_spec_match_filter or matchers.MatchAll()

    # We search for installed repos to list, and then display all the content in those installed repos
    icidb = installed_content_item_db.InstalledContentItemDatabase(
        galaxy_context)

    irdb = installed_repository_db.InstalledRepositoryDatabase(galaxy_context)

    # accumulate for api return
    repo_list = []

    for installed_repository in irdb.select(
            repository_spec_match_filter=all_repository_match):
        log.debug('installed_repo: %s', installed_repository)

        content_items = collections.defaultdict(list)

        # Find all the content items for this particular repo
        repository_match = matchers.MatchRepositorySpec(
            [installed_repository.repository_spec])

        for content_info in icidb.select(
                repository_spec_match_filter=repository_match):
            content_dict = content_info.copy()

            content_item_type = content_dict['content_data'].content_item_type

            # revisit this output format once we get some feedback
            content_dict.update({
                'type': content_item_type,
                'name': content_dict['content_data'].name,
                # 'installed_repo_namespace': repo.namespace,
                # 'installed_repo_name': repo.name,
                # 'installed_repo_path': repo.path,
                # 'installed_repo_id': repo.repository_spec.label,
                'installed_repository': installed_repository,
            })

            content_items[content_item_type].append(content_dict)
            # content_item_list.append(content_dict)

        repo_dict = {
            'content_items': content_items,
            'installed_repository': installed_repository
        }
        repo_list.append(repo_dict)

    for repo_item in repo_list:
        repo_msg = "repo={installed_repository.repository_spec.label}, type=repository, version={installed_repository.repository_spec.version}"
        display_callback(repo_msg.format(**repo_item))

        if not list_content:
            continue

        for content_item_type_key, content_items_data in repo_item[
                'content_items'].items():
            content_msg = "repo={installed_repository.repository_spec.label}, type={type}, name={name}, " + \
                "version={installed_repository.repository_spec.version}"
            # content_msg = "    type={type}, name={name}, " + \
            #    "version={installed_repository.repository_spec.version}"

            # type_msg = "  {content_item_type}:"
            # display_callback(type_msg.format(content_item_type=content_item_type_key))

            log.debug('content_item: %s', content_items_data)
            log.debug('content_item_type_key: %s', content_item_type_key)

            for content_item_data in content_items_data:
                display_callback(content_msg.format(**content_item_data))
        # display_callback(msg.format(**content_dict))

    return repo_list
 def by_repository_spec(self, repository_spec):
     repository_spec_match_filter = matchers.MatchRepositorySpec(
         [repository_spec])
     return self.select(
         repository_spec_match_filter=repository_spec_match_filter)