Current File : //usr/share/lib/pkg/web/en/catalog.shtml
## -*- coding: utf-8 -*-
##
##
## Copyright 2009, 2013 Oracle and/or its affiliates. All rights reserved.
##
<%!
        import pkg.fmri
        import urllib
%>\
<%inherit file="layout.shtml"/>\
<%page args="g_vars"/>\
<%
        catalog = g_vars["catalog"]
        config = g_vars["config"]
        request = g_vars["request"]
%>\
<%def name="page_title(g_vars)"><%
        return "Package Catalog"
%></%def>\
<div id="yui-main">
        <div class="yui-b">
% if config.mirror:
                <p>Information about packages is not available when the server
 is operating in mirror mode.</p>
% elif not request.publisher:
                <p>This package repository is empty or no default publisher has
 been set.</p>
% else:
<%
        versions = self.shared.get_releases(g_vars)
        if versions:
                # Add an "All" selection so that user can view entire catalog.
                versions.insert(0, ("", "", "All"))

        selected_val = request.params.get("version", None)
        show_all_versions = request.params.get("show_all_versions", None)
        show_obsolete = request.params.get("show_obsolete", None)
        show_renamed = request.params.get("show_renamed", None)
        selected_match = None
        selected_pkg = None
        if selected_val:
                for v in versions:
                        ver, val, label = v
                        if selected_val == val:
                                selected_match = ver
                                selected_pkg = val.split("@")[0]
                                break

        if versions and selected_val != "" and not selected_match:
                # Either a version wasn't already selected, or the version
                # provided didn't match a valid one, so default to the first in
                # the list.
                selected_match = versions[1][0]
                selected_val = versions[1][1]
                selected_pkg = selected_val.split("@")[0]
%>
%       if versions:
                <form action="catalog.shtml">
                        <p>
                                <label for="version">Release and Branch</label>
                                <select id="version" name="version">
<%
                for v in versions:
                        ver, val, label = v
                        attrs = ""
                        if val == selected_val:
                                attrs = 'selected="selected" '

                        context.write("""<option %svalue="%s">%s</option>""" % (
                            attrs, val, label))
%>
                                </select>
                                <input id="submit-browse" type="submit"
                                    name="action" value="Browse"/>
                        </p>
                        <p>
                                <input id="show-all-versions" type="checkbox"
%                       if show_all_versions:
                                    checked="checked"
%                       endif
                                    name="show_all_versions" value="1"/>
                                <label for="show-all-versions" title="By
 default, only the latest versions of packages are shown.  To show all versions,
 check this checkbox.">Show all versions</label>
                                <input id="show-obsolete" type="checkbox"
%                       if show_obsolete:
                                    checked="checked"
%                       endif
                                    name="show_obsolete" value="1"/>
                                <label for="show-obsolete" title="By
 default, obsolete packages are not shown.  To show obsolete
 packages, check this checkbox.">Show obsolete packages</label>
                                <input id="show-renamed" type="checkbox"
%                       if show_renamed:
                                    checked="checked"
%                       endif
                                    name="show_renamed" value="1"/>
                                <label for="show-renamed" title="By
 default, renamed packages are not shown.  To show renamed
 packages, check this checkbox.">Show renamed packages</label>
                        </p>
                </form>
%       else:
                <form action="catalog.shtml">
                        <p>
                                <input id="show-all-versions" type="checkbox"
%                       if show_all_versions:
                                    checked="checked"
%                       endif
                                    name="show_all_versions" value="1"/>
                                <label for="show-all-versions" title="By
 default, only the latest versions of packages are shown.  To show all versions,
 check this checkbox and click Refresh.">Show all versions</label>
                                <input id="show-obsolete" type="checkbox"
%                       if show_obsolete:
                                    checked="checked"
%                       endif
                                    name="show_obsolete" value="1"/>
                                <label for="show-obsolete" title="By
 default, obsolete packages are not shown.  To show obsolete
 packages, check this checkbox.">Show obsolete packages</label>
                                <input id="show-renamed" type="checkbox"
%                       if show_renamed:
                                    checked="checked"
%                       endif
                                    name="show_renamed" value="1"/>
                                <label for="show-renamed" title="By
 default, renamed packages are not shown.  To show renamed
 packages, check this checkbox.">Show renamed packages</label>
                                <input id="submit-browse" type="submit"
                                    name="action" value="Refresh"/>
                        </p>
                </form>
%       endif
        </div>
        <div class="yui-b results">
                <table summary="A list of packages available in the repository
 restricted by the specified listing criteria.">
                        <tr class="first">
                                <th scope="row">Name</th>
                                <th>Version</th>
                                <th>Install</th>
                                <th>Manifest</th>
                        </tr>
<%
        # Output each FMRI that we have in the catalog.
        flist = []
        if selected_val and selected_match:
                ver = selected_match
                pfmri = pkg.fmri.PkgFmri(name=selected_pkg,
                    publisher=request.publisher.prefix,
                    version=str(ver))
                flist = catalog.gen_allowed_packages([pfmri])
        else:
                # Entries need to be in descending version order.
                flist = (
                    (pfmri, states)
                    for (pfmri, states, attrs) in catalog.gen_packages(
                        return_fmris=True)
                )

        found = set()
        omit_stems = set()
        rclass = None
        total = 0
%>
%       for pfmri, states in flist:
        <%
                pkg_name = pfmri.pkg_name
                if not show_all_versions and pkg_name in found:
                        continue

                # For renames and obsoletes, only use package state for the
                # latest version.
                if states:
                        # The pkg_name should only be added to the list of stems
                        # to omit if the latest version of the package listed is
                        # renamed or obsolete.  If not all versions are being
                        # shown, then this is the latest version.
                        if not (show_renamed or show_obsolete):
                                # Only possible states are OBSOLETE or RENAMED.
                                if not show_all_versions or \
                                    pkg_name not in found:
                                        omit_stems.add(pkg_name)
                                        found.add(pkg_name)
                                continue
                        if not show_obsolete and \
                            catalog.PKG_STATE_OBSOLETE in states:
                                if not show_all_versions or \
                                    pkg_name not in found:
                                        omit_stems.add(pkg_name)
                                        found.add(pkg_name)
                                continue
                        if not show_renamed and \
                            catalog.PKG_STATE_RENAMED in states:
                                if not show_all_versions or \
                                    pkg_name not in found:
                                        omit_stems.add(pkg_name)
                                        found.add(pkg_name)
                                continue

                if show_all_versions and pkg_name in omit_stems:
                        # Terminal version found that is allowed by selected
                        # filter criteria; so omit all versions of that package.
                        continue

                found.add(pkg_name)
                total += 1
                if rclass is None or rclass == ' class="odd"':
                        rclass = ""
                else:
                        rclass = ' class="odd"'

                # Start FMRI entry
                phref = self.shared.rpath(g_vars, "info/0/%s" % (
                    urllib.quote(str(pfmri), "")))
                # XXX the .p5i extension is a bogus hack because
                # packagemanager requires it and shouldn't.
                p5ihref = self.shared.rpath(g_vars, "p5i/0/%s.p5i" % (
                    urllib.quote(pfmri.pkg_name, ""))) 
                mhref = self.shared.rpath(g_vars,
                    "manifest/0/%s" % (pfmri.get_url_path()))
%>
                        <tr${rclass}>
                                <td scope="row">
                                        <a title="Package Information Summary"
                                            href="${phref}">${pfmri.pkg_name}</a>
                                </td>
                                <td>${pfmri.version}</td>
                                <td>
%               if not show_obsolete or catalog.PKG_STATE_OBSOLETE not in states:
                                        <a class="p5i"
                                            title="Launch the Package Manager and install this package"
                                            href="${p5ihref}">Install</a>
%               else:
                                        &nbsp;
%               endif
                                </td>
                                <td>
                                        <a title="Package Manifest"
                                            href="${mhref}">Manifest</a>
                                </td>
                        </tr>
%       endfor
                        <tr class="last">
                                <td colspan="4" scope="row">${total} package(s)</td>
                        </tr>
                </table>
% endif
        </div>
</div>