Ejemplo n.º 1
0
def list_software_txt(software, detailed=False):
    """
    Return overview of supported software in plain text

    :param software: software information (structured like list_software does)
    :param detailed: whether or not to return detailed information (incl. version, versionsuffix, toolchain info)
    :return: multi-line string presenting requested info
    """

    lines = ['']
    for key in sorted(software, key=lambda x: x.lower()):
        lines.append('* %s' % key)
        if detailed:
            lines.extend([
                '',
                ' '.join(software[key][-1]['description'].split('\n')),
                '',
                "homepage: %s" % software[key][-1]['homepage'],
                '',
            ])

            # first determine unique pairs of version/versionsuffix
            # we can't use LooseVersion yet here, since nub uses set and LooseVersion instances are not hashable
            pairs = nub(
                (x['version'], x['versionsuffix']) for x in software[key])

            # sort pairs by version (and then by versionsuffix);
            # we sort by LooseVersion to obtain chronological version ordering,
            # but we also need to retain original string version for filtering-by-version done below
            sorted_pairs = sort_looseversions(
                (LooseVersion(v), vs, v) for v, vs in pairs)

            for _, vsuff, ver in sorted_pairs:
                tcs = [
                    x['toolchain'] for x in software[key]
                    if x['version'] == ver and x['versionsuffix'] == vsuff
                ]

                line = "  * %s v%s" % (key, ver)
                if vsuff:
                    line += " (versionsuffix: '%s')" % vsuff
                line += ": %s" % ', '.join(sorted(nub(tcs)))
                lines.append(line)
            lines.append('')

    return '\n'.join(lines)
Ejemplo n.º 2
0
def list_software_rst(software, detailed=False):
    """
    Return overview of supported software in RST format

    :param software: software information (structured like list_software does)
    :param detailed: whether or not to return detailed information (incl. version, versionsuffix, toolchain info)
    :return: multi-line string presenting requested info
    """

    title = "List of supported software"
    lines = [
        title,
        '=' * len(title),
        '',
        "EasyBuild |version| supports %d different software packages (incl. toolchains, bundles):"
        % len(software),
        '',
    ]

    # links to per-letter tables
    letter_refs = ''
    key_letters = nub(sorted(k[0].lower() for k in software.keys()))
    for letter in ascii_lowercase:
        if letter in key_letters:
            if letter_refs:
                letter_refs += " - :ref:`list_software_letter_%s`" % letter
            else:
                letter_refs = ":ref:`list_software_letter_%s`" % letter
    lines.extend([letter_refs, ''])

    def key_to_ref(name):
        """Create a reference label for the specified software name."""
        return 'list_software_%s_%d' % (name,
                                        sum(ord(letter) for letter in name))

    letter = None
    sorted_keys = sorted(software.keys(), key=lambda x: x.lower())
    for key in sorted_keys:

        # start a new subsection for each letter
        if key[0].lower() != letter:

            # subsection for new letter
            letter = key[0].lower()
            lines.extend([
                '',
                '.. _list_software_letter_%s:' % letter,
                '',
                "*%s*" % letter.upper(),
                '-' * 3,
                '',
            ])

            if detailed:
                # quick links per software package
                lines.extend([
                    '',
                    ' - '.join(':ref:`%s`' % key_to_ref(k) for k in sorted_keys
                               if k[0].lower() == letter),
                    '',
                ])

        # append software to list, including version(suffix) & toolchain info if detailed info is requested
        if detailed:
            table_titles = ['version', 'toolchain']
            table_values = [[], []]

            # first determine unique pairs of version/versionsuffix
            # we can't use LooseVersion yet here, since nub uses set and LooseVersion instances are not hashable
            pairs = nub(
                (x['version'], x['versionsuffix']) for x in software[key])

            # check whether any non-empty versionsuffixes are in play
            with_vsuff = any(vs for (_, vs) in pairs)
            if with_vsuff:
                table_titles.insert(1, 'versionsuffix')
                table_values.insert(1, [])

            # sort pairs by version (and then by versionsuffix);
            # we sort by LooseVersion to obtain chronological version ordering,
            # but we also need to retain original string version for filtering-by-version done below
            sorted_pairs = sort_looseversions(
                (LooseVersion(v), vs, v) for v, vs in pairs)

            for _, vsuff, ver in sorted_pairs:
                table_values[0].append('``%s``' % ver)
                if with_vsuff:
                    if vsuff:
                        table_values[1].append('``%s``' % vsuff)
                    else:
                        table_values[1].append('')
                tcs = [
                    x['toolchain'] for x in software[key]
                    if x['version'] == ver and x['versionsuffix'] == vsuff
                ]
                table_values[-1].append(', '.join('``%s``' % tc
                                                  for tc in sorted(nub(tcs))))

            lines.extend([
                '',
                '.. _%s:' % key_to_ref(key),
                '',
                '*%s*' % key,
                '+' * (len(key) + 2),
                '',
                ' '.join(software[key][-1]['description'].split('\n')).lstrip(
                    ' '),
                '',
                "*homepage*: %s" % software[key][-1]['homepage'],
                '',
            ] + rst_title_and_table(None, table_titles, table_values))
        else:
            lines.append("* %s" % key)

    return '\n'.join(lines)