{% extends "_base.html" %}

{% block titlecontent %}{{pkg.name }} – {{ super() }} {% endblock titlecontent %}

{% block favicon_url -%}
    {{ url_for('status_svg', status=pkg.status) }}?{{ cache_tag }}
{%- endblock favicon_url %}

{% macro related_block(name, icon, packages, nonpy=None) %}
    <h4>{{ name }} <i class="fa fa-{{ icon }}"></i></h4>
    {% if packages %}
        {{ progress_legend(packages.values(), kind='Python 2') }}
        <table class="table table-striped table-condensed table-hovered">
            {{ pkglist_table_content(packages.values(), show_nonblocking=1) }}
        </table>
    {% else %}
        <div>No Python 2 packages.</div>
    {% endif %}

    {% if nonpy %}
        {{ nonpy | length }} non-Python packages:
        <ul>
            {% for name in nonpy | sort %}
                <li>
                    {{ name }}
                    ({{ nonpython_package_links(name) }})
                </li>
            {% endfor %}
        </ul>
    {% endif %}
{% endmacro %}

{% macro related_packages(runtime, buildtime, tree, nonpy={}) %}
    {{ related_block('Run time', 'rocket', runtime, nonpy.get('run_time')) }}
    {{ related_block('Build time', 'wrench', buildtime, nonpy.get('build_time')) }}
    {% if tree %}
        <h3>Dependency Tree</h3>
        {{ print_deptree(tree) }}
    {% endif %}
{% endmacro %}

{% macro rpm_leaf_badge(rpm) %}
    {% if rpm.almost_leaf %}
    <span class="badge"
          style="background-color: #444 !important;
                 color: {% if rpm.legacy_leaf %}#fd3{% else %}#ddd{% endif %};"
          title="The RPM is not required by other packages in Fedora
            {%- if not rpm.legacy_leaf %} (except sibling subpackages)
            {%- endif -%}
            {%- if pkg.status == "legacy-leaf" %} and can be dropped if the maintainer wishes
            {%- endif -%}
    "><i class="fa fa-leaf"></i></span>
    {% endif %}
{% endmacro %}

{% macro buglink(bug) %}
    <a href="{{ bug.url }}">#{{ bug.id }} {{ bug.short_desc }}</a>
    {% if bug.trackers %}
        <small>
            (for {% for tracker in bug.trackers | sort -%}
                <a href="https://bugzilla.redhat.com/show_bug.cgi?id={{ tracker }}"
                >{{ tracker }}</a>
                {%- if not loop.last %}, {% endif -%}
            {% endfor %})
        </small>
    {% endif %}
{% endmacro %}

{% block bodycontent %}
    <div class="container">
        <div class="col-md-12">
            <h1>Package {{ pkg.name }} </h1>
            <div style="border-left: 4px solid #{{pkg.status_obj.color}}; padding-left: 4px; ">
                {{ pkg.status_obj.instructions | md }}
            </div>
            <br>
            {% if pkg['is_misnamed'] %}
                <div>
                    {{ misnamed_badge() }}
                    This package does not conform to Fedora's Python naming guidelines.
                    See individual RPMs below.
                </div>
                <br>
            {% endif %}
            {% if pkg.unversioned_requires %}
                <div>
                    {{ unversioned_requires_badge(blocked=False) }}
                    This package has Ambiguous Requires (or BuildRequires):
                    it uses unversioned <code>python</code>, rather than
                    <code>python2</code> or <code>python3</code>,
                    to refer to other packages.
                    The Python version should always be given explicitly.
                </div>
                {% if pkg.blocked_requires %}
                    <div>
                        {{ unversioned_requires_badge(pkg.blocked_requires) }}
                        Note that some required packages may not provide the
                        necessary versioned Provides yet.
                    </div>
                {% endif %}
                <br>
            {% endif %}
            {%- if 'orphan' in pkg['maintainers'] -%}
                <div>
                    <i class="fa fa-power-off" title="The package is orphaned."></i>
                    This package is
                    <a href="https://fedoraproject.org/wiki/Orphaned_package_that_need_new_maintainers">orphaned</a>.
                    It will be removed from Fedora if no one steps up to
                    maintain it.
                    {% if 'last_repo_metadata_change' in pkg %}
                        <br>
                        {{ orphan_clock_badge(pkg) }}
                        It is orphaned (at least) since
                        <time
                            datetime="{{ pkg['last_repo_metadata_change']}}"
                            title="{{ pkg['last_repo_metadata_change']}}"
                        >
                            {{ pkg['last_repo_metadata_change'] | format_time_ago -}}
                        </time>.
                        Check the
                        <a href="https://churchyard.fedorapeople.org/orphans.txt">
                            orphan report
                        </a>
                        for details.
                    {% endif %}
                </div>
                <br>
            {%- endif -%}
            {% if pkg.ftbfs_age %}
                <div>
                    {{ ftbfs_badge(pkg) }}
                    From the RPM names, it looks like this package was last
                    built for Fedora {{ pkg.last_build_releasever }},
                    and it FTBFS (fails to build from source) since then.
                </div>
                <br>
            {% endif %}
            {%- for grp in pkg['groups'].values() -%}
                {%- if 'exception' in grp and not grp['hidden'] and pkg['name'] in grp['seed_packages'] -%}
                    <div>
                        <a href="{{ url_for('group', grp=grp['ident']) }}" title="This package has a FESCo exception for {{ grp['name'] }}">
                            <i class="fa fa-thumb-tack"></i>
                        </a>
                        This package has a <a href="{{ grp['exception'] }}">FESCo exception</a> to stay on Python 2.
                        See the <a href="{{ url_for('group', grp=grp['ident']) }}">{{ grp['name'] }}</a> group.
                    </div>
                    <br>
                {%- endif -%}
            {%- endfor -%}
            <div>
                <img src="https://fedoraproject.org/static/images/favicon.ico">
                See
                <a href="https://src.fedoraproject.org/rpms/{{ pkg.name }}/">
                    {{ pkg.name }}</a>
                in the Fedora Pagure, or go directly to the corresponding
                <a href="https://src.fedoraproject.org/rpms/{{ pkg.name }}/blob/rawhide/f/{{ pkg.name }}.spec">spec file</a>.
            </div>
        </div>
        <div class="col-md-3">
                {% if pkg['bugs'] %}
                    <div>
                        <h3>Bugs</h3>
                        <ul class="pkg-link-list fa-ul">
                            {% for id, bug in pkg['bugs'].items() %}
                                <li>
                                    {{ bugicon(bug, 'fa-li') }}
                                    {{ buglink(bug) }}
                                    <div>
                                        <small>
                                            {{ bug.status }}
                                            {{ bug.resolution }}
                                        </small>
                                    </div>
                                    <div>
                                        <small>
                                            Updated
                                            <span title="{{ bug.last_change }}">
                                                {{ bug.last_change.date() }}
                                            </span>
                                        </small>
                                    </div>
                                </li>
                            {% endfor %}
                        </ul>
                    </div>
                {% endif %}
                {% set pc = pkg %}
                {% if pc %}
                    {% if 'note' in pc %}
                        <div>
                            <h3>Note</h3>
                            {{ pc.note | md }}
                        </div>
                    {% endif %}
                    {% if pc.rpms %}
                        <div>
                            <h3>RPMs</h3>
                            <ul class="rpm-list">
                            {% for rpm_name, rpm in pc.rpms.items() %}
                                <li>
                                    {{ rpm_name | format_rpm_name }}
                                    {% if rpm.get('arch') == 'src' %}
                                        <span class="fa fa-wrench" title="SRPM"></span>
                                    {% endif %}
                                    {% if rpm.get('is_misnamed') %}
                                    <span class="naming-badge"
                                          style="background-color: #F0AD4E !important;"
                                          title="The RPM name does not comply with Python package naming guidelines"
                                    ></span>
                                    {% endif %}
                                    {{ rpm_leaf_badge(rpm) }}
                                    <ul class="fa-ul">
                                        {% for pydep, ver in rpm.get('py_deps', {}).items() %}
                                            <li>
                                                {% if ver == 3 %}
                                                    <span class="fa fa-li">✔</span>
                                                {% elif ver == 2 %}
                                                    <span class="fa fa-li">×</span>
                                                {% else %}
                                                    <span class="fa fa-li"> </span>
                                                {% endif %}
                                                {{ pydep }}
                                                {% if pydep == '/usr/bin/python' %}
                                                    <span class="badge"
                                                        style="background-color: #F0AD4E !important;"
                                                        title="Scripts should explicitly use /usr/bin/python3 or /usr/bin/python2, especially in shebangs"
                                                    >⅔</span>
                                                {% endif %}
                                            </li>
                                        {% endfor %}
                                    </ul>
                                </li>
                            {% endfor %}
                            </ul>
                        </div>
                    {% endif %}
                    {% if pkg.unversioned_requires %}
                        <div>
                            <h3>Ambiguous Requires</h3>
                            {{ unversioned_requires_badge(pkg['blocked_requires']) }}
                            This package has ambiguous (Build)Requires for:
                            <ul class='simple-pkg-list'>
                                {% for name, p in pkg.unversioned_requires.items() | sort %}
                                    <li>
                                        {{ pkglink(p) }}
                                    </li>
                                {% endfor %}
                            </ul>
                        </div>
                    {% endif %}
                    {% if pc.get('links') %}
                        <div>
                            <h3>Links</h3>
                            <ul class="pkg-link-list fa-ul">
                                {% for link in pc.get('links', ()) %}
                                    <li>
                                        <i class="fa-li {{ iconlink_class(link) }}"></i>
                                        {{ link.type }}:
                                        <a href="{{ link.url }}">{{ link.url }}</a>
                                        {% if link.note %}
                                            ({{ link.note }})
                                        {% endif %}
                                        {% if link.last_update %}
                                            <br/>
                                            Last activity:
                                            <time style="font-style: italic;"
                                                    title="{{ link.last_update }}">
                                                {{ link.last_update | format_time_ago }}
                                            </time>
                                        {% endif %}
                                    </li>
                                {% endfor %}
                            </ul>
                        </div>
                    {% endif %}
                {% endif %}
            {% if pkg['groups'] %}
                <h3>Groups</h3>
                <ul>
                    {% for grp in pkg.groups.values() | sort(attribute='name') %}
                        <li>
                            <a href="{{ url_for('group', grp=grp.ident) }}">
                                {{ grp.name }}
                            </a>
                        </li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if pkg['maintainers'] %}
                <h3>Maintainers</h3>
                <ul>
                    {% for name, maintainer in pkg['maintainers'].items() | sort %}
                        <li>
                            {{ maintainer_link(maintainer) }}
                        </li>
                    {% endfor %}
                </ul>
            {% endif %}
        </div>
        {% if pkg['deps']
           or pkg['build_deps']
           or pkg['dependents']
           or pkg['build_dependents']
           or pkg['non_python_requirers']
        %}
            <div class="col-md-4 related-packages">
                <h2>Dependencies</h2>
                {{ related_packages(
                    pkg['deps'],
                    pkg['build_deps'],
                    deptree,
                ) }}
            </div>
            <div class="col-md-4 related-packages">
                <h2>Dependents</h2>
                {{ related_packages(
                    pkg['dependents'],
                    pkg['build_dependents'],
                    dependent_tree,
                    nonpy=pkg['non_python_requirers'],
                ) }}
            </div>
        {% endif %}
    </div>
{% endblock bodycontent %}
