shared.shtml revision 3339
1N/A## -*- coding: utf-8 -*-
1N/A##
1N/A## CDDL HEADER START
1N/A##
1N/A## The contents of this file are subject to the terms of the
1N/A## Common Development and Distribution License (the "License").
1N/A## You may not use this file except in compliance with the License.
1N/A##
1N/A## You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A## or http://www.opensolaris.org/os/licensing.
1N/A## See the License for the specific language governing permissions
1N/A## and limitations under the License.
1N/A##
1N/A## When distributing Covered Code, include this CDDL HEADER in each
1N/A## file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A## If applicable, add the following below this CDDL HEADER, with the
1N/A## fields enclosed by brackets "[]" replaced with your own identifying
1N/A## information: Portions Copyright [yyyy] [name of copyright owner]
1N/A##
1N/A## CDDL HEADER END
1N/A##
1N/A## Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
1N/A##
1N/A<%!
1N/A import six
1N/A import operator
1N/A%>
1N/A## Returns the value of the named respository configuration property in the
1N/A## given section.
1N/A<%def name="dcval(g_vars, section, name)"><%
1N/A return g_vars["config"].get_depot_property_value(section, name)
1N/A%></%def>\
1N/A<%def name="rcval(g_vars, section, name)"><%
1N/A return g_vars["config"].get_repo_property_value(section, name)
1N/A%></%def>\
1N/A## Returns the relative URI path to the named resource.
1N/A<%def name="rpath(g_vars, name)"><%
1N/A return g_vars["request"].get_rel_path(name)
1N/A%></%def>\
1N/A## Returns path relative to the current request path for the current locale
1N/A## and region.
1N/A<%def name="lrelpath(g_vars, path)"><%
1N/A return g_vars["request"].get_rel_path(path)[len("../"):]
1N/A%></%def>\
1N/A## Returns a list of tuples containing a pkg.Version object, a string
1N/A## representing the version, and a label for that version. Entries are
1N/A## sorted by release and branch in descending order.
1N/A<%def name="get_releases(g_vars)"><%
1N/A catalog = g_vars["catalog"]
1N/A request = g_vars["request"]
1N/A versions = {}
1N/A for f, states, attrs in catalog.gen_packages(patterns=["/entire",
1N/A "/solaris"],
1N/A return_fmris=True):
1N/A br = str(f.version.branch).replace(".", "").strip()
1N/A ver_label = "{0}-{1}".format(f.version.release,
1N/A f.version.branch)
1N/A if br == "086":
1N/A ver_label = "2008.05 ({0})".format(ver_label)
1N/A elif br == "0101":
1N/A ver_label = "2008.11 ({0})".format(ver_label)
elif br == "0111":
ver_label = "2009.06 ({0})".format(ver_label)
entry = "{0}@{1},{2}-{3}".format(f.pkg_name, f.version.release,
f.version.build_release, f.version.branch)
versions[entry] = (f.version, entry, ver_label)
return [
ver[1] for ver in
sorted(six.iteritems(versions), key=operator.itemgetter(1),
reverse=True)
]
%></%def>\
## Returns a uri, relative to the current request path to the given resource
## based on the current theme, that is not locale or region specific.
<%def name="tpath(g_vars, resource)"><%
return g_vars["request"].get_rel_path("_themes/{0}/{1}".format(
g_vars["web_config"]["theme"], resource))
%></%def>\
## Returns the %include path to the given resource based on the current theme,
## locale, and region information.
<%def name="ltipath(g_vars, resource)"><%
return "/_themes/{0}/{1}/{2}".format(g_vars["web_config"]["theme"],
g_vars["web_config"]["locale-region"], resource)
%></%def>\
## Returns a uri, relative to the current request path, to the given resource
## based on the current locale and region information.
<%def name="ltupath(g_vars, resource)"><%
path = "_themes/{0}/{1}/{2}".format(g_vars["web_config"]["theme"],
g_vars["web_config"]["locale-region"], resource)
return g_vars["request"].get_rel_path(path)
%></%def>\