#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
import fnmatch
import re
# In order to keep track of what publisher is presently the preferred publisher,
# a prefix is included ahead of the name of the publisher. If this prefix is
# present, the publisher is considered to be the current preferred publisher for
# the image. This is where we define the prefix, since it's used primarily in
# the FMRI. PREF_PUB_PFX => preferred publisher prefix.
#
# For is_same_publisher(), we need a version of this constant with the
# trailing _ attached.
#
g_valid_pkg_name = \
"""Base exception class for FMRI errors."""
"""Used to indicate that the requested operation is not supported for
the fmri since version information is missing."""
return _("FMRI '{0}' is missing version information.").format(
"""The publisher is the anchor of a package namespace. Clients can
choose to take packages from multiple publishers, and specify a default
search path. In general, package names may also be prefixed by a domain
name, reverse domain name, or a stock symbol to avoid conflict. The
unprefixed namespace is expected to be managed by architectural review.
The primary equivalence relationship assumes that packages of the same
package name are forwards compatible across all versions of that
package, and that higher build release versions are superior
publications than lower build release versions."""
# Stored in a class variable so that subclasses can override
if fmri is not None:
if pubidx != None:
# Always use publisher information provided in
# FMRI string. (It could be ""; pkg:///name is
# valid.)
if veridx != None:
try:
except VersionError as iv:
raise IllegalFmri(fmri,
else:
else:
# pkg_name and version must be explicitly set.
if version:
else:
# Ensure publisher is always None if one was not specified.
if publisher:
else:
detail="Missing package name")
"""Returns the serialized state of this object in a format
that that can be easily stored using JSON, pickle, etc."""
"""Allocate a new object using previously serialized state
obtained via getstate()."""
"""Return a tuple of offsets, used to extract different
components of the FMRI."""
if veridx == -1:
veridx = None
pubidx = None
if nameidx == -1:
raise IllegalFmri(fmri,
detail=_("Missing '/' after "
"publisher name"))
# Publisher starts after //.
pubidx = 6
# Name starts after / which terminates publisher
nameidx += 1
# Name starts after / which terminates scheme
nameidx = 5
if nameidx == -1:
raise IllegalFmri(fmri,
detail=_("Missing '/' after "
"publisher name"))
# Publisher starts after //.
pubidx = 2
# Name starts after / which terminates publisher
nameidx += 1
# Name starts after / which terminates scheme
nameidx = 1
else:
nameidx = 0
"""Return the name of the publisher that is contained
within this FMRI. This strips off extraneous data
that may be attached to the publisher. The output
is suitable as a key into the publisher["prefix"] table."""
# Strip off preferred publisher prefix, if it exists.
a = r[len(r) - 1]
return a
# Otherwise just return the publisher
"""Set the FMRI's publisher. If this is a preferred
publisher, set preferred to True."""
else:
return self
"""Returns true if the FMRI has a publisher."""
return True
return False
"""Returns True if the FMRI has a version"""
return True
return False
"""Returns true if this FMRI's publisher is the preferred
publisher."""
return True
return False
"""Return the bare string that specifies everything about
the publisher. This should only be used by code that
must write out (or restore) the complete publisher
information to disk."""
"""Return a string representation of the FMRI without a specific
version. Anarchy returns a stem without any publisher."""
pkg_str = ""
if include_scheme:
pkg_str = "pkg:/"
if include_scheme:
pkg_str = "pkg://"
"""Return a string representation of the FMRI without a specific
version."""
pkg_str = ""
if not publisher:
version = ""
else:
anarchy):
if include_scheme:
pkg_str = "pkg:/"
if include_scheme:
pkg_str = "pkg://"
"""Return a string representation of the FMRI.
Anarchy returns a string without any publisher."""
pkg_str = ""
if publisher == None:
or anarchy:
if include_scheme:
pkg_str = "pkg:/"
if include_scheme:
pkg_str = "pkg://"
"""Generate the different hierarchical names that could be used
to reference this fmri."""
return res
"""Return as specific an FMRI representation as possible."""
"""Return as specific an FMRI representation as possible."""
else:
else:
#
# __hash__ need not generate a unique hash value for all
# possible objects-- it must simply guarantee that two
# items which are equal (i.e. a = b) always hash to
# the same value.
#
if h is None:
return h
if not other:
return False
return False
return True
return False
if not other:
return False
return True
return True
return False
return True
return False
return True
return False
return False
if not other:
return True
return False
return True
return False
return True
return False
return True
return False
return False
"""Return the escaped link (or file) path fragment for this
FMRI."""
if stemonly:
raise MissingVersionError(self)
"""Return the escaped directory path fragment for this FMRI."""
if stemonly:
raise MissingVersionError(self)
"""Return the escaped URL path fragment for this FMRI.
Requires a version to be defined."""
raise MissingVersionError(self)
"""Return true if these packages are the same (although
potentially of different versions.)"""
"""True if the regular expression given in fmristr matches the
stem of this pkg: FMRI."""
return m != None
"""True if package names match exactly. Not a pattern-based
query."""
""" returns True if self >= other """
# Fastest path for most common case.
return False
return True
return False
return True
""" A subclass of PkgFmri with (much) weaker rules about package names.
This is intended to accept user input with globbing characters. """
try:
except IllegalFmri as e:
"""Returns true if 'pattern' is a proper subset of 'pkg_name'."""
"""Returns true if 'pattern' is a regular expression matching
'pkg_name'."""
"""Returns true if 'pattern' matches 'pkg_name' exactly."""
"""Given a string that can be converted to a FMRI. Return the
substring that is the FMRI's pkg_name."""
if veridx:
else:
return pkg_name
"""Strip the PREF_PUB_PFX off of a publisher."""
else:
return outstr
"""Compare two publishers. Return true if they are the same, false
otherwise. """
#
# This code is performance sensitive. Ensure that you benchmark
# changes to it.
#
# Fastest path for most common case.
return True
if pub1 == None:
pub1 = ""
if pub2 == None:
pub2 = ""
# String concatenation and string equality are both pretty fast.
return True
return True
return False