api_errors.py revision 2158
1516N/A#!/usr/bin/python
565N/A#
565N/A# CDDL HEADER START
565N/A#
565N/A# The contents of this file are subject to the terms of the
565N/A# Common Development and Distribution License (the "License").
565N/A# You may not use this file except in compliance with the License.
565N/A#
565N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
565N/A# or http://www.opensolaris.org/os/licensing.
565N/A# See the License for the specific language governing permissions
565N/A# and limitations under the License.
565N/A#
565N/A# When distributing Covered Code, include this CDDL HEADER in each
565N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
565N/A# If applicable, add the following below this CDDL HEADER, with the
565N/A# fields enclosed by brackets "[]" replaced with your own identifying
565N/A# information: Portions Copyright [yyyy] [name of copyright owner]
565N/A#
565N/A# CDDL HEADER END
565N/A#
926N/A
926N/A#
2614N/A# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
926N/A#
565N/A
2026N/Aimport errno
1050N/Aimport os
2524N/Aimport urlparse
926N/A
926N/A# EmptyI for argument defaults; can't import from misc due to circular
2339N/A# dependency.
2339N/AEmptyI = tuple()
2339N/A
926N/Aclass ApiException(Exception):
926N/A def __init__(self, *args):
926N/A Exception.__init__(self)
838N/A self.__verbose_info = []
565N/A
2034N/A def __unicode__(self):
2034N/A # To workaround python issues 6108 and 2517, this provides a
2034N/A # a standard wrapper for this class' exceptions so that they
1540N/A # have a chance of being stringified correctly.
1540N/A return unicode(str(self))
1540N/A
1540N/A def add_verbose_info(self, info):
1540N/A self.__verbose_info.extend(info)
1968N/A
1540N/A @property
2034N/A def verbose_info(self):
2034N/A return self.__verbose_info
2200N/A
2034N/Aclass ImageLockedError(ApiException):
2034N/A """Used to indicate that the image is currently locked by another thread
2034N/A or process and cannot be modified."""
565N/A
2339N/A def __init__(self, hostname=None, pid=None, pid_name=None):
2339N/A ApiException.__init__(self)
2339N/A self.hostname = hostname
2339N/A self.pid = pid
2339N/A self.pid_name = pid_name
2339N/A
2524N/A def __str__(self):
2524N/A if self.pid is not None and self.pid_name is not None and \
2524N/A self.hostname is not None:
2524N/A return _("The image cannot be modified as it is "
2524N/A "currently in use by another package client: "
2524N/A "%(pid_name)s on %(host)s, pid %(pid)s.") % {
2524N/A "pid_name": self.pid_name, "pid": self.pid,
2524N/A "host": self.hostname }
2524N/A if self.pid is not None and self.pid_name is not None:
2524N/A return _("The image cannot be modified as it is "
2524N/A "currently in use by another package client: "
2524N/A "%(pid_name)s on an unknown host, pid %(pid)s.") % {
2524N/A "pid_name": self.pid_name, "pid": self.pid }
2524N/A elif self.pid is not None:
2524N/A return _("The image cannot be modified as it is "
2524N/A "currently in use by another package client: "
2524N/A "pid %(pid)s on %(host)s.") % {
2524N/A "pid": self.pid, "host": self.hostname }
2524N/A return _("The image cannot be modified as it is currently "
2524N/A "in use by another package client.")
2524N/A
2524N/Aclass ImageNotFoundException(ApiException):
2524N/A """Used when an image was not found"""
2524N/A def __init__(self, user_specified, user_dir, root_dir):
2524N/A ApiException.__init__(self)
2524N/A self.user_specified = user_specified
2524N/A self.user_dir = user_dir
2524N/A self.root_dir = root_dir
2524N/A
2524N/A
2524N/Aclass ImageLocationAmbiguous(ApiException):
2524N/A """Used to indicate that an image was found at a location other than
2524N/A '/' on the Solaris platform when requesting automatic image location
2524N/A discovery. Clients should trap this exception and add their own
2524N/A messaging telling the user how to specify an image root explicitly
2524N/A for the location."""
2524N/A
2524N/A def __init__(self, root, live_root="/"):
2524N/A ApiException.__init__(self)
2524N/A self.root = root
2524N/A self.live_root = live_root
2524N/A
2524N/A def __str__(self):
2524N/A return _("pkg(5) image found at '%(found)s' instead of "
2524N/A "'%(expected)s'.") % { "found": self.root,
2524N/A "expected": self.live_root }
2524N/A
2524N/A
2524N/Aclass ImageFormatUpdateNeeded(ApiException):
1710N/A """Used to indicate that an image cannot be used until its format is
1710N/A updated."""
1710N/A
1710N/A def __init__(self, path):
1710N/A ApiException.__init__(self)
1710N/A self.path = path
1710N/A
1710N/A def __str__(self):
1710N/A return _("The image rooted at %s is written in an older format "
1710N/A "and must be updated before the requested operation can be "
1710N/A "performed.") % self.path
1710N/A
1710N/A
1710N/Aclass VersionException(ApiException):
1710N/A def __init__(self, expected_version, received_version):
1710N/A ApiException.__init__(self)
1710N/A self.expected_version = expected_version
1710N/A self.received_version = received_version
1710N/A
1710N/A
1710N/Aclass PlanExistsException(ApiException):
1710N/A def __init__(self, plan_type):
1710N/A ApiException.__init__(self)
1710N/A self.plan_type = plan_type
1710N/A
1710N/A
1710N/Aclass PlanPrepareException(ApiException):
1710N/A """Base exception class for plan preparation errors."""
1710N/A pass
1710N/A
1710N/A
565N/Aclass InvalidPackageErrors(ApiException):
565N/A """Used to indicate that the requested operation could not be completed
565N/A as one or more packages contained invalid metadata."""
565N/A
565N/A def __init__(self, errors):
565N/A """'errors' should be a list of exceptions or strings
565N/A indicating what packages had errors and why."""
565N/A
2144N/A ApiException.__init__(self)
2144N/A self.errors = errors
2144N/A
2144N/A def __str__(self):
2144N/A return _("The requested operation cannot be completed due "
2144N/A "to invalid package metadata. Details follow:\n\n"
2144N/A "%s") % "\n".join(str(e) for e in self.errors)
2144N/A
2144N/A
2144N/Aclass LicenseAcceptanceError(ApiException):
2144N/A """Used to indicate that license-related errors occurred during
2144N/A plan evaluation or execution."""
2144N/A
2144N/A def __init__(self, pfmri, src=None, dest=None, accepted=None,
2407N/A displayed=None):
2407N/A ApiException.__init__(self)
2407N/A self.fmri = pfmri
2407N/A self.src = src
2407N/A self.dest = dest
2407N/A self.accepted = accepted
2407N/A self.displayed = displayed
2407N/A
2407N/A
2407N/Aclass PkgLicenseErrors(PlanPrepareException):
2407N/A """Used to indicate that plan evaluation or execution failed due
2407N/A to license-related errors for a package."""
2407N/A
2407N/A def __init__(self, errors):
2407N/A """'errors' should be a list of LicenseAcceptanceError
2407N/A exceptions."""
2144N/A
565N/A PlanPrepareException.__init__(self)
565N/A self.__errors = errors
565N/A
565N/A @property
565N/A def errors(self):
565N/A """A list of LicenseAcceptanceError exceptions."""
2144N/A return self.__errors
565N/A
565N/A
565N/Aclass PlanLicenseErrors(PlanPrepareException):
565N/A """Used to indicate that image plan evaluation or execution failed due
565N/A to license-related errors."""
1618N/A
1618N/A def __init__(self, pp_errors):
1618N/A """'errors' should be a list of PkgLicenseErrors exceptions."""
1618N/A
1618N/A PlanPrepareException.__init__(self)
1618N/A self.__errors = pkgs = {}
1755N/A for pp_err in pp_errors:
1755N/A for e in pp_err.errors:
1755N/A pkgs.setdefault(str(e.fmri), []).append(e)
1755N/A
1755N/A @property
1755N/A def errors(self):
1755N/A """Returns a dictionary indexed by package FMRI string of
1755N/A lists of LicenseAcceptanceError exceptions."""
1755N/A
1755N/A return self.__errors
1755N/A
1755N/A def __str__(self):
1755N/A """Returns a string representation of the license errors."""
1755N/A
1755N/A output = ""
1755N/A for sfmri in self.__errors:
1755N/A output += ("-" * 40) + "\n"
1618N/A output += _("Package: %s\n\n") % sfmri
1618N/A for e in self.__errors[sfmri]:
1618N/A lic_name = e.dest.attrs["license"]
1618N/A output += _("License: %s\n") % lic_name
1618N/A if e.dest.must_accept and not e.accepted:
1618N/A output += _(" License requires "
1618N/A "acceptance.")
1618N/A if e.dest.must_display and not e.displayed:
1618N/A output += _(" License must be viewed.")
1618N/A output += "\n"
1618N/A return output
1618N/A
1618N/A
1618N/Aclass ActuatorException(ApiException):
1618N/A def __init__(self, e):
1618N/A ApiException.__init__(self)
1618N/A self.exception = e
1618N/A
1618N/A def __str__(self):
1618N/A return str(self.exception)
1618N/A
1618N/A
1618N/Aclass PrematureExecutionException(ApiException):
1618N/A pass
1618N/A
1618N/A
1618N/Aclass AlreadyPreparedException(PlanPrepareException):
1618N/A pass
1618N/A
1618N/A
1618N/Aclass AlreadyExecutedException(ApiException):
1618N/A pass
1618N/A
1618N/A
1618N/Aclass ImageplanStateException(ApiException):
1618N/A def __init__(self, state):
1618N/A ApiException.__init__(self)
1618N/A self.state = state
1618N/A
1618N/A
1618N/Aclass InvalidPlanError(ApiException):
1618N/A """Used to indicate that the image plan is no longer valid, likely as a
1618N/A result of an image state change since the plan was created."""
1618N/A
1618N/A def __str__(self):
1618N/A return _("The plan for the current operation is no longer "
1618N/A "valid. The image has likely been modified by another "
1618N/A "process or client. Please try the operation again.")
1618N/A
1618N/A
1618N/Aclass ImagePkgStateError(ApiException):
1618N/A
1618N/A def __init__(self, fmri, states):
1618N/A ApiException.__init__(self)
1618N/A self.fmri = fmri
1618N/A self.states = states
1618N/A
1618N/A def __str__(self):
1618N/A return _("Invalid package state change attempted '%(states)s' "
1618N/A "for package '%(fmri)s'.") % { "states": self.states,
1618N/A "fmri": self.fmri }
1618N/A
1618N/A
1618N/Aclass IpkgOutOfDateException(ApiException):
1618N/A pass
1618N/A
1618N/Aclass ImageUpdateOnLiveImageException(ApiException):
1618N/A pass
1618N/A
1618N/Aclass RebootNeededOnLiveImageException(ApiException):
1019N/A pass
1019N/A
1019N/Aclass CanceledException(ApiException):
1019N/A pass
1019N/A
1019N/Aclass PlanMissingException(ApiException):
1019N/A pass
1019N/A
1618N/Aclass NoPackagesInstalledException(ApiException):
565N/A pass
565N/A
565N/Aclass PermissionsException(ApiException):
1618N/A def __init__(self, path):
1618N/A ApiException.__init__(self)
565N/A self.path = path
565N/A
1618N/A def __str__(self):
565N/A if self.path:
565N/A return _("Could not operate on %s\nbecause of "
565N/A "insufficient permissions. Please try the "
1618N/A "command again as a privileged user.") % \
565N/A self.path
565N/A else:
565N/A return _("""
565N/ACould not complete the operation because of insufficient permissions.
565N/APlease try the command again as a privileged user.
1369N/A""")
1710N/A
1710N/Aclass FileInUseException(PermissionsException):
1710N/A def __init__(self, path):
1710N/A PermissionsException.__init__(self, path)
1710N/A assert path
1710N/A
1710N/A def __str__(self):
1710N/A return _("Could not operate on %s\nbecause the file is "
1710N/A "in use. Please stop using the file and try the\n"
1710N/A "operation again.") % self.path
1372N/A
1369N/A
1369N/Aclass ReadOnlyFileSystemException(PermissionsException):
1369N/A """Used to indicate that the operation was attempted on a
1369N/A read-only filesystem"""
1369N/A
1369N/A def __init__(self, path):
1369N/A ApiException.__init__(self)
1369N/A self.path = path
1372N/A
1372N/A def __str__(self):
1369N/A if self.path:
1369N/A return _("Could not complete the operation on %s: "
565N/A "read-only filesystem.") % self.path
565N/A return _("Could not complete the operation: read-only "
565N/A "filesystem.")
565N/A
565N/A
565N/Aclass PlanCreationException(ApiException):
1328N/A def __init__(self, unmatched_fmris=EmptyI, multiple_matches=EmptyI,
1328N/A missing_matches=EmptyI, illegal=EmptyI,
1328N/A badarch=EmptyI, installed=EmptyI, multispec=EmptyI,
565N/A no_solution=False, no_version=EmptyI, missing_dependency=EmptyI,
565N/A wrong_publishers=EmptyI, obsolete=EmptyI):
565N/A ApiException.__init__(self)
565N/A self.unmatched_fmris = unmatched_fmris
565N/A self.multiple_matches = multiple_matches
565N/A self.missing_matches = missing_matches
565N/A self.illegal = illegal
565N/A self.badarch = badarch
565N/A self.installed = installed
685N/A self.multispec = multispec
685N/A self.obsolete = obsolete
685N/A self.no_solution = no_solution
685N/A self.no_version = no_version
685N/A self.missing_dependency = missing_dependency
685N/A self.wrong_publishers = wrong_publishers
685N/A
926N/A def __str__(self):
2126N/A res = []
2126N/A if self.unmatched_fmris:
2126N/A s = _("""\
685N/AThe following pattern(s) did not match any packages in the current catalog.
685N/ATry relaxing the pattern, refreshing and/or examining the catalogs:""")
2126N/A res += [s]
2126N/A res += ["\t%s" % p for p in self.unmatched_fmris]
685N/A
685N/A if self.wrong_publishers:
879N/A s = _("The following patterns only matched packages "
879N/A "that are from publishers other than that which "
879N/A "supplied the already installed version of this package")
879N/A res += [s]
879N/A res += ["\t%s: %s" % (p[0], ", ".join(p[1])) for p in self.wrong_publishers]
879N/A
879N/A if self.multiple_matches:
879N/A s = _("'%s' matches multiple packages")
879N/A for p, lst in self.multiple_matches:
879N/A res.append(s % p)
1335N/A for pfmri in lst:
2612N/A res.append("\t%s" % pfmri)
2612N/A
2612N/A if self.missing_matches:
2612N/A s = _("'%s' matches no installed packages")
2612N/A res += [ s % p for p in self.missing_matches ]
2612N/A
2612N/A if self.illegal:
2612N/A s = _("'%s' is an illegal fmri")
2612N/A res += [ s % p for p in self.illegal ]
2612N/A
1335N/A if self.badarch:
1945N/A s = _("'%s' supports the following architectures: %s")
1335N/A a = _("Image architecture is defined as: %s")
1335N/A res += [ s % (self.badarch[0],
1335N/A ", ".join(self.badarch[1]))]
1335N/A res += [ a % (self.badarch[2])]
1335N/A
1335N/A s = _("'%(p)s' depends on obsolete package '%(op)s'")
1335N/A res += [ s % {"p": p, "op": op} for p, op in self.obsolete ]
1335N/A
1335N/A if self.installed:
1968N/A s = _("The proposed operation can not be performed for "
1335N/A "the following package(s) as they are already "
1335N/A "installed: ")
1335N/A res += [s]
1335N/A res += ["\t%s" % p for p in self.installed]
2301N/A
2510N/A if self.multispec:
2510N/A s = _("The following different patterns specify the"
2510N/A "same package(s):")
2301N/A res += [s]
2301N/A for t in self.multispec:
2301N/A res += [
2301N/A ", ".join(
2301N/A [t[i] for i in range(1, len(t))])
2301N/A + ": %s" % t[0]
2301N/A ]
2301N/A if self.no_solution:
2301N/A res += [_("No solution was found to satisfy constraints")]
2301N/A
2301N/A if self.no_version:
2301N/A res += self.no_version
2301N/A
2301N/A if self.missing_dependency:
2301N/A res += [_("Package %(pkg)s is missing a dependency: "
2301N/A "%(dep)s") %
2301N/A {"pkg": self.missing_dependency[0],
2301N/A "dep": self.missing_dependency[1]}]
2301N/A
2301N/A return "\n".join(res)
2301N/A
2301N/A
2301N/Aclass ActionExecutionError(ApiException):
2301N/A """Used to indicate that action execution (such as install, remove,
2301N/A etc.) failed even though the action is valid.
2301N/A
2301N/A In particular, this exception indicates that something went wrong in the
2301N/A application (or unapplication) of the action to the system, and is most
2301N/A likely not an error in the pkg(5) code."""
2301N/A
2301N/A def __init__(self, action, details=None, error=None, fmri=None,
2301N/A use_errno=None):
2301N/A """'action' is the object for the action that failed during the
2301N/A requested operation.
2301N/A
2301N/A 'details' is an optional message explaining what operation
2301N/A failed, why it failed, and why it cannot continue. It should
2301N/A also include a suggestion as to how to resolve the situation
2301N/A if possible.
2301N/A
2301N/A 'error' is an optional exception object that may have been
565N/A raised when the operation failed.
2339N/A
2339N/A 'fmri' is an optional package FMRI indicating what package
2339N/A was being operated on at the time the error occurred.
2339N/A
2339N/A 'use_errno' is an optional boolean value indicating whether
2453N/A the strerror() text of the exception should be used. If
2339N/A 'details' is provided, the default value is False, otherwise
2339N/A True."""
2339N/A
2339N/A assert (details or error)
2339N/A self.action = action
2339N/A self.details = details
2339N/A self.error = error
2339N/A self.fmri = fmri
2505N/A if use_errno == None:
2339N/A # If details were provided, don't use errno unless
2339N/A # explicitly requested.
2339N/A use_errno = not details
2445N/A self.use_errno = use_errno
2339N/A
2339N/A def __str__(self):
2339N/A errno = ""
2339N/A if self.use_errno and self.error and \
2339N/A hasattr(self.error, "errno"):
2339N/A errno = "[errno %d: %s]" % (self.error.errno,
565N/A os.strerror(self.error.errno))
2339N/A
2339N/A details = self.details or ""
2339N/A
2339N/A # Fall back on the wrapped exception if we don't have anything
2453N/A # useful.
2339N/A if not errno and not details:
2339N/A return str(self.error)
2339N/A
1505N/A if errno and details:
1505N/A details = "%s: %s" % (errno, details)
2339N/A
2339N/A if details and not self.fmri:
2339N/A details = _("Requested operation failed for action "
2505N/A "%(action)s:\n%(details)s") % {
2339N/A "action": self.action,
2207N/A "details": details }
2339N/A elif details:
2445N/A details = _("Requested operation failed for package "
2339N/A "%(fmri)s:\n%(details)s") % { "fmri": self.fmri,
2339N/A "details": details }
2339N/A
1505N/A # If we only have one of the two, no need for the colon.
2212N/A return "%s%s" % (errno, details)
2339N/A
565N/A
616N/Aclass CatalogRefreshException(ApiException):
1141N/A def __init__(self, failed, total, succeeded, errmessage=None):
616N/A ApiException.__init__(self)
2339N/A self.failed = failed
2445N/A self.total = total
2339N/A self.succeeded = succeeded
926N/A self.errmessage = errmessage
1141N/A
565N/A
2445N/Aclass CatalogError(ApiException):
2445N/A """Base exception class for all catalog exceptions."""
2445N/A
2445N/A def __init__(self, *args, **kwargs):
2445N/A ApiException.__init__(self)
2445N/A if args:
2445N/A self.data = args[0]
2445N/A else:
2212N/A self.data = None
2212N/A self._args = kwargs
2212N/A
2212N/A def __str__(self):
2212N/A return str(self.data)
2212N/A
2212N/A
1505N/Aclass AnarchicalCatalogFMRI(CatalogError):
1505N/A """Used to indicate that the specified FMRI is not valid for catalog
1505N/A operations because it is missing publisher information."""
1505N/A
1505N/A def __str__(self):
1505N/A return _("The FMRI '%s' does not contain publisher information "
1505N/A "and cannot be used for catalog operations.") % self.data
565N/A
988N/A
565N/Aclass BadCatalogMetaRoot(CatalogError):
922N/A """Used to indicate an operation on the catalog's meta_root failed
922N/A because the meta_root is invalid."""
633N/A
616N/A def __str__(self):
1505N/A return _("Catalog meta_root '%(root)s' is invalid; unable "
1505N/A "to complete operation: '%(op)s'.") % { "root": self.data,
1505N/A "op": self._args.get("operation", None) }
616N/A
1505N/A
1505N/Aclass BadCatalogPermissions(CatalogError):
1505N/A """Used to indicate the server catalog files do not have the expected
655N/A permissions."""
838N/A
2826N/A def __init__(self, files):
2826N/A """files should contain a list object with each entry consisting
838N/A of a tuple of filename, expected_mode, received_mode."""
2826N/A if not files:
2826N/A files = []
838N/A CatalogError.__init__(self, files)
838N/A
1461N/A def __str__(self):
1461N/A msg = _("The following catalog files have incorrect "
1461N/A "permissions:\n")
1352N/A for f in self._args:
1352N/A fname, emode, fmode = f
1352N/A msg += _("\t%(fname)s: expected mode: %(emode)s, found "
1352N/A "mode: %(fmode)s\n") % { "fname": fname,
1352N/A "emode": emode, "fmode": fmode }
1352N/A return msg
1352N/A
2453N/A
2453N/Aclass BadCatalogSignatures(CatalogError):
2453N/A """Used to indicate that the Catalog signatures are not valid."""
2453N/A
2453N/A def __str__(self):
2453N/A return _("The signature data for the '%s' catalog file is not "
2453N/A "valid.") % self.data
1505N/A
2681N/A
2681N/Aclass BadCatalogUpdateIdentity(CatalogError):
1505N/A """Used to indicate that the requested catalog updates could not be
1505N/A applied as the new catalog data is significantly different such that
1505N/A the old catalog cannot be updated to match it."""
1505N/A
1505N/A def __str__(self):
1505N/A return _("Unable to determine the updates needed for "
1945N/A "the current catalog using the provided catalog "
1505N/A "update data in '%s'.") % self.data
1505N/A
2197N/A
2197N/Aclass DuplicateCatalogEntry(CatalogError):
2207N/A """Used to indicate that the specified catalog operation could not be
2339N/A performed since it would result in a duplicate catalog entry."""
2339N/A
2339N/A def __str__(self):
2339N/A return _("Unable to perform '%(op)s' operation for catalog "
2339N/A "%(name)s; completion would result in a duplicate entry "
2339N/A "for package '%(fmri)s'.") % { "op": self._args.get(
2339N/A "operation", None), "name": self._args.get("catalog_name",
2339N/A None), "fmri": self.data }
2339N/A
1505N/A
1505N/Aclass CatalogUpdateRequirements(CatalogError):
1505N/A """Used to indicate that an update request for the catalog could not
2339N/A be performed because update requirements were not satisfied."""
2339N/A
2339N/A def __str__(self):
2339N/A return _("Catalog updates can only be applied to an on-disk "
2339N/A "catalog.")
2339N/A
2339N/A
2339N/Aclass InvalidCatalogFile(CatalogError):
2339N/A """Used to indicate a Catalog file could not be loaded."""
1505N/A
1945N/A def __str__(self):
1945N/A return _("Catalog file '%s' is invalid.") % self.data
1945N/A
1945N/A
2200N/Aclass MismatchedCatalog(CatalogError):
2200N/A """Used to indicate that a Catalog's attributes and parts do not
2200N/A match. This is likely the result of an attributes file being
1945N/A retrieved which doesn't match the parts that were retrieved such
2207N/A as in a misconfigured or stale cache case."""
2207N/A
2207N/A def __str__(self):
2207N/A return _("The content of the catalog for publisher '%s' "
2207N/A "doesn't match the catalog's attributes. This is "
2228N/A "likely the result of a mix of older and newer "
2339N/A "catalog files being provided for the publisher.") % \
2339N/A self.data
2339N/A
2228N/A
2228N/Aclass ObsoleteCatalogUpdate(CatalogError):
2228N/A """Used to indicate that the specified catalog updates are for an older
2339N/A version of the catalog and cannot be applied."""
2339N/A
2339N/A def __str__(self):
2228N/A return _("Unable to determine the updates needed for the "
2228N/A "catalog using the provided catalog update data in '%s'. "
2505N/A "The specified catalog updates are for an older version "
2505N/A "of the catalog and cannot be used.") % self.data
2505N/A
2505N/A
2505N/Aclass UnknownCatalogEntry(CatalogError):
2339N/A """Used to indicate that an entry for the specified package FMRI or
2339N/A pattern could not be found in the catalog."""
2339N/A
2339N/A def __str__(self):
2339N/A return _("'%s' could not be found in the catalog.") % self.data
2339N/A
2339N/A
2339N/Aclass UnknownUpdateType(CatalogError):
2339N/A """Used to indicate that the specified CatalogUpdate operation is
2339N/A unknown."""
2339N/A
2339N/A def __str__(self):
2339N/A return _("Unknown catalog update type '%s'") % self.data
2339N/A
2339N/A
2339N/Aclass UnrecognizedCatalogPart(CatalogError):
2339N/A """Raised when the catalog finds a CatalogPart that is unrecognized
2339N/A or invalid."""
2364N/A
2339N/A def __str__(self):
2339N/A return _("Unrecognized, unknown, or invalid CatalogPart '%s'") \
2339N/A % self.data
2339N/A
2339N/A
2339N/Aclass InventoryException(ApiException):
2339N/A """Used to indicate that some of the specified patterns to a catalog
2339N/A matching function did not match any catalog entries, or were invalid
2339N/A patterns."""
2339N/A
1352N/A def __init__(self, illegal=EmptyI, matcher=EmptyI, notfound=EmptyI,
565N/A publisher=EmptyI, version=EmptyI):
2228N/A ApiException.__init__(self)
2205N/A self.illegal = illegal
2205N/A self.matcher = matcher
2205N/A self.notfound = set(notfound)
2205N/A self.publisher = publisher
2205N/A self.version = version
2205N/A
2205N/A self.notfound.update(matcher)
2205N/A self.notfound.update(publisher)
2205N/A self.notfound.update(version)
2205N/A self.notfound = list(self.notfound)
2205N/A
2205N/A assert self.illegal or self.notfound
2205N/A
2205N/A def __str__(self):
2205N/A outstr = ""
2205N/A for x in self.illegal:
2205N/A # Illegal FMRIs have their own __str__ method
2205N/A outstr += "%s\n" % x
2205N/A
2205N/A if self.matcher or self.publisher or self.version:
2205N/A outstr += _("No matching package could be found for "
2205N/A "the following FMRIs in any of the catalogs for "
2205N/A "the current publishers:\n")
2205N/A
2205N/A for x in self.matcher:
2205N/A outstr += _("%s (pattern did not match)\n") % x
2205N/A for x in self.publisher:
2205N/A outstr += _("%s (publisher did not "
2205N/A "match)\n") % x
2205N/A for x in self.version:
2205N/A outstr += _("%s (version did not match)\n") % x
2205N/A return outstr
2205N/A
2205N/A
2205N/A# SearchExceptions
2205N/A
2205N/Aclass SearchException(ApiException):
2205N/A """Based class used for all search-related api exceptions."""
2205N/A pass
2205N/A
2205N/A
2205N/Aclass MalformedSearchRequest(SearchException):
2205N/A """Raised when the server cannot understand the format of the
2205N/A search request."""
2205N/A
2205N/A def __init__(self, url):
2205N/A SearchException.__init__(self)
2205N/A self.url = url
2205N/A
2205N/A def __str__(self):
2205N/A return str(self.url)
2205N/A
2205N/A
2205N/Aclass NegativeSearchResult(SearchException):
2205N/A """Returned when the search cannot find any matches."""
2205N/A
2205N/A def __init__(self, url):
2205N/A SearchException.__init__(self)
2205N/A self.url = url
2205N/A
2205N/A def __str__(self):
2205N/A return _("The search at url %s returned no results.") % self.url
2205N/A
2205N/A
2205N/Aclass ProblematicSearchServers(SearchException):
2205N/A """This class wraps exceptions which could appear while trying to
2205N/A do a search request."""
2205N/A
2205N/A def __init__(self, failed=EmptyI, invalid=EmptyI, unsupported=EmptyI):
2205N/A SearchException.__init__(self)
2205N/A self.failed_servers = failed
2205N/A self.invalid_servers = invalid
2205N/A self.unsupported_servers = unsupported
2205N/A
2205N/A def __str__(self):
2205N/A s = _("Some repositories failed to respond appropriately:\n")
2205N/A for pub, err in self.failed_servers:
2205N/A s += _("%(o)s:\n%(msg)s\n") % \
2205N/A { "o": pub, "msg": err}
2205N/A for pub in self.invalid_servers:
2205N/A s += _("%s did not return a valid response.\n" \
2205N/A % pub)
2205N/A if len(self.unsupported_servers) > 0:
2205N/A s += _("Some repositories don't support requested "
2205N/A "search operation:\n")
2205N/A for pub, err in self.unsupported_servers:
2205N/A s += _("%(o)s:\n%(msg)s\n") % \
2205N/A { "o": pub, "msg": err}
2205N/A
2205N/A return s
2205N/A
2205N/A
2205N/Aclass SlowSearchUsed(SearchException):
2205N/A """This exception is thrown when a local search is performed without
2205N/A an index. It's raised after all results have been yielded."""
2205N/A
2205N/A def __str__(self):
2205N/A return _("Search performance is degraded.\n"
2205N/A "Run 'pkg rebuild-index' to improve search speed.")
2205N/A
2205N/A
2205N/Aclass UnsupportedSearchError(SearchException):
2453N/A """Returned when a search protocol is not supported by the
2453N/A remote server."""
2453N/A
2453N/A def __init__(self, url=None, proto=None):
2205N/A SearchException.__init__(self)
2205N/A self.url = url
2205N/A self.proto = proto
2205N/A
2205N/A def __str__(self):
2205N/A s = _("Search repository does not support the requested "
2232N/A "protocol:")
2232N/A if self.url:
2205N/A s += "\nRepository URL: %s" % self.url
2205N/A if self.proto:
2205N/A s += "\nRequested operation: %s" % self.proto
2205N/A return s
2205N/A
2205N/A def __cmp__(self, other):
2205N/A if not isinstance(other, UnsupportedSearchError):
2205N/A return -1
2205N/A r = cmp(self.url, other.url)
2205N/A if r != 0:
2205N/A return r
2205N/A return cmp(self.proto, other.proto)
2205N/A
2205N/A
2205N/A# IndexingExceptions.
2205N/A
2205N/Aclass IndexingException(SearchException):
2205N/A """ The base class for all exceptions that can occur while indexing. """
2205N/A
2205N/A def __init__(self, private_exception):
2826N/A SearchException.__init__(self)
2826N/A self.cause = private_exception.cause
2205N/A
2205N/A
2205N/Aclass CorruptedIndexException(IndexingException):
2205N/A """This is used when the index is not in a correct state."""
2239N/A pass
2205N/A
2205N/A
2239N/Aclass InconsistentIndexException(IndexingException):
2205N/A """This is used when the existing index is found to have inconsistent
2205N/A versions."""
2205N/A def __init__(self, e):
2205N/A IndexingException.__init__(self, e)
2205N/A self.exception = e
2205N/A
2205N/A def __str__(self):
2205N/A return str(self.exception)
2205N/A
2205N/A
2205N/Aclass IndexLockedException(IndexingException):
2205N/A """This is used when an attempt to modify an index locked by another
2205N/A process or thread is made."""
2205N/A
2205N/A def __init__(self, e):
2205N/A IndexingException.__init__(self, e)
2205N/A self.exception = e
2205N/A
2205N/A def __str__(self):
2205N/A return str(self.exception)
2205N/A
2205N/A
2205N/Aclass ProblematicPermissionsIndexException(IndexingException):
2205N/A """ This is used when the indexer is unable to create, move, or remove
2205N/A files or directories it should be able to. """
2205N/A def __str__(self):
2205N/A return "Could not remove or create " \
2205N/A "%s because of incorrect " \
2205N/A "permissions. Please correct this issue then " \
2205N/A "rebuild the index." % self.cause
2205N/A
2205N/Aclass WrapIndexingException(ApiException):
1068N/A """This exception is used to wrap an indexing exception during install,
1050N/A uninstall, or update so that a more appropriate error message can be
1859N/A displayed to the user."""
1859N/A
1050N/A def __init__(self, e, tb, stack):
1050N/A ApiException.__init__(self)
1859N/A self.wrapped = e
1859N/A self.tb = tb
1859N/A self.stack = stack
1859N/A
1859N/A def __str__(self):
1859N/A tmp = self.tb.split("\n")
1859N/A res = tmp[:1] + [s.rstrip("\n") for s in self.stack] + tmp[1:]
1859N/A return "\n".join(res)
1859N/A
1859N/A
1859N/Aclass WrapSuccessfulIndexingException(WrapIndexingException):
1859N/A """This exception is used to wrap an indexing exception during install,
1859N/A uninstall, or update which was recovered from by performing a full
1859N/A reindex."""
1859N/A pass
1050N/A
1859N/A
1859N/A# Query Parsing Exceptions
1859N/Aclass BooleanQueryException(ApiException):
1859N/A """This exception is used when the children of a boolean operation
1859N/A have different return types. The command 'pkg search foo AND <bar>'
1859N/A is the simplest example of this."""
1859N/A
1050N/A def __init__(self, e):
1859N/A ApiException.__init__(self)
1050N/A self.e = e
1859N/A
1859N/A def __str__(self):
1859N/A return str(self.e)
1859N/A
1859N/A
1859N/Aclass ParseError(ApiException):
1859N/A def __init__(self, e):
1859N/A ApiException.__init__(self)
1050N/A self.e = e
1050N/A
1050N/A def __str__(self):
1859N/A return str(self.e)
1859N/A
1859N/A
1859N/Aclass NonLeafPackageException(ApiException):
1050N/A """Removal of a package which satisfies dependencies has been attempted.
1859N/A
1050N/A The first argument to the constructor is the FMRI which we tried to
1050N/A remove, and is available as the "fmri" member of the exception. The
1050N/A second argument is the list of dependent packages that prevent the
1859N/A removal of the package, and is available as the "dependents" member.
1859N/A """
1859N/A
1859N/A def __init__(self, *args):
1859N/A ApiException.__init__(self, *args)
1050N/A
1859N/A self.fmri = args[0]
1859N/A self.dependents = args[1]
1859N/A
1859N/Aclass InvalidDepotResponseException(ApiException):
2073N/A """Raised when the depot doesn't have versions of operations
1859N/A that the client needs to operate successfully."""
1859N/A def __init__(self, url, data):
1859N/A ApiException.__init__(self)
1859N/A self.url = url
1050N/A self.data = data
1050N/A
1859N/A def __str__(self):
1050N/A s = "Unable to contact valid package repository"
1068N/A if self.url:
565N/A s += ": %s" % self.url
1603N/A if self.data:
565N/A s += "\nEncountered the following error(s):\n%s" % \
565N/A self.data
565N/A return s
565N/A
1603N/Aclass DataError(ApiException):
565N/A """Base exception class used for all data related errors."""
1068N/A
1352N/A def __init__(self, *args, **kwargs):
1352N/A ApiException.__init__(self, *args)
1352N/A if args:
1352N/A self.data = args[0]
565N/A else:
1352N/A self.data = None
1352N/A self._args = kwargs
1352N/A
1352N/A
1516N/Aclass InvalidP5IFile(DataError):
1352N/A """Used to indicate that the specified location does not contain a
1352N/A valid p5i-formatted file."""
1352N/A
1352N/A def __str__(self):
1352N/A if self.data:
1352N/A return _("The provided p5i data is in an unrecognized "
1352N/A "format or does not contain valid publisher "
1352N/A "information: %s") % self.data
1352N/A return _("The provided p5i data is in an unrecognized format "
1352N/A "or does not contain valid publisher information.")
1352N/A
1352N/A
1352N/Aclass UnsupportedP5IFile(DataError):
1352N/A """Used to indicate that an attempt to read an unsupported version
1352N/A of pkg(5) info file was attempted."""
1352N/A
1352N/A def __str__(self):
1352N/A return _("Unsupported pkg(5) publisher information data "
1352N/A "format.")
1352N/A
1352N/A
1516N/Aclass TransportError(ApiException):
1352N/A """Abstract exception class for all transport exceptions.
1352N/A Specific transport exceptions should be implemented in the
1352N/A transport code. Callers wishing to catch transport exceptions
1352N/A should use this class. Subclasses must implement all methods
1352N/A defined here that raise NotImplementedError."""
1352N/A
1352N/A def __str__(self):
1352N/A raise NotImplementedError()
1352N/A
1352N/A
1352N/Aclass RetrievalError(ApiException):
1352N/A """Used to indicate that a a requested resource could not be
1352N/A retrieved."""
1352N/A
1352N/A def __init__(self, data, location=None):
1352N/A ApiException.__init__(self)
2614N/A self.data = data
1352N/A self.location = location
1352N/A
1352N/A def __str__(self):
1352N/A if self.location:
1352N/A return _("Error encountered while retrieving data from "
1352N/A "'%s':\n%s") % (self.location, self.data)
1352N/A return _("Error encountered while retrieving data from: %s") % \
1352N/A self.data
1352N/A
1352N/A
1352N/Aclass InvalidResourceLocation(ApiException):
1352N/A """Used to indicate that an invalid transport location was provided."""
1352N/A
1352N/A def __init__(self, data):
1352N/A ApiException.__init__(self)
1352N/A self.data = data
1352N/A
1352N/A def __str__(self):
1352N/A return _("'%s' is not a valid location.") % self.data
1352N/A
1352N/Aclass BEException(ApiException):
1352N/A def __init__(self):
1352N/A ApiException.__init__(self)
1352N/A
1352N/Aclass InvalidBENameException(BEException):
1352N/A def __init__(self, be_name):
1352N/A BEException.__init__(self)
1352N/A self.be_name = be_name
1352N/A
1352N/A def __str__(self):
1352N/A return _("'%s' is not a valid boot environment name.") % \
1352N/A self.be_name
1352N/A
1516N/Aclass DuplicateBEName(BEException):
1516N/A """Used to indicate that there is an existing boot environment
1352N/A with this name"""
1352N/A
1352N/A def __init__(self, be_name):
1352N/A BEException.__init__(self)
1352N/A self.be_name = be_name
1352N/A
1352N/A def __str__(self):
1352N/A return _("The boot environment '%s' already exists.") % \
1352N/A self.be_name
1352N/A
1352N/Aclass BENamingNotSupported(BEException):
1352N/A def __init__(self, be_name):
1352N/A BEException.__init__(self)
1352N/A self.be_name = be_name
1352N/A
1352N/A def __str__(self):
1352N/A return _("""\
1352N/ABoot environment naming during package install is not supported on this
1352N/Aversion of OpenSolaris. Please update without the --be-name option.""")
2022N/A
2022N/Aclass UnableToCopyBE(BEException):
2022N/A def __str__(self):
2022N/A return _("Unable to clone the current boot environment.")
2022N/A
2022N/Aclass UnableToRenameBE(BEException):
2022N/A def __init__(self, orig, dest):
2022N/A BEException.__init__(self)
2022N/A self.original_name = orig
2022N/A self.destination_name = dest
2022N/A
2022N/A def __str__(self):
2022N/A d = {
2022N/A "orig": self.original_name,
1352N/A "dest": self.destination_name
1352N/A }
1352N/A return _("""\
1352N/AA problem occurred while attempting to rename the boot environment
1352N/Acurrently named %(orig)s to %(dest)s.""") % d
1352N/A
1352N/Aclass UnableToMountBE(BEException):
1352N/A def __init__(self, be_name, be_dir):
1352N/A BEException.__init__(self)
1352N/A self.name = be_name
1352N/A self.mountpoint = be_dir
1352N/A
1352N/A def __str__(self):
1352N/A return _("Unable to mount %(name)s at %(mt)s") % \
1352N/A {"name": self.name, "mt": self.mountpoint}
1352N/A
1352N/Aclass BENameGivenOnDeadBE(BEException):
1352N/A def __init__(self, be_name):
1352N/A BEException.__init__(self)
1352N/A self.name = be_name
1352N/A
1352N/A def __str__(self):
1352N/A return _("""\
1352N/ANaming a boot environment when operating on a non-live image is
1352N/Anot allowed.""")
1352N/A
1352N/A
1431N/Aclass UnrecognizedOptionsToInfo(ApiException):
1431N/A def __init__(self, opts):
1431N/A ApiException.__init__(self)
1431N/A self._opts = opts
1431N/A
1431N/A def __str__(self):
1431N/A s = _("Info does not recognize the following options:")
1431N/A for o in self._opts:
1431N/A s += _(" '") + str(o) + _("'")
1352N/A return s
1352N/A
1970N/Aclass IncorrectIndexFileHash(ApiException):
1970N/A """This is used when the index hash value doesn't match the hash of the
1352N/A packages installed in the image."""
1352N/A pass
1352N/A
1352N/A
838N/Aclass PublisherError(ApiException):
1352N/A """Base exception class for all publisher exceptions."""
1352N/A
1352N/A def __init__(self, *args, **kwargs):
1352N/A ApiException.__init__(self, *args)
1352N/A if args:
1352N/A self.data = args[0]
1352N/A else:
1352N/A self.data = None
1352N/A self._args = kwargs
1352N/A
1945N/A def __str__(self):
565N/A return str(self.data)
596N/A
596N/A
596N/Aclass BadPublisherMetaRoot(PublisherError):
596N/A """Used to indicate an operation on the publisher's meta_root failed
596N/A because the meta_root is invalid."""
614N/A
1352N/A def __str__(self):
614N/A return _("Publisher meta_root '%(root)s' is invalid; unable "
614N/A "to complete operation: '%(op)s'.") % { "root": self.data,
926N/A "op": self._args.get("operation", None) }
614N/A
1352N/A
1352N/Aclass BadPublisherAlias(PublisherError):
1352N/A """Used to indicate that a publisher alias is not valid."""
1352N/A
1352N/A def __str__(self):
1352N/A return _("'%s' is not a valid publisher alias.") % self.data
1352N/A
596N/A
565N/Aclass BadPublisherPrefix(PublisherError):
1027N/A """Used to indicate that a publisher name is not valid."""
1191N/A
1191N/A def __str__(self):
1027N/A return _("'%s' is not a valid publisher name.") % self.data
1027N/A
1027N/A
1027N/Aclass BadRepositoryAttributeValue(PublisherError):
1027N/A """Used to indicate that the specified repository attribute value is
1191N/A invalid."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("'%(value)s' is not a valid value for repository "
1191N/A "attribute '%(attribute)s'.") % {
1191N/A "value": self._args["value"], "attribute": self.data }
1191N/A
1191N/A
1191N/Aclass BadRepositoryCollectionType(PublisherError):
1191N/A """Used to indicate that the specified repository collection type is
1191N/A invalid."""
1191N/A
1191N/A def __init__(self, *args, **kwargs):
1191N/A PublisherError.__init__(self, *args, **kwargs)
1191N/A
1191N/A def __str__(self):
1191N/A return _("'%s' is not a valid repository collection type.") % \
1191N/A self.data
1191N/A
1191N/A
1191N/Aclass BadRepositoryURI(PublisherError):
1191N/A """Used to indicate that a repository URI is not syntactically valid."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("'%s' is not a valid URI.") % self.data
1191N/A
1191N/A
1191N/Aclass BadRepositoryURIPriority(PublisherError):
1191N/A """Used to indicate that the priority specified for a repository URI is
1191N/A not valid."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("'%s' is not a valid URI priority; integer value "
1191N/A "expected.") % self.data
1895N/A
1191N/A
1191N/Aclass BadRepositoryURISortPolicy(PublisherError):
1191N/A """Used to indicate that the specified repository URI sort policy is
1191N/A invalid."""
1191N/A
1191N/A def __init__(self, *args, **kwargs):
1191N/A PublisherError.__init__(self, *args, **kwargs)
1895N/A
1895N/A def __str__(self):
1191N/A return _("'%s' is not a valid repository URI sort policy.") % \
1191N/A self.data
1191N/A
1191N/A
1191N/Aclass DisabledPublisher(PublisherError):
1191N/A """Used to indicate that an attempt to use a disabled publisher occurred
1191N/A during an operation."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("Publisher '%s' is disabled and cannot be used for "
1191N/A "packaging operations.") % self.data
1191N/A
1191N/A
1191N/Aclass DuplicatePublisher(PublisherError):
1191N/A """Used to indicate that a publisher with the same name or alias already
1191N/A exists for an image."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("A publisher with the same name or alias as '%s' "
1191N/A "already exists.") % self.data
1191N/A
1191N/A
1191N/Aclass DuplicateRepository(PublisherError):
1191N/A """Used to indicate that a repository with the same origin uris
1191N/A already exists for a publisher."""
1191N/A
1895N/A def __str__(self):
1895N/A return _("A repository with the same name or origin URIs "
1191N/A "already exists for publisher '%s'.") % self.data
1895N/A
1191N/A
1191N/Aclass DuplicateRepositoryMirror(PublisherError):
1191N/A """Used to indicate that a repository URI is already in use by another
1191N/A repository mirror."""
1191N/A
1191N/A def __str__(self):
1945N/A return _("Mirror '%s' already exists for the specified "
1191N/A "publisher.") % self.data
1191N/A
1191N/A
1191N/Aclass DuplicateRepositoryOrigin(PublisherError):
1191N/A """Used to indicate that a repository URI is already in use by another
1191N/A repository origin."""
1191N/A
1191N/A def __str__(self):
1027N/A return _("Origin '%s' already exists for the specified "
565N/A "publisher.") % self.data
1027N/A
565N/A
1027N/Aclass PublisherOriginRequired(PublisherError):
565N/A """Used to indicate that the specified publisher must have at least one
565N/A repository with at least one origin URI."""
1027N/A
565N/A def __str__(self):
565N/A return _("At least one origin is required for %s. You must "
565N/A "add a new origin before attempting to remove the specified "
565N/A "origin(s).") % self.data
1027N/A
1191N/A
1191N/Aclass RemovePreferredPublisher(PublisherError):
1191N/A """Used to indicate an attempt to remove the preferred publisher was
1191N/A made."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("The preferred publisher cannot be removed.")
1191N/A
1191N/A
1191N/Aclass MoveRelativeToSelf(PublisherError):
1191N/A """Used to indicate an attempt to search a repo before or after itself"""
2028N/A
2028N/A def __str__(self):
2028N/A return _("Cannot search a repository before or after itself")
2028N/A
2028N/A
2028N/Aclass SelectedRepositoryRemoval(PublisherError):
2028N/A """Used to indicate that an attempt to remove the selected repository
2028N/A for a publisher was made."""
2028N/A
2028N/A def __str__(self):
2028N/A return _("Cannot remove the selected repository for a "
2028N/A "publisher.")
565N/A
565N/A
565N/Aclass SetDisabledPublisherPreferred(PublisherError):
565N/A """Used to indicate an attempt to set a disabled publisher as the
565N/A preferred publisher was made."""
565N/A
565N/A def __str__(self):
565N/A return _("Publisher '%s' is disabled and cannot be set as the "
941N/A "preferred publisher.") % self.data
1286N/A
1286N/A
2089N/Aclass SetPreferredPublisherDisabled(PublisherError):
2089N/A """Used to indicate that an attempt was made to set the preferred
1286N/A publisher as disabled."""
1286N/A
1286N/A def __str__(self):
1286N/A return _("The preferred publisher may not be disabled."
1286N/A " Another publisher must be set as the preferred "
1286N/A "publisher before this publisher can be disabled.")
1286N/A
1286N/A
1286N/Aclass UnknownLegalURI(PublisherError):
1286N/A """Used to indicate that no matching legal URI could be found using the
1286N/A provided criteria."""
1286N/A
1286N/A def __str__(self):
1286N/A return _("Unknown legal URI '%s'.") % self.data
1286N/A
2089N/A
2089N/Aclass UnknownPublisher(PublisherError):
1286N/A """Used to indicate that no matching publisher could be found using the
1286N/A provided criteria."""
1286N/A
1191N/A def __str__(self):
1191N/A return _("Unknown publisher '%s'.") % self.data
1191N/A
1191N/A
1191N/Aclass UnknownRepositoryPublishers(PublisherError):
941N/A """Used to indicate that one or more publisher prefixes are unknown by
941N/A the specified repository."""
1191N/A
1191N/A def __init__(self, known=EmptyI, unknown=EmptyI, location=None,
1191N/A origins=EmptyI):
1191N/A ApiException.__init__(self)
1191N/A self.known = known
1191N/A self.location = location
1191N/A self.origins = origins
1191N/A self.unknown = unknown
1191N/A
1191N/A def __str__(self):
941N/A if self.location:
941N/A return _("The repository at %(location)s does not "
941N/A "contain package data for %(unknown)s; only "
1027N/A "%(known)s.\n\nThis is either because the "
1027N/A "repository location is not valid, or because the "
565N/A "provided publisher does not match those known by "
565N/A "the repository.") % {
565N/A "unknown": ", ".join(self.unknown),
1027N/A "location": self.location,
565N/A "known": ", ".join(self.known) }
565N/A if self.origins:
565N/A return _("One or more of the repository origin(s) "
565N/A "listed below contains package data for "
565N/A "%(known)s; not %(unknown)s:\n\n%(origins)s\n\n"
565N/A "This is either because one of the repository "
565N/A "origins is not valid for this publisher, or "
565N/A "because the list of known publishers retrieved "
565N/A "from the repository origin does not match the "
565N/A "client.") % { "unknown": ", ".join(self.unknown),
565N/A "known": ", ".join(self.known),
835N/A "origins": "\n".join(str(o) for o in self.origins) }
2205N/A return _("The specified publisher repository does not "
2205N/A "contain any package data for %(unknown)s; only "
2205N/A "%(known)s.") % { "unknown": ", ".join(self.unknown),
2205N/A "known": ", ".join(self.known) }
2205N/A
2205N/A
2205N/Aclass UnknownRelatedURI(PublisherError):
2205N/A """Used to indicate that no matching related URI could be found using
2205N/A the provided criteria."""
2205N/A
2205N/A def __str__(self):
2205N/A return _("Unknown related URI '%s'.") % self.data
835N/A
835N/A
835N/Aclass UnknownRepository(PublisherError):
835N/A """Used to indicate that no matching repository could be found using the
926N/A provided criteria."""
835N/A
835N/A def __str__(self):
835N/A return _("Unknown repository '%s'.") % self.data
835N/A
2205N/A
835N/Aclass UnknownRepositoryMirror(PublisherError):
2205N/A """Used to indicate that a repository URI could not be found in the
835N/A list of repository mirrors."""
2205N/A
835N/A def __str__(self):
2205N/A return _("Unknown repository mirror '%s'.") % self.data
2205N/A
2205N/Aclass UnsupportedRepositoryOperation(PublisherError):
835N/A """The publisher has no active repositories that support the
884N/A requested operation."""
926N/A
926N/A def __init__(self, pub, operation):
926N/A ApiException.__init__(self)
926N/A self.data = None
926N/A self.kwargs = None
926N/A self.pub = pub
926N/A self.op = operation
926N/A
926N/A def __str__(self):
1516N/A return _("Publisher '%s' has no repositories that support the"
926N/A " '%s' operation.") % (self.pub, self.op)
926N/A
926N/A
926N/Aclass RepoPubConfigUnavailable(PublisherError):
926N/A """Used to indicate that the specified repository does not provide
926N/A publisher configuration information."""
926N/A
926N/A def __init__(self, location=None, pub=None):
1736N/A ApiException.__init__(self)
926N/A self.location = location
926N/A self.pub = pub
1736N/A
1736N/A def __str__(self):
926N/A if not self.location and not self.pub:
926N/A return _("The specified package repository does not "
2310N/A "provide publisher configuration information.")
2310N/A if self.location:
2310N/A return _("The package repository at %s does not "
2310N/A "provide publisher configuration information or "
2310N/A "the information provided is incomplete.") % \
2310N/A self.location
2310N/A return _("One of the package repository origins for %s does "
2310N/A "not provide publisher configuration information or the "
2310N/A "information provided is incomplete.") % self.pub
2310N/A
2310N/A
2310N/Aclass UnknownRepositoryOrigin(PublisherError):
2310N/A """Used to indicate that a repository URI could not be found in the
926N/A list of repository origins."""
926N/A
926N/A def __str__(self):
926N/A return _("Unknown repository origin '%s'") % self.data
926N/A
926N/A
926N/Aclass UnsupportedRepositoryURI(PublisherError):
926N/A """Used to indicate that the specified repository URI uses an
926N/A unsupported scheme."""
2310N/A
2310N/A def __str__(self):
2310N/A if self.data:
2310N/A scheme = urlparse.urlsplit(self.data,
2310N/A allow_fragments=0)[0]
2310N/A return _("The URI '%(uri)s' uses the unsupported "
2310N/A "scheme '%(scheme)s'. Supported schemes are "
2310N/A "file://, http://, and https://.") % {
2310N/A "uri": self.data, "scheme": scheme }
2310N/A return _("The specified URI uses an unsupported scheme."
2310N/A " Supported schemes are: file://, http://, and https://.")
2310N/A
2310N/A
2310N/Aclass UnsupportedRepositoryURIAttribute(PublisherError):
2310N/A """Used to indicate that the specified repository URI attribute is not
2310N/A supported for the URI's scheme."""
2310N/A
2310N/A def __str__(self):
2310N/A return _("'%(attr)s' is not supported for '%(scheme)s'.") % {
2310N/A "attr": self.data, "scheme": self._args["scheme"] }
2310N/A
926N/A
1191N/Aclass SigningException(ApiException):
1191N/A """The base class for exceptions related to manifest signing."""
1191N/A
1191N/A def __init__(self, pfmri=None, sig=None):
1191N/A self.pfmri = pfmri
926N/A self.sig = sig
926N/A
1540N/A # This string method is used by subclasses to fill in the details
926N/A # about the package and signature involved.
2205N/A def __str__(self):
2205N/A if self.pfmri:
2205N/A if self.sig:
926N/A return _("The relevant signature action is "
1191N/A "found in %(pfmri)s and has a hash of "
926N/A "%(hsh)s") % \
926N/A {"pfmri": self.pfmri, "hsh": self.sig.hash}
926N/A return _("The package involved is:%s") % self.pfmri
1191N/A if self.sig:
1191N/A return _("The relevant signature action's value "
1191N/A "attribute is %s") % self.sig.attrs["value"]
1191N/A return ""
1191N/A
926N/A
1191N/Aclass BadFileFormat(SigningException):
926N/A """Exception used when a key, certificate or CRL file is not in a
2826N/A recognized format."""
2826N/A
926N/A def __init__(self, txt):
926N/A self.txt = txt
926N/A
926N/A def __str__(self):
1191N/A return self.txt
926N/A
926N/A
1191N/Aclass UnsupportedSignatureVersion(SigningException):
1191N/A """Exception used when a signature reports a version which this version
1191N/A of pkg(5) doesn't support."""
1191N/A
926N/A def __init__(self, version, *args, **kwargs):
926N/A SigningException.__init__(self, *args, **kwargs)
926N/A self.version = version
941N/A
941N/A def __str__(self):
941N/A return _("The signature action %(act)s was made using a "
926N/A "version (%(ver)s) this version of pkg(5) doesn't "
884N/A "understand.") % {"act":self.sig, "ver":self.version}
884N/A
884N/A
884N/Aclass CertificateException(SigningException):
884N/A """Base class for exceptions encountered while establishing the chain
884N/A of trust."""
1076N/A
1076N/A def __init__(self, cert, pfmri=None):
1076N/A SigningException.__init__(self, pfmri)
1076N/A self.cert = cert
1945N/A
1076N/A
1076N/Aclass ModifiedCertificateException(CertificateException):
1076N/A """Exception used when a certificate does not match its expected hash
1076N/A value."""
1076N/A
1076N/A def __init__(self, cert, path, pfmri=None):
1076N/A CertificateException.__init__(self, cert, pfmri)
1076N/A self.path = path
1076N/A
884N/A def __str__(self):
884N/A return _("Certificate %s has been modified on disk. Its hash "
884N/A "value is not what was expected.") % self.path
884N/A
884N/A
884N/Aclass UntrustedSelfSignedCert(CertificateException):
884N/A """Exception used when a chain of trust is rooted in an untrusted
884N/A self-signed certificate."""
884N/A
2089N/A def __str__(self):
884N/A return _("Chain was rooted in an untrusted self-signed "
884N/A "certificate.\n") + CertificateException.__str__(self)
884N/A
884N/A
884N/Aclass BrokenChain(CertificateException):
884N/A """Exception used when a chain of trust can not be established between
884N/A the leaf certificate and a trust anchor."""
884N/A
884N/A def __init__(self, cert, cert_exceptions, *args, **kwargs):
884N/A CertificateException.__init__(self, cert, *args, **kwargs)
884N/A self.ext_exs = cert_exceptions
884N/A
884N/A def __str__(self):
884N/A s = ""
884N/A if self.ext_exs:
884N/A s = _("The following problems were encountered:\n") + \
884N/A "\n".join([str(e) for e in self.ext_exs])
884N/A return _("The certificate which issued this "
884N/A "certificate:%(subj)s could not be found. The issuer "
884N/A "is:%(issuer)s\n") % {"subj":self.cert.get_subject(),
884N/A "issuer":self.cert.get_issuer()} + s + \
884N/A CertificateException.__str__(self)
884N/A
884N/A
884N/Aclass RevokedCertificate(CertificateException):
884N/A """Exception used when a chain of trust contains a revoked certificate.
884N/A """
884N/A
884N/A def __init__(self, cert, reason, *args, **kwargs):
884N/A CertificateException.__init__(self, cert, *args, **kwargs)
884N/A self.reason = reason
884N/A
884N/A def __str__(self):
884N/A return _("This certificate was revoked:%(cert)s for this "
884N/A "reason:\n%(reason)s") % {"cert":self.cert.get_subject(),
884N/A "reason":self.reason} + CertificateException.__str__(self)
884N/A
884N/A
884N/Aclass UnverifiedSignature(SigningException):
926N/A """Exception used when a signature could not be verified by the
926N/A expected certificate."""
917N/A
917N/A def __init__(self, sig, reason, pfmri=None):
917N/A SigningException.__init__(self, pfmri)
917N/A self.sig = sig
917N/A self.reason = reason
917N/A
917N/A def __str__(self):
917N/A if self.pfmri:
917N/A return _("A signature in %(pfmri)s could not be "
917N/A "verified for "
926N/A "this reason:\n%(reason)s\nThe signature's hash is "
941N/A "%(hash)s") % {"pfmri": self.pfmri,
941N/A "reason": self.reason,
941N/A "hash": self.sig.hash}
941N/A return _("The signature with this signature value:\n"
941N/A "%(sigval)s\n could not be verified for this reason:\n"
941N/A "%(reason)s\n") % {"reason": self.reason,
926N/A "sigval": self.sig.attrs["value"]}
926N/A
926N/A
926N/Aclass RequiredSignaturePolicyException(SigningException):
926N/A """Exception used when signatures were required but none were found."""
926N/A
926N/A def __init__(self, pub, pfmri=None):
926N/A SigningException.__init__(self, pfmri)
926N/A self.pub = pub
1516N/A
926N/A def __str__(self):
926N/A pub_str = self.pub.prefix
926N/A if self.pfmri:
926N/A return _("The policy for %(pub_str)s requires "
926N/A "signatures to be present but no signature was "
1087N/A "found in %(fmri_str)s.") % \
1087N/A {"pub_str": pub_str, "fmri_str": self.pfmri}
1087N/A return _("The policy for %(pub_str)s requires signatures to be "
1087N/A "present but no signature was found.") % {
1087N/A "pub_str": pub_str}
1087N/A
1087N/A
1516N/Aclass MissingRequiredNamesException(SigningException):
1087N/A """Exception used when a signature policy required names to be seen
1087N/A which weren't seen."""
2028N/A
2028N/A def __init__(self, pub, missing_names, pfmri=None):
2028N/A SigningException.__init__(self, pfmri)
2028N/A self.pub = pub
2028N/A self.missing_names = missing_names
2028N/A
2028N/A def __str__(self):
926N/A pub_str = self.pub.prefix
926N/A if self.pfmri:
926N/A return _("The policy for %(pub_str)s requires certain "
926N/A "CNs to be seen in a chain of trust. The following "
926N/A "required names couldn't be found for this "
926N/A "package:%(fmri_str)s.\n%(missing)s") % \
926N/A {"pub_str": pub_str, "fmri_str": self.pfmri,
2339N/A "missing": "\n".join(self.missing_names)}
2339N/A return _("The policy for %(pub_str)s requires certain CNs to "
2339N/A "be seen in a chain of trust. The following required names "
2339N/A "couldn't be found.\n%(missing)s") % {"pub_str": pub_str,
2339N/A "missing": "\n".join(self.missing_names)}
2339N/A
2339N/Aclass UnsupportedCriticalExtension(SigningException):
2339N/A """Exception used when a certificate in the chain of trust uses a
2339N/A critical extension pkg5 doesn't understand."""
2339N/A
926N/A def __init__(self, cert, ext):
926N/A SigningException.__init__(self)
926N/A self.cert = cert
926N/A self.ext = ext
926N/A
926N/A def __str__(self):
926N/A return _("The certificate whose subject is %(cert)s could not "
1516N/A "be verified "
926N/A "because it uses a critical extension that pkg5 cannot "
926N/A "handle yet.\nExtension name:%(name)s\nExtension "
926N/A "value:%(val)s") % {"cert": self.cert.get_subject(),
926N/A "name":self.ext.get_name(), "val":self.ext.get_value()}
926N/A
926N/A
926N/Aclass InvalidPropertyValue(ApiException):
926N/A """Exception used when a property was set to an invalid value."""
926N/A
926N/A def __init__(self, s):
926N/A ApiException.__init__(self)
926N/A self.str = s
926N/A
926N/A def __str__(self):
926N/A return self.str
926N/A
926N/A
926N/Aclass CertificateError(ApiException):
926N/A """Base exception class for all certificate exceptions."""
926N/A
926N/A def __init__(self, *args, **kwargs):
926N/A ApiException.__init__(self, *args)
926N/A if args:
926N/A self.data = args[0]
926N/A else:
926N/A self.data = None
926N/A self._args = kwargs
926N/A
926N/A def __str__(self):
926N/A return str(self.data)
926N/A
926N/A
926N/Aclass ExpiredCertificate(CertificateError):
926N/A """Used to indicate that a certificate has expired."""
926N/A
926N/A def __str__(self):
926N/A publisher = self._args.get("publisher", None)
926N/A uri = self._args.get("uri", None)
926N/A if publisher:
926N/A if uri:
926N/A return _("Certificate '%(cert)s' for publisher "
926N/A "'%(pub)s' needed to access '%(uri)s', "
926N/A "has expired. Please install a valid "
926N/A "certificate.") % { "cert": self.data,
926N/A "pub": publisher, "uri": uri }
926N/A return _("Certificate '%(cert)s' for publisher "
926N/A "'%(pub)s', has expired. Please install a valid "
926N/A "certificate.") % { "cert": self.data,
926N/A "pub": publisher }
926N/A if uri:
926N/A return _("Certificate '%(cert)s', needed to access "
926N/A "'%(uri)s', has expired. Please install a valid "
926N/A "certificate.") % { "cert": self.data, "uri": uri }
926N/A return _("Certificate '%s' has expired. Please install a "
926N/A "valid certificate.") % self.data
926N/A
926N/A
926N/Aclass ExpiringCertificate(CertificateError):
926N/A """Used to indicate that a certificate has expired."""
926N/A
926N/A def __str__(self):
926N/A publisher = self._args.get("publisher", None)
926N/A uri = self._args.get("uri", None)
926N/A days = self._args.get("days", 0)
926N/A if publisher:
926N/A if uri:
926N/A return _("Certificate '%(cert)s' for publisher "
926N/A "'%(pub)s', needed to access '%(uri)s', "
926N/A "will expire in '%(days)s' days.") % {
926N/A "cert": self.data, "pub": publisher,
926N/A "uri": uri, "days": days }
926N/A return _("Certificate '%(cert)s' for publisher "
926N/A "'%(pub)s' will expire in '%(days)s' days.") % {
926N/A "cert": self.data, "pub": publisher, "days": days }
926N/A if uri:
1504N/A return _("Certificate '%(cert)s', needed to access "
926N/A "'%(uri)s', will expire in '%(days)s' days.") % {
926N/A "cert": self.data, "uri": uri, "days": days }
2701N/A return _("Certificate '%(cert)s' will expire in "
2701N/A "'%(days)s' days.") % { "cert": self.data, "days": days }
2701N/A
2701N/A
2701N/Aclass InvalidCertificate(CertificateError):
2701N/A """Used to indicate that a certificate is invalid."""
2701N/A
2701N/A def __str__(self):
2701N/A publisher = self._args.get("publisher", None)
926N/A uri = self._args.get("uri", None)
926N/A if publisher:
926N/A if uri:
926N/A return _("Certificate '%(cert)s' for publisher "
926N/A "'%(pub)s', needed to access '%(uri)s', is "
926N/A "invalid.") % { "cert": self.data,
1504N/A "pub": publisher, "uri": uri }
1504N/A return _("Certificate '%(cert)s' for publisher "
1504N/A "'%(pub)s' is invalid.") % { "cert": self.data,
2701N/A "pub": publisher }
2701N/A if uri:
2701N/A return _("Certificate '%(cert)s' needed to access "
2701N/A "'%(uri)s' is invalid.") % { "cert": self.data,
2701N/A "uri": uri }
2701N/A return _("Invalid certificate '%s'.") % self.data
2701N/A
2701N/A
2701N/Aclass NoSuchKey(CertificateError):
2701N/A """Used to indicate that a key could not be found."""
2701N/A
2701N/A def __str__(self):
2701N/A publisher = self._args.get("publisher", None)
2701N/A uri = self._args.get("uri", None)
2701N/A if publisher:
2701N/A if uri:
2701N/A return _("Unable to locate key '%(key)s' for "
2701N/A "publisher '%(pub)s' needed to access "
2701N/A "'%(uri)s'.") % { "key": self.data,
2701N/A "pub": publisher, "uri": uri }
2701N/A return _("Unable to locate key '%(key)s' for publisher "
2701N/A "'%(pub)s'.") % { "key": self.data, "pub": publisher
2701N/A }
2701N/A if uri:
2701N/A return _("Unable to locate key '%(key)s' needed to "
2701N/A "access '%(uri)s'.") % { "key": self.data,
2322N/A "uri": uri }
2219N/A return _("Unable to locate key '%s'.") % self.data
2219N/A
1504N/A
2322N/Aclass NoSuchCertificate(CertificateError):
2322N/A """Used to indicate that a certificate could not be found."""
2322N/A
2322N/A def __str__(self):
1504N/A publisher = self._args.get("publisher", None)
2219N/A uri = self._args.get("uri", None)
2219N/A if publisher:
2322N/A if uri:
926N/A return _("Unable to locate certificate "
926N/A "'%(cert)s' for publisher '%(pub)s' needed "
1505N/A "to access '%(uri)s'.") % {
1505N/A "cert": self.data, "pub": publisher,
1505N/A "uri": uri }
1505N/A return _("Unable to locate certificate '%(cert)s' for "
1505N/A "publisher '%(pub)s'.") % { "cert": self.data,
1505N/A "pub": publisher }
1505N/A if uri:
2409N/A return _("Unable to locate certificate '%(cert)s' "
2409N/A "needed to access '%(uri)s'.") % {
2409N/A "cert": self.data, "uri": uri }
2409N/A return _("Unable to locate certificate '%s'.") % self.data
2409N/A
2409N/A
2409N/Aclass NotYetValidCertificate(CertificateError):
2409N/A """Used to indicate that a certificate is not yet valid (future
2409N/A effective date)."""
2409N/A
2409N/A def __str__(self):
2409N/A publisher = self._args.get("publisher", None)
926N/A uri = self._args.get("uri", None)
926N/A if publisher:
926N/A if uri:
926N/A return _("Certificate '%(cert)s' for publisher "
926N/A "'%(pub)s', needed to access '%(uri)s', "
926N/A "has a future effective date.") % {
926N/A "cert": self.data, "pub": publisher,
926N/A "uri": uri }
926N/A return _("Certificate '%(cert)s' for publisher "
926N/A "'%(pub)s' has a future effective date.") % {
926N/A "cert": self.data, "pub": publisher }
926N/A if uri:
926N/A return _("Certificate '%(cert)s' needed to access "
926N/A "'%(uri)s' has a future effective date.") % {
926N/A "cert": self.data, "uri": uri }
926N/A return _("Certificate '%s' has a future effective date.") % \
926N/A self.data
926N/A
926N/A
926N/Aclass ServerReturnError(ApiException):
926N/A """This exception is used when the server returns a line which the
926N/A client cannot parse correctly."""
926N/A
926N/A def __init__(self, line):
926N/A ApiException.__init__(self)
1736N/A self.line = line
1736N/A
1736N/A def __str__(self):
1736N/A return _("Gave a bad response:%s") % self.line
1736N/A
1736N/A
1736N/Aclass MissingFileArgumentException(ApiException):
1736N/A """This exception is used when a file was given as an argument but
1736N/A no such file could be found."""
1736N/A def __init__(self, path):
1736N/A ApiException.__init__(self)
1736N/A self.path = path
1736N/A
1736N/A def __str__(self):
1736N/A return _("Could not find %s") % self.path
1736N/A
1736N/A
1736N/Aclass ManifestError(ApiException):
1736N/A """Base exception class for all manifest exceptions."""
1736N/A
1736N/A def __init__(self, *args, **kwargs):
1736N/A ApiException.__init__(self, *args, **kwargs)
1736N/A if args:
1736N/A self.data = args[0]
1736N/A else:
1736N/A self.data = None
1736N/A self._args = kwargs
1736N/A
1736N/A def __str__(self):
1736N/A return str(self.data)
1736N/A
1736N/A
1736N/Aclass BadManifestSignatures(ManifestError):
1736N/A """Used to indicate that the Manifest signatures are not valid."""
1736N/A
1736N/A def __str__(self):
1736N/A if self.data:
1736N/A return _("The signature data for the manifest of the "
1736N/A "'%s' package is not valid.") % self.data
1736N/A return _("The signature data for the manifest is not valid.")
926N/A
926N/A
926N/Aclass UnknownErrors(ApiException):
926N/A """Used to indicate that one or more exceptions were encountered.
926N/A This is intended for use with where multiple exceptions for multiple
926N/A files are encountered and the errors have been condensed into a
926N/A single exception and re-raised. One example case would be rmtree()
926N/A with shutil.Error."""
926N/A
926N/A def __init__(self, msg):
926N/A ApiException.__init__(self)
926N/A self.__msg = msg
926N/A
926N/A def __str__(self):
926N/A return self.__msg
926N/A
926N/A
926N/A# Image creation exceptions
926N/Aclass ImageCreationException(ApiException):
926N/A def __init__(self, path):
926N/A ApiException.__init__(self)
926N/A self.path = path
926N/A
2316N/A def __str__(self):
1431N/A raise NotImplementedError()
1431N/A
1431N/A
1431N/Aclass ImageAlreadyExists(ImageCreationException):
1431N/A def __str__(self):
1431N/A return _("there is already an image at: %s.\nTo override, use "
1431N/A "the -f (force) option.") % self.path
1431N/A
1431N/A
1431N/Aclass ImageCfgEmptyError(ApiException):
1431N/A """Used to indicate that the image configuration is invalid."""
2316N/A
2316N/A def __str__(self):
1736N/A return _("The configuration data for the image rooted at "
1736N/A "%s is empty or missing.") % self.data
1736N/A
1736N/A
1736N/Aclass UnsupportedImageError(ApiException):
1736N/A """Used to indicate that the image at a specific location is in a format
1736N/A not supported by this version of the pkg(5) API."""
1736N/A
1736N/A def __init__(self, path):
1736N/A ApiException.__init__(self)
1736N/A self.path = path
1736N/A
1736N/A def __str__(self):
1736N/A return _("The image rooted at %s is invalid or is not "
1736N/A "supported by this version of the packaging system.") % \
1736N/A self.path
1736N/A
1736N/A
1736N/Aclass CreatingImageInNonEmptyDir(ImageCreationException):
1736N/A def __str__(self):
1736N/A return _("the specified image path is not empty: %s.\nTo "
1736N/A "override, use the -f (force) option.") % self.path
1736N/A
1736N/A
926N/Adef _convert_error(e, ignored_errors=EmptyI):
926N/A """Converts the provided exception into an ApiException equivalent if
926N/A possible. Returns a new exception object if converted or the original
926N/A if not.
926N/A
926N/A 'ignored_errors' is an optional list of errno values for which None
926N/A should be returned.
926N/A """
926N/A
926N/A if not hasattr(e, "errno"):
926N/A return e
926N/A if e.errno in ignored_errors:
926N/A return None
926N/A if e.errno in (errno.EACCES, errno.EPERM):
926N/A return PermissionsException(e.filename)
926N/A if e.errno == errno.EROFS:
926N/A return ReadOnlyFileSystemException(e.filename)
2144N/A return e
2144N/A