api_errors.py revision 2410
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#
3321N/A# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
926N/A#
565N/A
2026N/Aimport errno
3094N/Aimport os
1050N/Aimport urlparse
3234N/A
2524N/A# pkg classes
3245N/Aimport pkg.client.pkgdefs as pkgdefs
3234N/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.
2034N/A return unicode(str(self))
2034N/A
2200N/A def add_verbose_info(self, info):
2034N/A self.__verbose_info.extend(info)
2034N/A
2034N/A @property
565N/A def verbose_info(self):
2339N/A return self.__verbose_info
2339N/A
2339N/Aclass SuidUnsupportedError(ApiException):
2339N/A def __str__(self):
2339N/A return _("""
2339N/AThe pkg client api module can not be invoked from an setuid executable.""")
2524N/A
2524N/Aclass SubprocessError(ApiException):
2524N/A
2524N/A def __init__(self, rv, cmd):
2524N/A if type(cmd) == list:
2524N/A cmd = " ".join(cmd)
2524N/A assert type(cmd) == str
2524N/A self.err = _("The following subprocess returned an "
2524N/A "unexpected exit code of %(rv)d:\n%(cmd)s") % \
2524N/A {"rv": rv, "cmd": cmd}
2524N/A
2524N/A def __str__(self):
2524N/A return self.err
2524N/A
2524N/Aclass ImageLockedError(ApiException):
2524N/A """Used to indicate that the image is currently locked by another thread
2524N/A or process and cannot be modified."""
2524N/A
2524N/A def __init__(self, hostname=None, pid=None, pid_name=None):
2524N/A ApiException.__init__(self)
2524N/A self.hostname = hostname
2524N/A self.pid = pid
2524N/A self.pid_name = pid_name
2524N/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)
1710N/A self.user_specified = user_specified
1710N/A self.user_dir = user_dir
1710N/A self.root_dir = root_dir
1710N/A
1710N/A
1710N/Aclass ImageLocationAmbiguous(ApiException):
1710N/A """Used to indicate that an image was found at a location other than
1710N/A '/' on the Solaris platform when requesting automatic image location
1710N/A discovery. Clients should trap this exception and add their own
1710N/A messaging telling the user how to specify an image root explicitly
1710N/A for the location."""
1710N/A
1710N/A def __init__(self, root, live_root="/"):
1710N/A ApiException.__init__(self)
1710N/A self.root = root
3158N/A self.live_root = live_root
3158N/A
3158N/A def __str__(self):
1710N/A return _("pkg(5) image found at '%(found)s' instead of "
1710N/A "'%(expected)s'.") % { "found": self.root,
1710N/A "expected": self.live_root }
3158N/A
3158N/A
1710N/Aclass ImageFormatUpdateNeeded(ApiException):
1710N/A """Used to indicate that an image cannot be used until its format is
1710N/A updated."""
3158N/A
3158N/A def __init__(self, path):
1710N/A ApiException.__init__(self)
1710N/A self.path = path
1710N/A
565N/A def __str__(self):
565N/A return _("The image rooted at %s is written in an older format "
565N/A "and must be updated before the requested operation can be "
565N/A "performed.") % self.path
565N/A
565N/Aclass ImageInsufficentSpace(ApiException):
565N/A """Used when insuffcient space exists for proposed operation"""
565N/A def __init__(self, needed, avail, use):
2976N/A self.needed = needed
3158N/A self.avail = avail
2976N/A self.use = use
2144N/A
2144N/A def __str__(self):
2144N/A from pkg.misc import bytes_to_str
2144N/A return _("Insufficent disk space available (%(avail)s)"
2144N/A "for estimated need (%(needed)s) for %(use)s") % {
2144N/A "avail": bytes_to_str(self.avail),
2144N/A "needed": bytes_to_str(self.needed),
2144N/A "use": self.use
2144N/A }
2144N/A
3158N/A
2144N/Aclass VersionException(ApiException):
3158N/A def __init__(self, expected_version, received_version):
2144N/A ApiException.__init__(self)
2407N/A self.expected_version = expected_version
2407N/A self.received_version = received_version
2407N/A
2407N/A
2407N/Aclass PlanExistsException(ApiException):
2407N/A def __init__(self, plan_type):
2407N/A ApiException.__init__(self)
2407N/A self.plan_type = plan_type
2407N/A
3158N/A
3158N/Aclass PlanPrepareException(ApiException):
3158N/A """Base exception class for plan preparation errors."""
3158N/A pass
3158N/A
3158N/A
2875N/Aclass InvalidPackageErrors(ApiException):
2144N/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)
565N/A self.errors = errors
565N/A
565N/A def __str__(self):
565N/A return _("The requested operation cannot be completed due "
565N/A "to invalid package metadata. Details follow:\n\n"
1618N/A "%s") % "\n".join(str(e) for e in self.errors)
1618N/A
1618N/A
1618N/Aclass LicenseAcceptanceError(ApiException):
1618N/A """Used to indicate that license-related errors occurred during
1618N/A plan evaluation or execution."""
1755N/A
1755N/A def __init__(self, pfmri, src=None, dest=None, accepted=None,
1755N/A displayed=None):
1755N/A ApiException.__init__(self)
1755N/A self.fmri = pfmri
1755N/A self.src = src
1755N/A self.dest = dest
1755N/A self.accepted = accepted
1755N/A self.displayed = displayed
1755N/A
1755N/A
1755N/Aclass PkgLicenseErrors(PlanPrepareException):
1755N/A """Used to indicate that plan evaluation or execution failed due
1755N/A to license-related errors for a package."""
3158N/A
1755N/A def __init__(self, errors):
1755N/A """'errors' should be a list of LicenseAcceptanceError
1618N/A exceptions."""
1618N/A
1618N/A PlanPrepareException.__init__(self)
1618N/A self.__errors = errors
1618N/A
1618N/A @property
1618N/A def errors(self):
1618N/A """A list of LicenseAcceptanceError exceptions."""
1618N/A return self.__errors
1618N/A
1618N/A
1618N/Aclass PlanLicenseErrors(PlanPrepareException):
1618N/A """Used to indicate that image plan evaluation or execution failed due
1618N/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 = {}
1618N/A for pp_err in pp_errors:
1618N/A for e in pp_err.errors:
1618N/A pkgs.setdefault(str(e.fmri), []).append(e)
1618N/A
1618N/A @property
1618N/A def errors(self):
1618N/A """Returns a dictionary indexed by package FMRI string of
1618N/A lists of LicenseAcceptanceError exceptions."""
1618N/A
1618N/A return self.__errors
1618N/A
1618N/A def __str__(self):
1618N/A """Returns a string representation of the license errors."""
1618N/A
1618N/A output = ""
1618N/A for sfmri in self.__errors:
1618N/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)
3158N/A
1618N/A
1618N/Aclass PrematureExecutionException(ApiException):
3158N/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
1019N/A
1019N/Aclass ImageplanStateException(ApiException):
1019N/A def __init__(self, state):
1019N/A ApiException.__init__(self)
1019N/A self.state = state
1019N/A
1019N/A
1019N/Aclass InvalidPlanError(ApiException):
1618N/A """Used to indicate that the image plan is no longer valid, likely as a
565N/A result of an image state change since the plan was created."""
565N/A
565N/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 "
565N/A "process or client. Please try the operation again.")
565N/A
1618N/A
565N/Aclass ImagePkgStateError(ApiException):
565N/A
565N/A def __init__(self, fmri, states):
1618N/A ApiException.__init__(self)
565N/A self.fmri = fmri
565N/A self.states = states
565N/A
565N/A def __str__(self):
565N/A return _("Invalid package state change attempted '%(states)s' "
1369N/A "for package '%(fmri)s'.") % { "states": self.states,
1710N/A "fmri": self.fmri }
1710N/A
1710N/A
1710N/Aclass IpkgOutOfDateException(ApiException):
1710N/A pass
1710N/A
1710N/Aclass ImageUpdateOnLiveImageException(ApiException):
1710N/A pass
1710N/A
1710N/Aclass RebootNeededOnLiveImageException(ApiException):
1372N/A pass
1369N/A
1369N/Aclass CanceledException(ApiException):
1369N/A pass
1369N/A
1369N/Aclass PlanMissingException(ApiException):
1369N/A pass
1369N/A
3158N/Aclass NoPackagesInstalledException(ApiException):
3158N/A pass
3158N/A
1369N/Aclass PermissionsException(ApiException):
1369N/A def __init__(self, path):
565N/A ApiException.__init__(self)
2976N/A self.path = path
3356N/A
2976N/A def __str__(self):
565N/A if self.path:
565N/A return _("Could not operate on %s\nbecause of "
2976N/A "insufficient permissions. Please try the "
2976N/A "command again as a privileged user.") % \
2976N/A self.path
2976N/A else:
565N/A return _("""
1328N/ACould not complete the operation because of insufficient permissions.
2976N/APlease try the command again as a privileged user.
2976N/A""")
2976N/A
2976N/Aclass FileInUseException(PermissionsException):
1328N/A def __init__(self, path):
565N/A PermissionsException.__init__(self, path)
565N/A assert path
565N/A
565N/A def __str__(self):
565N/A return _("Could not operate on %s\nbecause the file is "
565N/A "in use. Please stop using the file and try the\n"
565N/A "operation again.") % self.path
565N/A
565N/A
685N/Aclass ReadOnlyFileSystemException(PermissionsException):
685N/A """Used to indicate that the operation was attempted on a
685N/A read-only filesystem"""
685N/A
685N/A def __init__(self, path):
685N/A ApiException.__init__(self)
685N/A self.path = path
3158N/A
2126N/A def __str__(self):
3158N/A if self.path:
3158N/A return _("Could not complete the operation on %s: "
685N/A "read-only filesystem.") % self.path
685N/A return _("Could not complete the operation: read-only "
2126N/A "filesystem.")
2126N/A
685N/A
685N/Aclass PackageMatchErrors(ApiException):
879N/A def __init__(self, unmatched_fmris=EmptyI, multiple_matches=EmptyI,
879N/A illegal=EmptyI, multispec=EmptyI):
879N/A ApiException.__init__(self)
879N/A self.unmatched_fmris = unmatched_fmris
879N/A self.multiple_matches = multiple_matches
879N/A self.illegal = illegal
3158N/A self.multispec = multispec
879N/A
3158N/A def __str__(self):
879N/A res = []
1335N/A if self.unmatched_fmris:
2612N/A s = _("The following pattern(s) did not match any "
2612N/A "packages:")
2612N/A
2612N/A res += [s]
2612N/A res += ["\t%s" % p for p in self.unmatched_fmris]
2612N/A
2612N/A if self.multiple_matches:
2612N/A s = _("'%s' matches multiple packages")
2612N/A for p, lst in self.multiple_matches:
2612N/A res.append(s % p)
1335N/A for pfmri in lst:
1945N/A res.append("\t%s" % pfmri)
1335N/A
1335N/A if self.illegal:
1335N/A s = _("'%s' is an illegal FMRI")
1335N/A res += [ s % p for p in self.illegal ]
1335N/A
1335N/A if self.multispec:
1335N/A s = _("The following different patterns specify the "
1335N/A "same package(s):")
3158N/A res += [s]
3158N/A for t in self.multispec:
1335N/A res += [
1335N/A ", ".join([t[i] for i in range(1, len(t))])
1335N/A + ": %s" % t[0]
1335N/A ]
2974N/A
2974N/A return "\n".join(res)
2974N/A
2974N/A
2974N/Aclass PlanCreationException(ApiException):
2974N/A def __init__(self,
3158N/A already_installed=EmptyI,
3158N/A badarch=EmptyI,
3158N/A illegal=EmptyI,
2974N/A installed=EmptyI,
2974N/A linked_pub_error=EmptyI,
2301N/A missing_dependency=EmptyI,
2510N/A missing_matches=EmptyI,
2510N/A multiple_matches=EmptyI,
2510N/A multispec=EmptyI,
2301N/A no_solution=False,
2301N/A no_tmp_origins=False,
2301N/A no_version=EmptyI,
2301N/A nofiles=EmptyI,
2301N/A obsolete=EmptyI,
2301N/A pkg_updates_required=EmptyI,
2301N/A solver_errors=EmptyI,
2301N/A unmatched_fmris=EmptyI,
2301N/A would_install=EmptyI,
2301N/A wrong_publishers=EmptyI,
2301N/A wrong_variants=EmptyI):
2301N/A
2301N/A ApiException.__init__(self)
2301N/A self.already_installed = already_installed
2301N/A self.badarch = badarch
3158N/A self.illegal = illegal
2301N/A self.installed = installed
2301N/A self.linked_pub_error = linked_pub_error
3158N/A self.missing_dependency = missing_dependency
2301N/A self.missing_matches = missing_matches
3158N/A self.multiple_matches = multiple_matches
2301N/A self.multispec = multispec
3158N/A self.no_solution = no_solution
2301N/A self.no_tmp_origins = no_tmp_origins
2301N/A self.no_version = no_version
3158N/A self.nofiles = nofiles
3158N/A self.obsolete = obsolete
2301N/A self.pkg_updates_required = pkg_updates_required
2301N/A self.solver_errors = solver_errors
2301N/A self.unmatched_fmris = unmatched_fmris
2301N/A self.would_install = would_install
2301N/A self.wrong_publishers = wrong_publishers
2301N/A self.wrong_variants = wrong_variants
2301N/A
2301N/A def __str__(self):
3158N/A res = []
2301N/A if self.unmatched_fmris:
2301N/A s = _("""\
2301N/AThe following pattern(s) did not match any allowable packages. Try
2301N/Ausing a different matching pattern, or refreshing the image:
2301N/A""")
3384N/A res += [s]
3384N/A res += ["\t%s" % p for p in self.unmatched_fmris]
3384N/A
3384N/A if self.wrong_variants:
3384N/A s = _("""\
3384N/AThe following pattern(s) only matched packages that are not available
3384N/Afor the current image's architecture, zone type, and/or other variant:""")
3384N/A res += [s]
3384N/A res += ["\t%s" % p for p in self.wrong_variants]
3384N/A
3384N/A if self.wrong_publishers:
3384N/A s = _("The following patterns only matched packages "
3384N/A "that are from publishers other than that which "
3384N/A "supplied the already installed version of this package")
3384N/A res += [s]
3384N/A res += ["\t%s: %s" % (p[0], ", ".join(p[1])) for p in self.wrong_publishers]
565N/A
2339N/A if self.multiple_matches:
2339N/A s = _("'%s' matches multiple packages")
2339N/A for p, lst in self.multiple_matches:
2339N/A res.append(s % p)
2339N/A for pfmri in lst:
2453N/A res.append("\t%s" % pfmri)
2339N/A
2339N/A if self.missing_matches:
2339N/A s = _("'%s' matches no installed packages")
2339N/A res += [ s % p for p in self.missing_matches ]
2339N/A
2339N/A if self.illegal:
2339N/A s = _("'%s' is an illegal fmri")
2339N/A res += [ s % p for p in self.illegal ]
2505N/A
2339N/A if self.badarch:
2339N/A s = _("'%s' supports the following architectures: %s")
2339N/A a = _("Image architecture is defined as: %s")
2445N/A res += [ s % (self.badarch[0],
2339N/A ", ".join(self.badarch[1]))]
3110N/A res += [ a % (self.badarch[2])]
2339N/A
2339N/A s = _("'%(p)s' depends on obsolete package '%(op)s'")
2339N/A res += [ s % {"p": p, "op": op} for p, op in self.obsolete ]
2339N/A
2339N/A if self.installed:
565N/A s = _("The proposed operation can not be performed for "
2339N/A "the following package(s) as they are already "
2339N/A "installed: ")
2339N/A res += [s]
2339N/A res += ["\t%s" % p for p in self.installed]
2453N/A
2339N/A if self.multispec:
2339N/A s = _("The following different patterns specify the "
2339N/A "same package(s):")
1505N/A res += [s]
1505N/A for t in self.multispec:
2339N/A res += [
2339N/A ", ".join(
2339N/A [t[i] for i in range(1, len(t))])
2505N/A + ": %s" % t[0]
2339N/A ]
2207N/A if self.no_solution:
2339N/A res += [_("No solution was found to satisfy constraints")]
2445N/A if isinstance(self.no_solution, list):
2339N/A res.extend(self.no_solution)
2339N/A
3110N/A if self.pkg_updates_required:
2339N/A s = _("""\
1505N/ASyncing this linked image would require the following package updates:
2212N/A""")
2339N/A res += [s]
565N/A for (oldfmri, newfmri) in self.pkg_updates_required:
616N/A res += ["%(oldfmri)s -> %(newfmri)s\n" % \
1141N/A {"oldfmri": oldfmri, "newfmri": newfmri}]
616N/A
2339N/A if self.no_version:
2445N/A res += self.no_version
2339N/A
926N/A if self.no_tmp_origins:
3158N/A s = _("""
565N/AThe proposed operation on this parent image can not be performed because
2445N/Atemporary origins were specified and this image has children. Please either
2445N/Aretry the operation again without specifying any temporary origins, or if
2445N/Apackages from additional origins are required, please configure those origins
2445N/Apersistently.""")
2445N/A res = [s]
2445N/A
3158N/A if self.missing_dependency:
2445N/A res += [_("Package %(pkg)s is missing a dependency: "
2212N/A "%(dep)s") %
2212N/A {"pkg": self.missing_dependency[0],
2212N/A "dep": self.missing_dependency[1]}]
2212N/A if self.nofiles:
2212N/A res += [_("The following files are not packaged in this image:")]
3158N/A res += ["\t%s" % f for f in self.nofiles]
2212N/A
1505N/A if self.solver_errors:
1505N/A res += ["\n"]
1505N/A res += [_("Solver dependency errors:")]
1505N/A res.extend(self.solver_errors)
1505N/A
3158N/A if self.already_installed:
1505N/A res += [_("The following packages are already "
565N/A "installed in this image; use uninstall to "
3158N/A "avoid these:")]
565N/A res += [ "\t%s" % s for s in self.already_installed]
3158N/A
922N/A if self.would_install:
3158N/A res += [_("The following packages are a target "
616N/A "of group dependencies; use install to unavoid "
1505N/A "these:")]
3158N/A res += [ "\t%s" % s for s in self.would_install]
3158N/A
616N/A def __format_li_pubs(pubs, res):
1505N/A i = 0
3158N/A for pub, sticky in pubs:
3158N/A s = " %s %d: %s" % (_("PUBLISHER"), i, pub)
655N/A mod = []
838N/A if not sticky:
3158N/A mod.append(_("non-sticky"))
3158N/A if mod:
3158N/A s += " (%s)" % ",".join(mod)
3158N/A res.append(s)
3158N/A i += 1
3158N/A
3158N/A if self.linked_pub_error:
3158N/A res = []
3158N/A (pubs, parent_pubs) = self.linked_pub_error
1461N/A
1352N/A res.append(_("""
1352N/AInvalid child image publisher configuration. Child image publisher
1352N/Aconfiguration must be a superset of the parent image publisher configuration.
1352N/APlease update the child publisher configuration to match the parent. If the
1352N/Achild image is a zone this can be done automatically by detaching and
3158N/Aattaching the zone.
1352N/A
2453N/AThe parent image has the following enabled publishers:"""))
2453N/A __format_li_pubs(parent_pubs, res)
2453N/A res.append(_("""
3234N/AThe child image has the following enabled publishers:"""))
2453N/A __format_li_pubs(pubs, res)
2453N/A
2453N/A return "\n".join(res)
1505N/A
2681N/A
2681N/Aclass ConflictingActionError(ApiException):
1505N/A """Used to indicate that the imageplan would result in one or more sets
1505N/A of conflicting actions, meaning that more than one action would exist on
1505N/A the system with the same key attribute value in the same namespace.
1505N/A There are three categories, each with its own subclass:
1505N/A
3158N/A - multiple files delivered to the same path or drivers, users, groups,
1945N/A etc, delivered with the same key attribute;
1505N/A
1505N/A - multiple objects delivered to the same path which aren't the same
2197N/A type;
2197N/A
2207N/A - multiple directories, links, or hardlinks delivered to the same path
2339N/A but with conflicting attributes.
2339N/A """
2339N/A
2339N/A def __init__(self, data):
2339N/A self._data = data
2339N/A
3158N/Aclass ConflictingActionErrors(ApiException):
3158N/A """A container for multiple ConflictingActionError exception objects
2339N/A that can be raised as a single exception."""
1505N/A
1505N/A def __init__(self, errors):
1505N/A self.__errors = errors
2339N/A
2339N/A def __str__(self):
2339N/A return "\n\n".join((str(err) for err in self.__errors))
2339N/A
2339N/Aclass DuplicateActionError(ConflictingActionError):
2339N/A """Multiple actions of the same type have been delivered with the same
2339N/A key attribute (when not allowed)."""
2339N/A
2339N/A def __str__(self):
1505N/A pfmris = set((a[1] for a in self._data))
3158N/A kv = self._data[0][0].attrs[self._data[0][0].key_attr]
3158N/A action = self._data[0][0].name
3158N/A if len(pfmris) > 1:
3158N/A s = _("The following packages all deliver %(action)s "
2200N/A "actions to %(kv)s:\n") % locals()
2200N/A for a, p in self._data:
3158N/A s += "\n %s" % p
1945N/A s += _("\n\nThese packages may not be installed together. "
2207N/A "Any non-conflicting set may\nbe, or the packages "
2207N/A "must be corrected before they can be installed.")
2207N/A else:
2207N/A pfmri = pfmris.pop()
2207N/A s = _("The package %(pfmri)s delivers multiple copies "
2228N/A "of %(action)s %(kv)s") % locals()
2339N/A s += _("\nThis package must be corrected before it "
2339N/A "can be installed.")
2339N/A
3158N/A return s
2228N/A
2228N/Aclass InconsistentActionTypeError(ConflictingActionError):
2339N/A """Multiple actions of different types have been delivered with the same
2339N/A 'path' attribute. While this exception could represent other action
2339N/A groups which share a single namespace, none such exist."""
3158N/A
2228N/A def __str__(self):
2505N/A ad = {}
2505N/A pfmris = set()
2505N/A kv = self._data[0][0].attrs[self._data[0][0].key_attr]
3158N/A for a, p in self._data:
2505N/A ad.setdefault(a.name, []).append(p)
2339N/A pfmris.add(p)
2339N/A
2339N/A if len(pfmris) > 1:
3158N/A s = _("The following packages deliver conflicting "
3158N/A "action types to %s:\n") % kv
2339N/A for name, pl in ad.iteritems():
2339N/A s += "\n %s:" % name
2339N/A s += "".join("\n %s" % p for p in pl)
2339N/A s += _("\n\nThese packages may not be installed together. "
3158N/A "Any non-conflicting set may\nbe, or the packages "
2339N/A "must be corrected before they can be installed.")
2339N/A else:
2339N/A pfmri = pfmris.pop()
2339N/A types = list_to_lang(ad.keys())
2339N/A s = _("The package %(pfmri)s delivers conflicting "
2339N/A "action types (%(types)s) to %(kv)s") % locals()
2339N/A s += _("\nThis package must be corrected before it "
2339N/A "can be installed.")
2339N/A return s
2364N/A
2339N/Aclass InconsistentActionAttributeError(ConflictingActionError):
2339N/A """Multiple actions of the same type representing the same object have
2339N/A have been delivered, but with conflicting attributes, such as two
2339N/A directories at /usr with groups 'root' and 'sys', or two 'root' users
2339N/A with uids '0' and '7'."""
2339N/A
2339N/A def __str__(self):
2339N/A actions = self._data
2339N/A keyattr = actions[0][0].attrs[actions[0][0].key_attr]
2339N/A actname = actions[0][0].name
3110N/A
3110N/A # Trim the action's attributes to only those required to be
3110N/A # unique.
3110N/A def ou(action):
3110N/A ua = dict(
3158N/A (k, v)
3110N/A for k, v in action.attrs.iteritems()
3110N/A if k in action.unique_attrs and
1352N/A not (k == "preserve" and "overlay" in action.attrs)
565N/A )
2228N/A action.attrs = ua
2205N/A return action
2205N/A
2205N/A d = {}
2205N/A for a in actions:
2205N/A if a[0].attrs.get("implicit", "false") == "false":
2205N/A d.setdefault(str(ou(a[0])), set()).add(a[1])
2205N/A l = sorted([
2205N/A (len(pkglist), action, pkglist)
2205N/A for action, pkglist in d.iteritems()
2205N/A ])
2205N/A
2205N/A s = _("The requested change to the system attempts to install "
2205N/A "multiple actions\nfor %(a)s '%(k)s' with conflicting "
2205N/A "attributes:\n\n") % {"a": actname, "k": keyattr}
2205N/A allpkgs = set()
2205N/A for num, action, pkglist in l:
2205N/A allpkgs.update(pkglist)
2205N/A if num <= 5:
2205N/A if num == 1:
2205N/A t = _(" %(n)d package delivers '%(a)s':\n")
2205N/A else:
2205N/A t = _(" %(n)d packages deliver '%(a)s':\n")
2205N/A s += t % {"n": num, "a": action}
2205N/A for pkg in sorted(pkglist):
2205N/A s += _(" %s\n") % pkg
2205N/A else:
2205N/A t = _(" %d packages deliver '%s', including:\n")
2205N/A s += t % (num, action)
2205N/A for pkg in sorted(pkglist)[:5]:
2205N/A s += _(" %s\n") % pkg
2205N/A
2205N/A if len(allpkgs) == 1:
2205N/A s += _("\nThis package must be corrected before it "
2205N/A "can be installed.")
2205N/A else:
2205N/A s += _("\nThese packages may not be installed together."
2205N/A " Any non-conflicting set may\nbe, or the packages "
2205N/A "must be corrected before they can be installed.")
3158N/A
3158N/A return s
2205N/A
3158N/Adef list_to_lang(l):
3347N/A """Takes a list of items and puts them into a string, with commas in
3347N/A between items, and an "and" between the last two items. Special cases
3347N/A for lists of two or fewer items, and uses the Oxford comma."""
2205N/A
2205N/A if not l:
3158N/A return ""
3158N/A if len(l) == 1:
2205N/A return l[0]
2205N/A if len(l) == 2:
2205N/A # Used for a two-element list
2205N/A return _("%(penultimate)s and %(ultimate)s") % {
2205N/A "penultimate": l[0],
2205N/A "ultimate": l[1]
2205N/A }
2205N/A # In order to properly i18n this construct, we create two templates:
2205N/A # one for each element save the last, and one that tacks on the last
2205N/A # element.
2205N/A # 'elementtemplate' is for each element through the penultimate
2205N/A elementtemplate = _("%s, ")
2205N/A # 'listtemplate' concatenates the concatenation of non-ultimate elements
2205N/A # and the ultimate element.
2205N/A listtemplate = _("%(list)sand %(tail)s")
2205N/A return listtemplate % {
2205N/A "list": "".join(elementtemplate % i for i in l[:-1]),
2205N/A "tail": l[-1]
2205N/A }
2205N/A
3158N/Aclass ActionExecutionError(ApiException):
3234N/A """Used to indicate that action execution (such as install, remove,
3158N/A etc.) failed even though the action is valid.
3158N/A
3347N/A In particular, this exception indicates that something went wrong in the
3347N/A application (or unapplication) of the action to the system, and is most
3347N/A likely not an error in the pkg(5) code."""
2205N/A
2205N/A def __init__(self, action, details=None, error=None, fmri=None,
3234N/A use_errno=None):
3158N/A """'action' is the object for the action that failed during the
3158N/A requested operation.
2205N/A
2205N/A 'details' is an optional message explaining what operation
2205N/A failed, why it failed, and why it cannot continue. It should
2205N/A also include a suggestion as to how to resolve the situation
2205N/A if possible.
2205N/A
2205N/A 'error' is an optional exception object that may have been
2205N/A raised when the operation failed.
2205N/A
2205N/A 'fmri' is an optional package FMRI indicating what package
2205N/A was being operated on at the time the error occurred.
2205N/A
2205N/A 'use_errno' is an optional boolean value indicating whether
2205N/A the strerror() text of the exception should be used. If
2205N/A 'details' is provided, the default value is False, otherwise
2205N/A True."""
2205N/A
2205N/A assert (details or error)
2205N/A self.action = action
2205N/A self.details = details
3234N/A self.error = error
2453N/A self.fmri = fmri
2453N/A if use_errno == None:
2453N/A # If details were provided, don't use errno unless
2453N/A # explicitly requested.
2205N/A use_errno = not details
2205N/A self.use_errno = use_errno
2205N/A
2205N/A def __str__(self):
2205N/A errno = ""
2205N/A if self.use_errno and self.error and \
2232N/A hasattr(self.error, "errno"):
2232N/A errno = "[errno %d: %s]" % (self.error.errno,
2205N/A os.strerror(self.error.errno))
2205N/A
3234N/A details = self.details or ""
2205N/A
2205N/A # Fall back on the wrapped exception if we don't have anything
2205N/A # useful.
3158N/A if not errno and not details:
3158N/A return str(self.error)
2205N/A
2205N/A if errno and details:
2205N/A details = "%s: %s" % (errno, details)
2205N/A
2205N/A if details and not self.fmri:
3158N/A details = _("Requested operation failed for action "
2205N/A "%(action)s:\n%(details)s") % {
3158N/A "action": self.action,
3158N/A "details": details }
2205N/A elif details:
3158N/A details = _("Requested operation failed for package "
2205N/A "%(fmri)s:\n%(details)s") % { "fmri": self.fmri,
3158N/A "details": details }
3158N/A
2205N/A # If we only have one of the two, no need for the colon.
3158N/A return "%s%s" % (errno, details)
2205N/A
2205N/A
2239N/Aclass CatalogRefreshException(ApiException):
2205N/A def __init__(self, failed, total, succeeded, errmessage=None):
2205N/A ApiException.__init__(self)
3347N/A self.failed = failed
3347N/A self.total = total
3347N/A self.succeeded = succeeded
2205N/A self.errmessage = errmessage
2205N/A
2205N/A
3206N/Aclass CatalogError(ApiException):
3206N/A """Base exception class for all catalog exceptions."""
3206N/A
3206N/A def __init__(self, *args, **kwargs):
3206N/A ApiException.__init__(self)
3206N/A if args:
3206N/A self.data = args[0]
3206N/A else:
3206N/A self.data = None
3206N/A self._args = kwargs
3206N/A
3206N/A def __str__(self):
3206N/A return str(self.data)
3206N/A
3206N/A
3206N/Aclass AnarchicalCatalogFMRI(CatalogError):
3206N/A """Used to indicate that the specified FMRI is not valid for catalog
3206N/A operations because it is missing publisher information."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("The FMRI '%s' does not contain publisher information "
3206N/A "and cannot be used for catalog operations.") % self.data
3206N/A
3206N/A
3206N/Aclass BadCatalogMetaRoot(CatalogError):
3206N/A """Used to indicate an operation on the catalog's meta_root failed
3206N/A because the meta_root is invalid."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("Catalog meta_root '%(root)s' is invalid; unable "
3206N/A "to complete operation: '%(op)s'.") % { "root": self.data,
3206N/A "op": self._args.get("operation", None) }
3206N/A
3206N/A
3206N/Aclass BadCatalogPermissions(CatalogError):
3206N/A """Used to indicate the server catalog files do not have the expected
3206N/A permissions."""
3206N/A
3206N/A def __init__(self, files):
3206N/A """files should contain a list object with each entry consisting
3206N/A of a tuple of filename, expected_mode, received_mode."""
3206N/A if not files:
3206N/A files = []
3206N/A CatalogError.__init__(self, files)
3206N/A
3206N/A def __str__(self):
3206N/A msg = _("The following catalog files have incorrect "
3206N/A "permissions:\n")
3206N/A for f in self._args:
3206N/A fname, emode, fmode = f
3206N/A msg += _("\t%(fname)s: expected mode: %(emode)s, found "
3206N/A "mode: %(fmode)s\n") % { "fname": fname,
3206N/A "emode": emode, "fmode": fmode }
3206N/A return msg
3206N/A
3206N/A
3206N/Aclass BadCatalogSignatures(CatalogError):
3206N/A """Used to indicate that the Catalog signatures are not valid."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("The signature data for the '%s' catalog file is not "
3206N/A "valid.") % self.data
3206N/A
3206N/A
3206N/Aclass BadCatalogUpdateIdentity(CatalogError):
3206N/A """Used to indicate that the requested catalog updates could not be
3206N/A applied as the new catalog data is significantly different such that
3206N/A the old catalog cannot be updated to match it."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("Unable to determine the updates needed for "
3206N/A "the current catalog using the provided catalog "
3206N/A "update data in '%s'.") % self.data
3206N/A
3206N/A
3206N/Aclass DuplicateCatalogEntry(CatalogError):
3206N/A """Used to indicate that the specified catalog operation could not be
3206N/A performed since it would result in a duplicate catalog entry."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("Unable to perform '%(op)s' operation for catalog "
3206N/A "%(name)s; completion would result in a duplicate entry "
3206N/A "for package '%(fmri)s'.") % { "op": self._args.get(
3206N/A "operation", None), "name": self._args.get("catalog_name",
3206N/A None), "fmri": self.data }
3206N/A
3206N/A
3206N/Aclass CatalogUpdateRequirements(CatalogError):
3206N/A """Used to indicate that an update request for the catalog could not
3206N/A be performed because update requirements were not satisfied."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("Catalog updates can only be applied to an on-disk "
3206N/A "catalog.")
3206N/A
3206N/A
3206N/Aclass InvalidCatalogFile(CatalogError):
3206N/A """Used to indicate a Catalog file could not be loaded."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("Catalog file '%s' is invalid.") % self.data
3206N/A
3206N/A
3206N/Aclass MismatchedCatalog(CatalogError):
3206N/A """Used to indicate that a Catalog's attributes and parts do not
3206N/A match. This is likely the result of an attributes file being
3206N/A retrieved which doesn't match the parts that were retrieved such
3206N/A as in a misconfigured or stale cache case."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("The content of the catalog for publisher '%s' "
3206N/A "doesn't match the catalog's attributes. This is "
3206N/A "likely the result of a mix of older and newer "
3206N/A "catalog files being provided for the publisher.") % \
3206N/A self.data
3206N/A
3206N/A
3206N/Aclass ObsoleteCatalogUpdate(CatalogError):
3206N/A """Used to indicate that the specified catalog updates are for an older
3206N/A version of the catalog and cannot be applied."""
3206N/A
3206N/A def __str__(self):
3206N/A return _("Unable to determine the updates needed for the "
3206N/A "catalog using the provided catalog update data in '%s'. "
2205N/A "The specified catalog updates are for an older version "
2205N/A "of the catalog and cannot be used.") % self.data
2205N/A
2205N/A
2205N/Aclass UnknownCatalogEntry(CatalogError):
2205N/A """Used to indicate that an entry for the specified package FMRI or
2205N/A pattern could not be found in the catalog."""
2205N/A
2205N/A def __str__(self):
2205N/A return _("'%s' could not be found in the catalog.") % self.data
2205N/A
3158N/A
3158N/Aclass UnknownUpdateType(CatalogError):
3158N/A """Used to indicate that the specified CatalogUpdate operation is
3158N/A unknown."""
2205N/A
2205N/A def __str__(self):
2205N/A return _("Unknown catalog update type '%s'") % self.data
2205N/A
3158N/A
2205N/Aclass UnrecognizedCatalogPart(CatalogError):
2205N/A """Raised when the catalog finds a CatalogPart that is unrecognized
3158N/A or invalid."""
3158N/A
3158N/A def __str__(self):
3158N/A return _("Unrecognized, unknown, or invalid CatalogPart '%s'") \
3158N/A % self.data
1068N/A
1050N/A
1859N/Aclass InventoryException(ApiException):
1859N/A """Used to indicate that some of the specified patterns to a catalog
1050N/A matching function did not match any catalog entries, or were invalid
1050N/A patterns."""
1859N/A
3356N/A def __init__(self, illegal=EmptyI, matcher=EmptyI, notfound=EmptyI,
1859N/A publisher=EmptyI, version=EmptyI):
1859N/A ApiException.__init__(self)
1859N/A self.illegal = illegal
1859N/A self.matcher = matcher
1859N/A self.notfound = set(notfound)
1859N/A self.publisher = publisher
1859N/A self.version = version
1859N/A
1859N/A self.notfound.update(matcher)
1859N/A self.notfound.update(publisher)
1859N/A self.notfound.update(version)
1859N/A self.notfound = list(self.notfound)
1859N/A
1050N/A assert self.illegal or self.notfound
1859N/A
1859N/A def __str__(self):
1859N/A outstr = ""
1859N/A for x in self.illegal:
1859N/A # Illegal FMRIs have their own __str__ method
1859N/A outstr += "%s\n" % x
1859N/A
1050N/A if self.matcher or self.publisher or self.version:
1859N/A outstr += _("No matching package could be found for "
1050N/A "the following FMRIs in any of the catalogs for "
1859N/A "the current publishers:\n")
1859N/A
1859N/A for x in self.matcher:
1859N/A outstr += _("%s (pattern did not match)\n") % x
1859N/A for x in self.publisher:
1859N/A outstr += _("%s (publisher did not "
1859N/A "match)\n") % x
1859N/A for x in self.version:
1050N/A outstr += _("%s (version did not match)\n") % x
1050N/A return outstr
1050N/A
1859N/A
1859N/A# SearchExceptions
3158N/A
1859N/Aclass SearchException(ApiException):
1050N/A """Based class used for all search-related api exceptions."""
1859N/A pass
1050N/A
1050N/A
1050N/Aclass MalformedSearchRequest(SearchException):
1859N/A """Raised when the server cannot understand the format of the
1859N/A search request."""
1859N/A
1859N/A def __init__(self, url):
3158N/A SearchException.__init__(self)
1050N/A self.url = url
1859N/A
1859N/A def __str__(self):
3158N/A return str(self.url)
3158N/A
3158N/A
1859N/Aclass NegativeSearchResult(SearchException):
1859N/A """Returned when the search cannot find any matches."""
3158N/A
3158N/A def __init__(self, url):
1050N/A SearchException.__init__(self)
1050N/A self.url = url
3158N/A
1050N/A def __str__(self):
1068N/A return _("The search at url %s returned no results.") % self.url
3293N/A
3293N/A
3293N/Aclass ProblematicSearchServers(SearchException):
3293N/A """This class wraps exceptions which could appear while trying to
3293N/A do a search request."""
3293N/A
3293N/A def __init__(self, failed=EmptyI, invalid=EmptyI, unsupported=EmptyI):
3293N/A SearchException.__init__(self)
565N/A self.failed_servers = failed
1603N/A self.invalid_servers = invalid
565N/A self.unsupported_servers = unsupported
565N/A
565N/A def __str__(self):
565N/A s = _("Some repositories failed to respond appropriately:\n")
1603N/A for pub, err in self.failed_servers:
565N/A s += _("%(o)s:\n%(msg)s\n") % \
1068N/A { "o": pub, "msg": err}
1352N/A for pub in self.invalid_servers:
1352N/A s += _("%s did not return a valid response.\n" \
1352N/A % pub)
1352N/A if len(self.unsupported_servers) > 0:
565N/A s += _("Some repositories don't support requested "
1352N/A "search operation:\n")
1352N/A for pub, err in self.unsupported_servers:
1352N/A s += _("%(o)s:\n%(msg)s\n") % \
1352N/A { "o": pub, "msg": err}
1516N/A
1352N/A return s
1352N/A
1352N/A
1352N/Aclass SlowSearchUsed(SearchException):
1352N/A """This exception is thrown when a local search is performed without
1352N/A an index. It's raised after all results have been yielded."""
1352N/A
1352N/A def __str__(self):
1352N/A return _("Search performance is degraded.\n"
1352N/A "Run 'pkg rebuild-index' to improve search speed.")
3158N/A
3158N/A
3158N/Aclass UnsupportedSearchError(SearchException):
1352N/A """Returned when a search protocol is not supported by the
1352N/A remote server."""
1352N/A
1352N/A def __init__(self, url=None, proto=None):
1352N/A SearchException.__init__(self)
1352N/A self.url = url
1352N/A self.proto = proto
3158N/A
3158N/A def __str__(self):
3158N/A s = _("Search repository does not support the requested "
1352N/A "protocol:")
1352N/A if self.url:
1352N/A s += "\nRepository URL: %s" % self.url
1352N/A if self.proto:
1352N/A s += "\nRequested operation: %s" % self.proto
1352N/A return s
1352N/A
1352N/A def __cmp__(self, other):
1352N/A if not isinstance(other, UnsupportedSearchError):
1352N/A return -1
1352N/A r = cmp(self.url, other.url)
1352N/A if r != 0:
1352N/A return r
1352N/A return cmp(self.proto, other.proto)
1352N/A
1352N/A
2614N/A# IndexingExceptions.
1352N/A
3158N/Aclass IndexingException(SearchException):
3158N/A """ The base class for all exceptions that can occur while indexing. """
3158N/A
1352N/A def __init__(self, private_exception):
1352N/A SearchException.__init__(self)
1352N/A self.cause = private_exception.cause
1352N/A
1352N/A
1352N/Aclass CorruptedIndexException(IndexingException):
1352N/A """This is used when the index is not in a correct state."""
3158N/A pass
3158N/A
1352N/A
1352N/Aclass InconsistentIndexException(IndexingException):
1352N/A """This is used when the existing index is found to have inconsistent
1352N/A versions."""
1352N/A def __init__(self, e):
1352N/A IndexingException.__init__(self, e)
1352N/A self.exception = e
1352N/A
1352N/A def __str__(self):
1352N/A return str(self.exception)
3158N/A
1352N/A
1352N/Aclass IndexLockedException(IndexingException):
1352N/A """This is used when an attempt to modify an index locked by another
1352N/A process or thread is made."""
1352N/A
1352N/A def __init__(self, e):
1352N/A IndexingException.__init__(self, e)
3158N/A self.exception = e
3158N/A
3158N/A def __str__(self):
3158N/A return str(self.exception)
3158N/A
1352N/A
1352N/Aclass ProblematicPermissionsIndexException(IndexingException):
1352N/A """ This is used when the indexer is unable to create, move, or remove
1352N/A files or directories it should be able to. """
1352N/A def __str__(self):
1352N/A return "Could not remove or create " \
1352N/A "%s because of incorrect " \
1352N/A "permissions. Please correct this issue then " \
1352N/A "rebuild the index." % self.cause
1352N/A
1352N/Aclass WrapIndexingException(ApiException):
1352N/A """This exception is used to wrap an indexing exception during install,
1352N/A uninstall, or update so that a more appropriate error message can be
1352N/A displayed to the user."""
1352N/A
3158N/A def __init__(self, e, tb, stack):
3158N/A ApiException.__init__(self)
1352N/A self.wrapped = e
1352N/A self.tb = tb
2022N/A self.stack = stack
2022N/A
2022N/A def __str__(self):
2022N/A tmp = self.tb.split("\n")
2022N/A res = tmp[:1] + [s.rstrip("\n") for s in self.stack] + tmp[1:]
2022N/A return "\n".join(res)
2022N/A
3158N/A
2022N/Aclass WrapSuccessfulIndexingException(WrapIndexingException):
2022N/A """This exception is used to wrap an indexing exception during install,
3158N/A uninstall, or update which was recovered from by performing a full
3158N/A reindex."""
2022N/A pass
2022N/A
1352N/A
1352N/A# Query Parsing Exceptions
1352N/Aclass BooleanQueryException(ApiException):
1352N/A """This exception is used when the children of a boolean operation
1352N/A have different return types. The command 'pkg search foo AND <bar>'
1352N/A is the simplest example of this."""
3158N/A
1352N/A def __init__(self, e):
3158N/A ApiException.__init__(self)
1352N/A self.e = e
1352N/A
1352N/A def __str__(self):
1352N/A return str(self.e)
1352N/A
1352N/A
1352N/Aclass ParseError(ApiException):
3158N/A def __init__(self, e):
3158N/A ApiException.__init__(self)
1352N/A self.e = e
1352N/A
1352N/A def __str__(self):
1352N/A return str(self.e)
1352N/A
1352N/A
1352N/Aclass NonLeafPackageException(ApiException):
3158N/A """Removal of a package which satisfies dependencies has been attempted.
1352N/A
1352N/A The first argument to the constructor is the FMRI which we tried to
1431N/A remove, and is available as the "fmri" member of the exception. The
1431N/A second argument is the list of dependent packages that prevent the
1431N/A removal of the package, and is available as the "dependents" member.
1431N/A """
1431N/A
3158N/A def __init__(self, *args):
3158N/A ApiException.__init__(self, *args)
1431N/A
1431N/A self.fmri = args[0]
1352N/A self.dependents = args[1]
1352N/A
1970N/Adef _str_autofix(self):
1970N/A
1352N/A if getattr(self, "_autofix_pkgs", []):
1352N/A s = _("\nThis is happening because the following "
1352N/A "packages needed to be repaired as\npart of this "
1352N/A "operation:\n\n ")
838N/A s += "\n ".join(str(f) for f in self._autofix_pkgs)
1352N/A s += _("\n\nYou will need to reestablish your access to the "
1352N/A "repository or remove the\npackages in the list above.")
1352N/A return s
1352N/A return ""
1352N/A
1352N/Aclass InvalidDepotResponseException(ApiException):
1352N/A """Raised when the depot doesn't have versions of operations
1352N/A that the client needs to operate successfully."""
3107N/A def __init__(self, url, data):
1352N/A ApiException.__init__(self)
1945N/A self.url = url
565N/A self.data = data
596N/A
596N/A def __str__(self):
596N/A s = _("Unable to contact valid package repository")
596N/A if self.url:
3158N/A s += _(": %s") % self.url
614N/A if self.data:
1352N/A s += ("\nEncountered the following error(s):\n%s") % \
614N/A self.data
614N/A
926N/A s += _str_autofix(self)
614N/A
1352N/A return s
3158N/A
3158N/Aclass DataError(ApiException):
1352N/A """Base exception class used for all data related errors."""
3158N/A
3158N/A def __init__(self, *args, **kwargs):
1352N/A ApiException.__init__(self, *args)
3158N/A if args:
3158N/A self.data = args[0]
596N/A else:
565N/A self.data = None
1027N/A self._args = kwargs
1191N/A
1191N/A
1027N/Aclass InvalidP5IFile(DataError):
1027N/A """Used to indicate that the specified location does not contain a
1027N/A valid p5i-formatted file."""
1027N/A
1027N/A def __str__(self):
1191N/A if self.data:
1191N/A return _("The provided p5i data is in an unrecognized "
1191N/A "format or does not contain valid publisher "
1191N/A "information: %s") % self.data
1191N/A return _("The provided p5i data is in an unrecognized format "
1191N/A "or does not contain valid publisher information.")
1191N/A
1191N/A
1191N/Aclass InvalidP5SFile(DataError):
1191N/A """Used to indicate that the specified location does not contain a
1191N/A valid p5i-formatted file."""
1191N/A
1191N/A def __str__(self):
1191N/A if self.data:
1191N/A return _("The provided p5s data is in an unrecognized "
1191N/A "format or does not contain valid publisher "
1191N/A "information: %s") % self.data
1191N/A return _("The provided p5s data is in an unrecognized format "
1191N/A "or does not contain valid publisher information.")
1191N/A
3158N/A
3158N/Aclass UnsupportedP5IFile(DataError):
1191N/A """Used to indicate that an attempt to read an unsupported version
1191N/A of pkg(5) info file was attempted."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("Unsupported pkg(5) publisher information data "
1191N/A "format.")
1191N/A
1191N/A
1191N/Aclass UnsupportedP5SFile(DataError):
1191N/A """Used to indicate that an attempt to read an unsupported version
1191N/A of pkg(5) info file was attempted."""
1191N/A
1191N/A def __str__(self):
1895N/A return _("Unsupported pkg(5) publisher and image information "
1191N/A "data format.")
3158N/A
3158N/A
1191N/Aclass UnsupportedP5SVersion(ApiException):
3158N/A """Used to indicate that an attempt to read an unsupported version
3158N/A of pkg(5) info file was attempted."""
1191N/A
1895N/A def __init__(self, v):
1895N/A self.version = v
1191N/A
3158N/A def __str__(self):
3158N/A return _("%s is not a supported version for creating a "
1191N/A "syspub response.") % self.version
1191N/A
1191N/A
1191N/Aclass TransportError(ApiException):
1191N/A """Abstract exception class for all transport exceptions.
1191N/A Specific transport exceptions should be implemented in the
1191N/A transport code. Callers wishing to catch transport exceptions
1191N/A should use this class. Subclasses must implement all methods
1191N/A defined here that raise NotImplementedError."""
1191N/A
1191N/A def __str__(self):
1191N/A raise NotImplementedError()
1191N/A
3245N/A def _str_autofix(self):
1191N/A return _str_autofix(self)
1191N/A
1191N/A
1191N/Aclass RetrievalError(ApiException):
1191N/A """Used to indicate that a a requested resource could not be
1191N/A retrieved."""
1191N/A
1191N/A def __init__(self, data, location=None):
1191N/A ApiException.__init__(self)
1191N/A self.data = data
1895N/A self.location = location
1895N/A
1191N/A def __str__(self):
3158N/A if self.location:
1191N/A return _("Error encountered while retrieving data from "
3158N/A "'%s':\n%s") % (self.location, self.data)
1191N/A return _("Error encountered while retrieving data from: %s") % \
1191N/A self.data
3245N/A
3245N/A
3245N/Aclass InvalidResourceLocation(ApiException):
3245N/A """Used to indicate that an invalid transport location was provided."""
3245N/A
3245N/A def __init__(self, data):
3245N/A ApiException.__init__(self)
1191N/A self.data = data
3245N/A
3245N/A def __str__(self):
3245N/A return _("'%s' is not a valid location.") % self.data
3245N/A
3245N/Aclass BEException(ApiException):
3245N/A def __init__(self):
3245N/A ApiException.__init__(self)
3245N/A
3245N/Aclass InvalidBENameException(BEException):
1191N/A def __init__(self, be_name):
1191N/A BEException.__init__(self)
1191N/A self.be_name = be_name
1191N/A
1027N/A def __str__(self):
565N/A return _("'%s' is not a valid boot environment name.") % \
1027N/A self.be_name
565N/A
1027N/Aclass DuplicateBEName(BEException):
565N/A """Used to indicate that there is an existing boot environment
565N/A with this name"""
1027N/A
565N/A def __init__(self, be_name):
565N/A BEException.__init__(self)
2976N/A self.be_name = be_name
2976N/A
565N/A def __str__(self):
1027N/A return _("The boot environment '%s' already exists.") % \
1191N/A self.be_name
1191N/A
1191N/Aclass BENamingNotSupported(BEException):
1191N/A def __init__(self, be_name):
1191N/A BEException.__init__(self)
1191N/A self.be_name = be_name
1191N/A
1191N/A def __str__(self):
1191N/A return _("""\
1191N/ABoot environment naming during package install is not supported on this
1191N/Aversion of OpenSolaris. Please update without the --be-name option.""")
2028N/A
2028N/Aclass UnableToCopyBE(BEException):
2028N/A def __str__(self):
2028N/A return _("Unable to clone the current boot environment.")
2028N/A
2028N/Aclass UnableToRenameBE(BEException):
2028N/A def __init__(self, orig, dest):
2028N/A BEException.__init__(self)
2028N/A self.original_name = orig
2028N/A self.destination_name = dest
2028N/A
2028N/A def __str__(self):
565N/A d = {
565N/A "orig": self.original_name,
565N/A "dest": self.destination_name
565N/A }
565N/A return _("""\
3158N/AA problem occurred while attempting to rename the boot environment
565N/Acurrently named %(orig)s to %(dest)s.""") % d
3158N/A
941N/Aclass UnableToMountBE(BEException):
1286N/A def __init__(self, be_name, be_dir):
1286N/A BEException.__init__(self)
2089N/A self.name = be_name
2089N/A self.mountpoint = be_dir
1286N/A
1286N/A def __str__(self):
1286N/A return _("Unable to mount %(name)s at %(mt)s") % \
1286N/A {"name": self.name, "mt": self.mountpoint}
1286N/A
1286N/Aclass BENameGivenOnDeadBE(BEException):
1286N/A def __init__(self, be_name):
1286N/A BEException.__init__(self)
1286N/A self.name = be_name
1286N/A
1286N/A def __str__(self):
1286N/A return _("""\
1286N/ANaming a boot environment when operating on a non-live image is
1286N/Anot allowed.""")
1286N/A
2089N/A
2089N/Aclass UnrecognizedOptionsToInfo(ApiException):
1286N/A def __init__(self, opts):
1286N/A ApiException.__init__(self)
1286N/A self._opts = opts
1191N/A
1191N/A def __str__(self):
1191N/A s = _("Info does not recognize the following options:")
1191N/A for o in self._opts:
1191N/A s += _(" '") + str(o) + _("'")
941N/A return s
941N/A
1191N/Aclass IncorrectIndexFileHash(ApiException):
1191N/A """This is used when the index hash value doesn't match the hash of the
1191N/A packages installed in the image."""
1191N/A pass
1191N/A
1191N/A
1191N/Aclass PublisherError(ApiException):
1191N/A """Base exception class for all publisher exceptions."""
1191N/A
1191N/A def __init__(self, *args, **kwargs):
941N/A ApiException.__init__(self, *args)
941N/A if args:
941N/A self.data = args[0]
1027N/A else:
1027N/A self.data = None
565N/A self._args = kwargs
565N/A
565N/A def __str__(self):
1027N/A return str(self.data)
565N/A
565N/A
565N/Aclass BadPublisherMetaRoot(PublisherError):
565N/A """Used to indicate an operation on the publisher's meta_root failed
565N/A because the meta_root is invalid."""
565N/A
565N/A def __str__(self):
565N/A return _("Publisher meta_root '%(root)s' is invalid; unable "
565N/A "to complete operation: '%(op)s'.") % { "root": self.data,
565N/A "op": self._args.get("operation", None) }
565N/A
835N/A
2976N/Aclass BadPublisherAlias(PublisherError):
3094N/A """Used to indicate that a publisher alias is not valid."""
3094N/A
3094N/A def __str__(self):
3094N/A return _("'%s' is not a valid publisher alias.") % self.data
3094N/A
3094N/A
3094N/Aclass BadPublisherPrefix(PublisherError):
3094N/A """Used to indicate that a publisher name is not valid."""
3094N/A
2976N/A def __str__(self):
2976N/A return _("'%s' is not a valid publisher name.") % self.data
3293N/A
2205N/A
2205N/Aclass ReservedPublisherPrefix(PublisherError):
2205N/A """Used to indicate that a publisher name is not valid."""
2205N/A
2205N/A def __str__(self):
2205N/A fmri = self._args["fmri"]
2205N/A return _("'%(pkg_pub)s' is a reserved publisher and does not "
2205N/A "contain the requested package: pkg:/%(pkg_name)s") % \
2205N/A {"pkg_pub": fmri.publisher, "pkg_name": fmri.pkg_name}
2205N/A
2205N/A
2205N/Aclass BadRepositoryAttributeValue(PublisherError):
3293N/A """Used to indicate that the specified repository attribute value is
835N/A invalid."""
835N/A
835N/A def __str__(self):
835N/A return _("'%(value)s' is not a valid value for repository "
926N/A "attribute '%(attribute)s'.") % {
835N/A "value": self._args["value"], "attribute": self.data }
835N/A
835N/A
835N/Aclass BadRepositoryCollectionType(PublisherError):
2205N/A """Used to indicate that the specified repository collection type is
835N/A invalid."""
3158N/A
835N/A def __init__(self, *args, **kwargs):
3158N/A PublisherError.__init__(self, *args, **kwargs)
3158N/A
2205N/A def __str__(self):
2205N/A return _("'%s' is not a valid repository collection type.") % \
2205N/A self.data
835N/A
884N/A
3293N/Aclass BadRepositoryURI(PublisherError):
926N/A """Used to indicate that a repository URI is not syntactically valid."""
926N/A
926N/A def __str__(self):
926N/A return _("'%s' is not a valid URI.") % self.data
926N/A
926N/A
926N/Aclass BadRepositoryURIPriority(PublisherError):
926N/A """Used to indicate that the priority specified for a repository URI is
926N/A not valid."""
1516N/A
926N/A def __str__(self):
926N/A return _("'%s' is not a valid URI priority; integer value "
926N/A "expected.") % self.data
926N/A
926N/A
926N/Aclass BadRepositoryURISortPolicy(PublisherError):
926N/A """Used to indicate that the specified repository URI sort policy is
926N/A invalid."""
1736N/A
926N/A def __init__(self, *args, **kwargs):
3158N/A PublisherError.__init__(self, *args, **kwargs)
1736N/A
1736N/A def __str__(self):
926N/A return _("'%s' is not a valid repository URI sort policy.") % \
926N/A self.data
2310N/A
2310N/A
2310N/Aclass DisabledPublisher(PublisherError):
2310N/A """Used to indicate that an attempt to use a disabled publisher occurred
2310N/A during an operation."""
2310N/A
2310N/A def __str__(self):
2310N/A return _("Publisher '%s' is disabled and cannot be used for "
3158N/A "packaging operations.") % self.data
2310N/A
2310N/A
2310N/Aclass DuplicatePublisher(PublisherError):
2310N/A """Used to indicate that a publisher with the same name or alias already
926N/A exists for an image."""
926N/A
3356N/A def __str__(self):
926N/A return _("A publisher with the same name or alias as '%s' "
926N/A "already exists.") % self.data
3356N/A
926N/A
926N/Aclass DuplicateRepository(PublisherError):
926N/A """Used to indicate that a repository with the same origin uris
2310N/A already exists for a publisher."""
2310N/A
3356N/A def __str__(self):
2310N/A return _("A repository with the same name or origin URIs "
2310N/A "already exists for publisher '%s'.") % self.data
3356N/A
2310N/A
2310N/Aclass DuplicateRepositoryMirror(PublisherError):
2310N/A """Used to indicate that a repository URI is already in use by another
2310N/A repository mirror."""
2310N/A
3356N/A def __str__(self):
2310N/A return _("Mirror '%s' already exists for the specified "
2310N/A "publisher.") % self.data
2310N/A
2875N/A
2310N/Aclass DuplicateRepositoryOrigin(PublisherError):
3158N/A """Used to indicate that a repository URI is already in use by another
3158N/A repository origin."""
2310N/A
2310N/A def __str__(self):
926N/A return _("Origin '%s' already exists for the specified "
1191N/A "publisher.") % self.data
1191N/A
1191N/A
1191N/Aclass NoPublisherRepositories(TransportError):
1191N/A """Used to indicate that a Publisher has no repository information
926N/A configured and so transport operations cannot be performed."""
926N/A
1540N/A def __init__(self, prefix):
926N/A TransportError.__init__(self)
2205N/A self.publisher = prefix
2205N/A
2205N/A def __str__(self):
926N/A return _("Unable to retrieve requested package data for "
1191N/A "publisher %s; no repositories are currently configured "
926N/A "for use with this publisher.") % self.publisher
926N/A
926N/A
1191N/Aclass MoveRelativeToSelf(PublisherError):
1191N/A """Used to indicate an attempt to search a repo before or after itself"""
1191N/A
1191N/A def __str__(self):
1191N/A return _("Cannot search a repository before or after itself")
926N/A
1191N/A
926N/Aclass MoveRelativeToUnknown(PublisherError):
3158N/A """Used to indicate an attempt to order a publisher relative to an
3158N/A unknown publisher."""
3158N/A
3158N/A def __init__(self, unknown_pub):
926N/A self.__unknown_pub = unknown_pub
926N/A
1191N/A def __str__(self):
926N/A return _("%s is an unknown publisher; no other publishers can "
926N/A "be ordered relative to it.") % self.__unknown_pub
1191N/A
1191N/A
1191N/Aclass SelectedRepositoryRemoval(PublisherError):
1191N/A """Used to indicate that an attempt to remove the selected repository
926N/A for a publisher was made."""
3158N/A
926N/A def __str__(self):
941N/A return _("Cannot remove the selected repository for a "
941N/A "publisher.")
941N/A
926N/A
884N/Aclass UnknownLegalURI(PublisherError):
884N/A """Used to indicate that no matching legal URI could be found using the
884N/A provided criteria."""
884N/A
884N/A def __str__(self):
884N/A return _("Unknown legal URI '%s'.") % self.data
3158N/A
3158N/A
1076N/Aclass UnknownPublisher(PublisherError):
1076N/A """Used to indicate that no matching publisher could be found using the
1945N/A provided criteria."""
1076N/A
1076N/A def __str__(self):
1076N/A return _("Unknown publisher '%s'.") % self.data
1076N/A
1076N/A
1076N/Aclass UnknownRepositoryPublishers(PublisherError):
1076N/A """Used to indicate that one or more publisher prefixes are unknown by
3158N/A the specified repository."""
3158N/A
884N/A def __init__(self, known=EmptyI, unknown=EmptyI, location=None,
884N/A origins=EmptyI):
884N/A ApiException.__init__(self)
884N/A self.known = known
884N/A self.location = location
884N/A self.origins = origins
884N/A self.unknown = unknown
884N/A
884N/A def __str__(self):
2089N/A if self.location:
884N/A return _("The repository at %(location)s does not "
884N/A "contain package data for %(unknown)s; only "
884N/A "%(known)s.\n\nThis is either because the "
884N/A "repository location is not valid, or because the "
884N/A "provided publisher does not match those known by "
884N/A "the repository.") % {
884N/A "unknown": ", ".join(self.unknown),
884N/A "location": self.location,
884N/A "known": ", ".join(self.known) }
884N/A if self.origins:
884N/A return _("One or more of the repository origin(s) "
884N/A "listed below contains package data for "
884N/A "%(known)s; not %(unknown)s:\n\n%(origins)s\n\n"
884N/A "This is either because one of the repository "
884N/A "origins is not valid for this publisher, or "
884N/A "because the list of known publishers retrieved "
884N/A "from the repository origin does not match the "
884N/A "client.") % { "unknown": ", ".join(self.unknown),
3158N/A "known": ", ".join(self.known),
884N/A "origins": "\n".join(str(o) for o in self.origins) }
884N/A return _("The specified publisher repository does not "
884N/A "contain any package data for %(unknown)s; only "
884N/A "%(known)s.") % { "unknown": ", ".join(self.unknown),
884N/A "known": ", ".join(self.known) }
884N/A
884N/A
884N/Aclass UnknownRelatedURI(PublisherError):
3158N/A """Used to indicate that no matching related URI could be found using
3158N/A the provided criteria."""
884N/A
884N/A def __str__(self):
884N/A return _("Unknown related URI '%s'.") % self.data
884N/A
884N/A
884N/Aclass UnknownRepository(PublisherError):
884N/A """Used to indicate that no matching repository could be found using the
884N/A provided criteria."""
884N/A
884N/A def __str__(self):
926N/A return _("Unknown repository '%s'.") % self.data
926N/A
917N/A
917N/Aclass UnknownRepositoryMirror(PublisherError):
917N/A """Used to indicate that a repository URI could not be found in the
917N/A list of repository mirrors."""
917N/A
917N/A def __str__(self):
917N/A return _("Unknown repository mirror '%s'.") % self.data
917N/A
917N/Aclass UnsupportedRepositoryOperation(TransportError):
917N/A """The publisher has no active repositories that support the
926N/A requested operation."""
941N/A
941N/A def __init__(self, pub, operation):
941N/A ApiException.__init__(self)
941N/A self.data = None
941N/A self.kwargs = None
941N/A self.pub = pub
926N/A self.op = operation
926N/A
926N/A def __str__(self):
926N/A return _("Publisher '%(pub)s' has no repositories that support "
926N/A "the '%(op)s' operation.") % self.__dict__
926N/A
926N/A
926N/Aclass RepoPubConfigUnavailable(PublisherError):
926N/A """Used to indicate that the specified repository does not provide
1516N/A publisher configuration information."""
926N/A
926N/A def __init__(self, location=None, pub=None):
926N/A ApiException.__init__(self)
926N/A self.location = location
926N/A self.pub = pub
1087N/A
1087N/A def __str__(self):
1087N/A if not self.location and not self.pub:
1087N/A return _("The specified package repository does not "
1087N/A "provide publisher configuration information.")
3158N/A if self.location:
3158N/A return _("The package repository at %s does not "
3158N/A "provide publisher configuration information or "
1087N/A "the information provided is incomplete.") % \
1087N/A self.location
2028N/A return _("One of the package repository origins for %s does "
2028N/A "not provide publisher configuration information or the "
2028N/A "information provided is incomplete.") % self.pub
2028N/A
3158N/A
3158N/Aclass UnknownRepositoryOrigin(PublisherError):
2028N/A """Used to indicate that a repository URI could not be found in the
2028N/A list of repository origins."""
926N/A
926N/A def __str__(self):
926N/A return _("Unknown repository origin '%s'") % self.data
926N/A
3158N/A
3158N/Aclass UnsupportedRepositoryURI(PublisherError):
926N/A """Used to indicate that the specified repository URI uses an
926N/A unsupported scheme."""
2339N/A
2339N/A def __str__(self):
2339N/A if self.data:
2339N/A scheme = urlparse.urlsplit(self.data,
2339N/A allow_fragments=0)[0]
3158N/A return _("The URI '%(uri)s' uses the unsupported "
3158N/A "scheme '%(scheme)s'. Supported schemes are "
3158N/A "file://, http://, and https://.") % {
2339N/A "uri": self.data, "scheme": scheme }
2339N/A return _("The specified URI uses an unsupported scheme."
926N/A " Supported schemes are: file://, http://, and https://.")
926N/A
926N/A
926N/Aclass UnsupportedRepositoryURIAttribute(PublisherError):
926N/A """Used to indicate that the specified repository URI attribute is not
3158N/A supported for the URI's scheme."""
3158N/A
3158N/A def __str__(self):
926N/A return _("'%(attr)s' is not supported for '%(scheme)s'.") % {
926N/A "attr": self.data, "scheme": self._args["scheme"] }
926N/A
926N/A
926N/Aclass UnknownSysrepoConfiguration(ApiException):
926N/A """Used when a pkg client needs to communicate with the system
926N/A repository but can't find the configuration for it."""
926N/A
926N/A def __str__(self):
926N/A return _("""\
3158N/Apkg is configured to use the system repository (via the use-system-repo
3158N/Aproperty) but it could not get the host and port from
926N/Asvc:/application/pkg/zones-proxy-client nor svc:/application/pkg/system-repository, and
926N/Athe PKG_SYSREPO_URL environment variable was not set. Please try enabling one
926N/Aof those services or setting the PKG_SYSREPO_URL environment variable.
926N/A""")
926N/A
926N/A
3158N/Aclass ModifyingSyspubException(ApiException):
926N/A """This exception is raised when a user attempts to modify a system
926N/A publisher."""
926N/A
926N/A def __init__(self, s):
926N/A self.s = s
926N/A
926N/A def __str__(self):
3158N/A return self.s
3158N/A
926N/A
926N/Aclass SigningException(ApiException):
926N/A """The base class for exceptions related to manifest signing."""
926N/A
926N/A def __init__(self, pfmri=None, sig=None):
926N/A self.pfmri = pfmri
926N/A self.sig = sig
926N/A
926N/A # This string method is used by subclasses to fill in the details
926N/A # about the package and signature involved.
3158N/A def __str__(self):
3158N/A if self.pfmri:
926N/A if self.sig:
926N/A return _("The relevant signature action is "
926N/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
926N/A if self.sig:
3158N/A return _("The relevant signature action's value "
3158N/A "attribute is %s") % self.sig.attrs["value"]
926N/A return ""
926N/A
926N/A
926N/Aclass BadFileFormat(SigningException):
926N/A """Exception used when a key, certificate or CRL file is not in a
926N/A recognized format."""
926N/A
3158N/A def __init__(self, txt):
3158N/A self.txt = txt
926N/A
926N/A def __str__(self):
926N/A return self.txt
926N/A
926N/A
926N/Aclass UnsupportedSignatureVersion(SigningException):
926N/A """Exception used when a signature reports a version which this version
926N/A of pkg(5) doesn't support."""
3158N/A
926N/A def __init__(self, version, *args, **kwargs):
926N/A SigningException.__init__(self, *args, **kwargs)
926N/A self.version = version
926N/A
926N/A def __str__(self):
926N/A return _("The signature action %(act)s was made using a "
926N/A "version (%(ver)s) this version of pkg(5) doesn't "
3158N/A "understand.") % {"act":self.sig, "ver":self.version}
3158N/A
926N/A
926N/Aclass CertificateException(SigningException):
2701N/A """Base class for exceptions encountered while establishing the chain
2701N/A of trust."""
2701N/A
2701N/A def __init__(self, cert, pfmri=None):
2701N/A SigningException.__init__(self, pfmri)
3158N/A self.cert = cert
3158N/A
2701N/A
2701N/Aclass ModifiedCertificateException(CertificateException):
926N/A """Exception used when a certificate does not match its expected hash
926N/A value."""
926N/A
926N/A def __init__(self, cert, path, pfmri=None):
926N/A CertificateException.__init__(self, cert, pfmri)
3158N/A self.path = path
3158N/A
1504N/A def __str__(self):
1504N/A return _("Certificate %s has been modified on disk. Its hash "
2701N/A "value is not what was expected.") % self.path
2701N/A
2701N/A
2701N/Aclass UntrustedSelfSignedCert(CertificateException):
2701N/A """Exception used when a chain of trust is rooted in an untrusted
3158N/A self-signed certificate."""
3158N/A
2701N/A def __str__(self):
2701N/A return _("Chain was rooted in an untrusted self-signed "
2701N/A "certificate.\n") + CertificateException.__str__(self)
2701N/A
2701N/A
2701N/Aclass BrokenChain(CertificateException):
2701N/A """Exception used when a chain of trust can not be established between
3158N/A the leaf certificate and a trust anchor."""
3158N/A
2701N/A def __init__(self, cert, cert_exceptions, *args, **kwargs):
2701N/A CertificateException.__init__(self, cert, *args, **kwargs)
2701N/A self.ext_exs = cert_exceptions
2701N/A
2701N/A def __str__(self):
2701N/A s = ""
3158N/A if self.ext_exs:
3158N/A s = _("The following problems were encountered:\n") + \
2701N/A "\n".join([str(e) for e in self.ext_exs])
2701N/A return _("The certificate which issued this "
2322N/A "certificate:%(subj)s could not be found. The issuer "
2219N/A "is:%(issuer)s\n") % {"subj":self.cert.get_subject(),
2219N/A "issuer":self.cert.get_issuer()} + s + \
1504N/A CertificateException.__str__(self)
2322N/A
2322N/A
2322N/Aclass RevokedCertificate(CertificateException):
2322N/A """Exception used when a chain of trust contains a revoked certificate.
1504N/A """
3167N/A
3167N/A def __init__(self, cert, reason, *args, **kwargs):
3167N/A CertificateException.__init__(self, cert, *args, **kwargs)
3167N/A self.reason = reason
3167N/A
3167N/A def __str__(self):
926N/A return _("This certificate was revoked:%(cert)s for this "
926N/A "reason:\n%(reason)s") % {"cert":self.cert.get_subject(),
1505N/A "reason":self.reason} + CertificateException.__str__(self)
1505N/A
1505N/A
1505N/Aclass UnverifiedSignature(SigningException):
1505N/A """Exception used when a signature could not be verified by the
1505N/A expected certificate."""
1505N/A
2409N/A def __init__(self, sig, reason, pfmri=None):
2409N/A SigningException.__init__(self, pfmri)
2409N/A self.sig = sig
2409N/A self.reason = reason
2409N/A
2409N/A def __str__(self):
2409N/A if self.pfmri:
2409N/A return _("A signature in %(pfmri)s could not be "
3158N/A "verified for "
3158N/A "this reason:\n%(reason)s\nThe signature's hash is "
2409N/A "%(hash)s") % {"pfmri": self.pfmri,
2409N/A "reason": self.reason,
926N/A "hash": self.sig.hash}
926N/A return _("The signature with this signature value:\n"
926N/A "%(sigval)s\n could not be verified for this reason:\n"
926N/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
926N/A
3158N/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 "
926N/A "found in %(fmri_str)s.") % \
926N/A {"pub_str": pub_str, "fmri_str": self.pfmri}
926N/A return _("The policy for %(pub_str)s requires signatures to be "
3158N/A "present but no signature was found.") % {
926N/A "pub_str": pub_str}
926N/A
1736N/A
1736N/Aclass MissingRequiredNamesException(SigningException):
1736N/A """Exception used when a signature policy required names to be seen
1736N/A which weren't seen."""
1736N/A
1736N/A def __init__(self, pub, missing_names, pfmri=None):
1736N/A SigningException.__init__(self, pfmri)
1736N/A self.pub = pub
1736N/A self.missing_names = missing_names
1736N/A
1736N/A def __str__(self):
1736N/A pub_str = self.pub.prefix
1736N/A if self.pfmri:
1736N/A return _("The policy for %(pub_str)s requires certain "
3158N/A "CNs to be seen in a chain of trust. The following "
3158N/A "required names couldn't be found for this "
3158N/A "package:%(fmri_str)s.\n%(missing)s") % \
1736N/A {"pub_str": pub_str, "fmri_str": self.pfmri,
1736N/A "missing": "\n".join(self.missing_names)}
3158N/A return _("The policy for %(pub_str)s requires certain CNs to "
3158N/A "be seen in a chain of trust. The following required names "
3158N/A "couldn't be found.\n%(missing)s") % {"pub_str": pub_str,
3158N/A "missing": "\n".join(self.missing_names)}
1736N/A
1736N/Aclass UnsupportedCriticalExtension(SigningException):
1736N/A """Exception used when a certificate in the chain of trust uses a
3158N/A critical extension pkg5 doesn't understand."""
1736N/A
1736N/A def __init__(self, cert, ext):
1736N/A SigningException.__init__(self)
1736N/A self.cert = cert
3158N/A self.ext = ext
3158N/A
3158N/A def __str__(self):
1736N/A return _("The certificate whose subject is %(cert)s could not "
3158N/A "be verified "
3158N/A "because it uses a critical extension that pkg5 cannot "
3158N/A "handle yet.\nExtension name:%(name)s\nExtension "
1736N/A "value:%(val)s") % {"cert": self.cert.get_subject(),
1736N/A "name":self.ext.get_name(), "val":self.ext.get_value()}
926N/A
926N/Aclass UnsupportedExtensionValue(SigningException):
926N/A """Exception used when a certificate in the chain of trust has an
926N/A extension with a value pkg5 doesn't understand."""
926N/A
3158N/A def __init__(self, cert, ext, bad_val=None):
926N/A SigningException.__init__(self)
926N/A self.cert = cert
926N/A self.ext = ext
926N/A self.bad_val = bad_val
926N/A
926N/A def __str__(self):
926N/A s = _("The certificate whose subject is %(cert)s could not be "
3158N/A "verified because it has an extension with a value that "
926N/A "pkg(5) does not understand."
926N/A "\nExtension name:%(name)s\nExtension value:%(val)s") % \
926N/A {"cert": self.cert.get_subject(),
926N/A "name":self.ext.get_name(), "val":self.ext.get_value()}
926N/A if self.bad_val:
926N/A s += _("\nProblematic Value:%s") % (self.bad_val,)
926N/A return s
3158N/A
926N/Aclass InappropriateCertificateUse(SigningException):
2316N/A """Exception used when a certificate in the chain of trust has been used
1431N/A inappropriately. An example would be a certificate which was only
1431N/A supposed to be used to sign code being used to sign other certificates.
1431N/A """
1431N/A
1431N/A def __init__(self, cert, ext, use):
1431N/A SigningException.__init__(self)
1431N/A self.cert = cert
1431N/A self.ext = ext
1431N/A self.use = use
1431N/A
1431N/A def __str__(self):
3158N/A return _("The certificate whose subject is %(cert)s could not "
3158N/A "be verified because it has been used inappropriately. "
1736N/A "The way it is used means that the value for extension "
1736N/A "%(name)s must include '%(use)s' but the value was "
1736N/A "'%(val)s'.") % {"cert": self.cert.get_subject(),
1736N/A "use": self.use, "name":self.ext.get_name(),
1736N/A "val":self.ext.get_value()}
1736N/A
1736N/Aclass PathlenTooShort(InappropriateCertificateUse):
1736N/A """Exception used when a certificate in the chain of trust has been used
1736N/A inappropriately. An example would be a certificate which was only
1736N/A supposed to be used to sign code being used to sign other certificates.
1736N/A """
1736N/A
1736N/A def __init__(self, cert, actual_length, cert_length):
1736N/A SigningException.__init__(self)
1736N/A self.cert = cert
1736N/A self.al = actual_length
3158N/A self.cl = cert_length
1736N/A
3158N/A def __str__(self):
3158N/A return _("The certificate whose subject is %(cert)s could not "
3158N/A "be verified because it has been used inappropriately. "
1736N/A "There can only be %(cl)s certificates between this "
3158N/A "certificate and the leaf certificate. There are %(al)s "
1736N/A "certificates between this certificate and the leaf in "
926N/A "this chain.") % {
926N/A "cert": self.cert.get_subject(),
926N/A "al": self.al,
926N/A "cl": self.cl
926N/A }
926N/A
3158N/A
926N/Aclass AlmostIdentical(ApiException):
926N/A """Exception used when a package already has a signature action which is
926N/A nearly identical to the one being added but differs on some
926N/A attributes."""
926N/A
926N/A def __init__(self, hsh, algorithm, version, pkg=None):
2839N/A self.hsh = hsh
3234N/A self.algorithm = algorithm
2839N/A self.version = version
2839N/A self.pkg = pkg
2839N/A
2839N/A def __str__(self):
2839N/A s = _("The signature to be added to the package has the same "
2839N/A "hash (%(hash)s), algorithm (%(algorithm)s), and "
926N/A "version (%(version)s) as an existing signature, but "
2839N/A "doesn't match the signature exactly. For this signature "
2839N/A "to be added, the existing signature must be removed.") % {
2839N/A "hash": self.hsh,
3234N/A "algorithm": self.algorithm,
3234N/A "version": self.version
926N/A }
2839N/A if self.pkg:
2839N/A s += _("The package being signed was %(pkg)s") % \
2839N/A {"pkg": self.pkg}
2839N/A return s
2839N/A
2839N/A
2839N/Aclass DuplicateSignaturesAlreadyExist(ApiException):
3158N/A """Exception used when a package already has a signature action which is
3158N/A nearly identical to the one being added but differs on some
2839N/A attributes."""
2839N/A
2839N/A def __init__(self, pfmri):
3158N/A self.pfmri = pfmri
3158N/A
3158N/A def __str__(self):
3158N/A return _("%s could not be signed because it already has two "
2144N/A "copies of this signature in it. One of those signature "
2839N/A "actions must be removed before the package is given to "
2840N/A "users.") % self.pfmri
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)
3158N/A self.str = s
3158N/A
926N/A def __str__(self):
926N/A return self.str
2701N/A
2701N/A
2701N/Aclass CertificateError(ApiException):
2701N/A """Base exception class for all certificate exceptions."""
2701N/A
3234N/A def __init__(self, *args, **kwargs):
2701N/A ApiException.__init__(self, *args)
3158N/A if args:
3244N/A self.data = args[0]
3244N/A else:
3158N/A self.data = None
2701N/A self._args = kwargs
3244N/A
2701N/A def __str__(self):
2701N/A return str(self.data)
2701N/A
2701N/A
2701N/Aclass ExpiredCertificate(CertificateError):
3158N/A """Used to indicate that a certificate has expired."""
2701N/A
2701N/A def __str__(self):
2310N/A publisher = self._args.get("publisher", None)
2310N/A uri = self._args.get("uri", None)
2310N/A if publisher:
2310N/A if uri:
2310N/A return _("Certificate '%(cert)s' for publisher "
2310N/A "'%(pub)s' needed to access '%(uri)s', "
2310N/A "has expired. Please install a valid "
2310N/A "certificate.") % { "cert": self.data,
2367N/A "pub": publisher, "uri": uri }
2335N/A return _("Certificate '%(cert)s' for publisher "
2335N/A "'%(pub)s', has expired. Please install a valid "
2310N/A "certificate.") % { "cert": self.data,
2310N/A "pub": publisher }
2310N/A if uri:
2310N/A return _("Certificate '%(cert)s', needed to access "
2310N/A "'%(uri)s', has expired. Please install a valid "
2310N/A "certificate.") % { "cert": self.data, "uri": uri }
2310N/A return _("Certificate '%s' has expired. Please install a "
2310N/A "valid certificate.") % self.data
2310N/A
2310N/A
2310N/Aclass ExpiringCertificate(CertificateError):
2310N/A """Used to indicate that a certificate has expired."""
2310N/A
2310N/A def __str__(self):
2026N/A publisher = self._args.get("publisher", None)
2026N/A uri = self._args.get("uri", None)
2026N/A days = self._args.get("days", 0)
2026N/A if publisher:
2026N/A if uri:
2026N/A return _("Certificate '%(cert)s' for publisher "
2026N/A "'%(pub)s', needed to access '%(uri)s', "
2026N/A "will expire in '%(days)s' days.") % {
2026N/A "cert": self.data, "pub": publisher,
2026N/A "uri": uri, "days": days }
2026N/A return _("Certificate '%(cert)s' for publisher "
2026N/A "'%(pub)s' will expire in '%(days)s' days.") % {
2026N/A "cert": self.data, "pub": publisher, "days": days }
3158N/A if uri:
3158N/A return _("Certificate '%(cert)s', needed to access "
3158N/A "'%(uri)s', will expire in '%(days)s' days.") % {
3158N/A "cert": self.data, "uri": uri, "days": days }
3158N/A return _("Certificate '%(cert)s' will expire in "
2026N/A "'%(days)s' days.") % { "cert": self.data, "days": days }
2026N/A
3158N/A
2026N/Aclass InvalidCertificate(CertificateError):
2026N/A """Used to indicate that a certificate is invalid."""
2026N/A
2026N/A def __str__(self):
2026N/A publisher = self._args.get("publisher", None)
2026N/A uri = self._args.get("uri", None)
2026N/A if publisher:
2026N/A if uri:
2026N/A return _("Certificate '%(cert)s' for publisher "
2026N/A "'%(pub)s', needed to access '%(uri)s', is "
2026N/A "invalid.") % { "cert": self.data,
2026N/A "pub": publisher, "uri": uri }
2200N/A return _("Certificate '%(cert)s' for publisher "
2026N/A "'%(pub)s' is invalid.") % { "cert": self.data,
2026N/A "pub": publisher }
2026N/A if uri:
3356N/A return _("Certificate '%(cert)s' needed to access "
2026N/A "'%(uri)s' is invalid.") % { "cert": self.data,
2026N/A "uri": uri }
2026N/A return _("Invalid certificate '%s'.") % self.data
2026N/A
2026N/A
2026N/Aclass NoSuchKey(CertificateError):
3158N/A """Used to indicate that a key could not be found."""
3356N/A
3158N/A def __str__(self):
2026N/A publisher = self._args.get("publisher", None)
2026N/A uri = self._args.get("uri", None)
2026N/A if publisher:
2026N/A if uri:
2026N/A return _("Unable to locate key '%(key)s' for "
2026N/A "publisher '%(pub)s' needed to access "
2026N/A "'%(uri)s'.") % { "key": self.data,
2026N/A "pub": publisher, "uri": uri }
2026N/A return _("Unable to locate key '%(key)s' for publisher "
2026N/A "'%(pub)s'.") % { "key": self.data, "pub": publisher
2026N/A }
2026N/A if uri:
2026N/A return _("Unable to locate key '%(key)s' needed to "
2026N/A "access '%(uri)s'.") % { "key": self.data,
2026N/A "uri": uri }
2026N/A return _("Unable to locate key '%s'.") % self.data
2026N/A
2026N/A
2200N/Aclass NoSuchCertificate(CertificateError):
2026N/A """Used to indicate that a certificate could not be found."""
3158N/A
3158N/A def __str__(self):
2026N/A publisher = self._args.get("publisher", None)
2026N/A uri = self._args.get("uri", None)
2026N/A if publisher:
2026N/A if uri:
2026N/A return _("Unable to locate certificate "
2026N/A "'%(cert)s' for publisher '%(pub)s' needed "
2026N/A "to access '%(uri)s'.") % {
2026N/A "cert": self.data, "pub": publisher,
2026N/A "uri": uri }
2026N/A return _("Unable to locate certificate '%(cert)s' for "
2026N/A "publisher '%(pub)s'.") % { "cert": self.data,
2026N/A "pub": publisher }
2026N/A if uri:
2026N/A return _("Unable to locate certificate '%(cert)s' "
2026N/A "needed to access '%(uri)s'.") % {
2026N/A "cert": self.data, "uri": uri }
2026N/A return _("Unable to locate certificate '%s'.") % self.data
2026N/A
2200N/A
2026N/Aclass NotYetValidCertificate(CertificateError):
2026N/A """Used to indicate that a certificate is not yet valid (future
2026N/A effective date)."""
2026N/A
2026N/A def __str__(self):
2026N/A publisher = self._args.get("publisher", None)
3158N/A uri = self._args.get("uri", None)
3321N/A if publisher:
3321N/A if uri:
3321N/A return _("Certificate '%(cert)s' for publisher "
3321N/A "'%(pub)s', needed to access '%(uri)s', "
2026N/A "has a future effective date.") % {
2026N/A "cert": self.data, "pub": publisher,
2026N/A "uri": uri }
2026N/A return _("Certificate '%(cert)s' for publisher "
2026N/A "'%(pub)s' has a future effective date.") % {
2026N/A "cert": self.data, "pub": publisher }
2026N/A if uri:
2026N/A return _("Certificate '%(cert)s' needed to access "
2026N/A "'%(uri)s' has a future effective date.") % {
2026N/A "cert": self.data, "uri": uri }
2026N/A return _("Certificate '%s' has a future effective date.") % \
2026N/A self.data
3158N/A
3321N/A
3321N/Aclass ServerReturnError(ApiException):
3158N/A """This exception is used when the server returns a line which the
2026N/A client cannot parse correctly."""
2026N/A
2026N/A def __init__(self, line):
2026N/A ApiException.__init__(self)
2026N/A self.line = line
2026N/A
2026N/A def __str__(self):
2026N/A return _("Gave a bad response:%s") % self.line
2026N/A
2026N/A
2026N/Aclass MissingFileArgumentException(ApiException):
2026N/A """This exception is used when a file was given as an argument but
2026N/A no such file could be found."""
3158N/A def __init__(self, path):
2026N/A ApiException.__init__(self)
3158N/A self.path = path
3158N/A
3158N/A def __str__(self):
3158N/A return _("Could not find %s") % self.path
2026N/A
3158N/A
3158N/Aclass ManifestError(ApiException):
3158N/A """Base exception class for all manifest exceptions."""
2026N/A
2026N/A def __init__(self, *args, **kwargs):
2026N/A ApiException.__init__(self, *args, **kwargs)
2026N/A if args:
2026N/A self.data = args[0]
2026N/A else:
2026N/A self.data = None
2026N/A self._args = kwargs
2026N/A
2026N/A def __str__(self):
2026N/A return str(self.data)
2026N/A
3158N/A
2026N/Aclass BadManifestSignatures(ManifestError):
3158N/A """Used to indicate that the Manifest signatures are not valid."""
3158N/A
3158N/A def __str__(self):
3158N/A if self.data:
3158N/A return _("The signature data for the manifest of the "
2026N/A "'%s' package is not valid.") % self.data
2026N/A return _("The signature data for the manifest is not valid.")
2026N/A
2026N/A
2026N/Aclass UnknownErrors(ApiException):
2026N/A """Used to indicate that one or more exceptions were encountered.
2026N/A This is intended for use with where multiple exceptions for multiple
2026N/A files are encountered and the errors have been condensed into a
2026N/A single exception and re-raised. One example case would be rmtree()
2026N/A with shutil.Error."""
2026N/A
2026N/A def __init__(self, msg):
2026N/A ApiException.__init__(self)
2026N/A self.__msg = msg
3158N/A
2026N/A def __str__(self):
2026N/A return self.__msg
3158N/A
3158N/A
3158N/A# Image creation exceptions
3158N/Aclass ImageCreationException(ApiException):
2026N/A def __init__(self, path):
3158N/A ApiException.__init__(self)
3158N/A self.path = path
2026N/A
2026N/A def __str__(self):
2026N/A raise NotImplementedError()
3321N/A
2026N/A
2026N/Aclass ImageAlreadyExists(ImageCreationException):
2026N/A def __str__(self):
2026N/A return _("there is already an image at: %s.\nTo override, use "
2026N/A "the -f (force) option.") % self.path
2026N/A
2026N/A
3158N/Aclass ImageCfgEmptyError(ApiException):
3321N/A """Used to indicate that the image configuration is invalid."""
3321N/A
3321N/A def __str__(self):
3321N/A return _("The configuration data for the image rooted at "
3321N/A "%s is empty or missing.") % self.data
2026N/A
3321N/A
3321N/Aclass UnsupportedImageError(ApiException):
3321N/A """Used to indicate that the image at a specific location is in a format
3321N/A not supported by this version of the pkg(5) API."""
3321N/A
3321N/A def __init__(self, path):
3321N/A ApiException.__init__(self)
3321N/A self.path = path
3321N/A
3321N/A def __str__(self):
3321N/A return _("The image rooted at %s is invalid or is not "
3321N/A "supported by this version of the packaging system.") % \
3321N/A self.path
3321N/A
3321N/A
2215N/Aclass CreatingImageInNonEmptyDir(ImageCreationException):
2215N/A def __str__(self):
2215N/A return _("the specified image path is not empty: %s.\nTo "
2215N/A "override, use the -f (force) option.") % self.path
2215N/A
2215N/A
2215N/Adef _convert_error(e, ignored_errors=EmptyI):
2215N/A """Converts the provided exception into an ApiException equivalent if
3321N/A possible. Returns a new exception object if converted or the original
2215N/A if not.
2215N/A
2215N/A 'ignored_errors' is an optional list of errno values for which None
2215N/A should be returned.
3321N/A """
2215N/A
2215N/A if not hasattr(e, "errno"):
3158N/A return e
2215N/A if e.errno in ignored_errors:
2215N/A return None
3158N/A if e.errno in (errno.EACCES, errno.EPERM):
3321N/A return PermissionsException(e.filename)
3321N/A if e.errno == errno.EROFS:
3321N/A return ReadOnlyFileSystemException(e.filename)
3321N/A return e
2286N/A
2286N/Aclass LinkedImageException(ApiException):
2286N/A
2286N/A def __init__(self, bundle=None, lin=None, exitrv=None,
2286N/A attach_bad_prop=None,
2286N/A attach_bad_prop_value=None,
2286N/A attach_child_notsup=None,
2286N/A attach_parent_notsup=None,
2286N/A attach_root_as_child=None,
2286N/A child_bad_img=None,
2286N/A child_diverged=None,
2286N/A child_dup=None,
2286N/A child_nested=None,
2286N/A child_not_in_altroot=None,
3158N/A child_not_nested=None,
2286N/A child_path_eaccess=None,
3158N/A child_path_notabs=None,
3158N/A child_unknown=None,
2286N/A cmd_failed=None,
3158N/A detach_child_notsup=None,
3321N/A detach_from_parent=None,
3321N/A detach_parent_notsup=None,
3158N/A img_linked=None,
3158N/A lin_malformed=False,
3158N/A link_to_self=False,
2286N/A parent_bad_img=None,
2286N/A parent_bad_notabs=None,
2286N/A parent_bad_path=None,
2286N/A parent_not_in_altroot=None,
2286N/A self_linked=None,
2286N/A self_not_child=None):
2286N/A
2286N/A self.attach_bad_prop = attach_bad_prop
2286N/A self.attach_bad_prop_value = attach_bad_prop_value
2286N/A self.attach_child_notsup = attach_child_notsup
2286N/A self.attach_parent_notsup = attach_parent_notsup
2286N/A self.attach_root_as_child = attach_root_as_child
2286N/A self.child_bad_img = child_bad_img
2286N/A self.child_diverged = child_diverged
2286N/A self.child_dup = child_dup
3158N/A self.child_nested = child_nested
3158N/A self.child_not_in_altroot = child_not_in_altroot
2286N/A self.child_not_nested = child_not_nested
3158N/A self.child_path_eaccess = child_path_eaccess
3158N/A self.child_path_notabs = child_path_notabs
3158N/A self.child_unknown = child_unknown
3158N/A self.cmd_failed = cmd_failed
3158N/A self.detach_child_notsup = detach_child_notsup
2286N/A self.detach_from_parent = detach_from_parent
3158N/A self.detach_parent_notsup = detach_parent_notsup
3158N/A self.img_linked = img_linked
2286N/A self.lin_malformed = lin_malformed
2286N/A self.link_to_self = link_to_self
2286N/A self.parent_bad_img = parent_bad_img
2286N/A self.parent_bad_notabs = parent_bad_notabs
2286N/A self.parent_bad_path = parent_bad_path
2286N/A self.parent_not_in_altroot = parent_not_in_altroot
2286N/A self.self_linked = self_linked
2286N/A self.self_not_child = self_not_child
2286N/A
2286N/A # first deal with an error bundle
2286N/A if bundle:
2286N/A assert type(bundle) in [tuple, list, set]
3158N/A for e in bundle:
2286N/A assert isinstance(e, LinkedImageException)
2286N/A
3158N/A # set default error return value
2286N/A if exitrv == None:
2286N/A exitrv = pkgdefs.EXIT_OOPS
2026N/A
2026N/A self.lix_err = None
2026N/A self.lix_bundle = bundle
2026N/A self.lix_exitrv = exitrv
2026N/A return
2026N/A
2026N/A err = None
2026N/A
2026N/A if attach_bad_prop:
2026N/A err = _("Invalid linked image attach property: %s") % \
2026N/A attach_bad_prop
926N/A
926N/A if attach_bad_prop_value:
926N/A assert type(attach_bad_prop_value) in [tuple, list]
926N/A assert len(attach_bad_prop_value) == 2
926N/A err = _("Invalid linked image attach property "
926N/A "value: %s") % "=".join(attach_bad_prop_value)
926N/A
926N/A if attach_child_notsup:
926N/A err = _("Linked image type does not support child "
1516N/A "attach: %s") % attach_child_notsup
926N/A
926N/A if attach_parent_notsup:
926N/A err = _("Linked image type does not support parent "
926N/A "attach: %s") % attach_parent_notsup
926N/A
926N/A if attach_root_as_child:
926N/A err = _("Cannot attach root image as child")
926N/A
2980N/A if child_bad_img:
2980N/A if exitrv == None:
2980N/A exitrv = pkgdefs.EXIT_EACCESS
2980N/A if lin:
2980N/A err = _("Can't initialize child image "
926N/A "(%(lin)s) at path: %(path)s") % {
2980N/A "lin": lin,
2980N/A "path": child_bad_img
3158N/A }
3158N/A else:
926N/A err = _("Can't initialize child image "
3158N/A "at path: %s") % child_bad_img
3158N/A
3158N/A if child_diverged:
3158N/A if exitrv == None:
3158N/A exitrv = pkgdefs.EXIT_DIVERGED
3158N/A err = _("Linked image is diverged: %s") % \
2980N/A child_diverged
3158N/A
3158N/A if child_dup:
3158N/A err = _("A linked child image with this name "
3158N/A "already exists: %s") % child_dup
3158N/A
3158N/A if child_nested:
926N/A cpath, ipath = child_nested
926N/A err = _("Child image '%(cpath)s' is nested "
2980N/A "within another image: '%(ipath)s'") % {
2980N/A "cpath": cpath,
2980N/A "ipath": ipath,
2980N/A }
3043N/A
2980N/A if child_not_in_altroot:
2980N/A path, altroot = child_not_in_altroot
2980N/A err = _("Child image '%(path)s' is not located "
2980N/A "within the parent's altroot '%(altroot)s'") % {
2980N/A "path": path,
2980N/A "altroot": altroot
2980N/A }
2980N/A
2980N/A if child_not_nested:
2980N/A cpath, ppath = child_not_nested
2980N/A err = _("Child image '%(cpath)s' is not nested "
2980N/A "within the parent image '%(ppath)s'") % {
2980N/A "cpath": cpath,
2980N/A "ppath": ppath,
2980N/A }
2980N/A
2980N/A if child_path_eaccess:
2980N/A if exitrv == None:
2980N/A exitrv = pkgdefs.EXIT_EACCESS
2980N/A if lin:
3158N/A err = _("Can't access child image "
3158N/A "(%(lin)s) at path: %(path)s") % {
2980N/A "lin": lin,
3158N/A "path": child_path_eaccess
3158N/A }
3158N/A else:
3158N/A err = _("Can't access child image "
3158N/A "at path: %s") % child_path_eaccess
3158N/A
2980N/A if child_path_notabs:
2980N/A err = _("Child path not absolute: %s") % \
3158N/A child_path_notabs
2980N/A
2980N/A if child_unknown:
926N/A err = _("Unknown child linked image: %s") % \
926N/A child_unknown
926N/A
926N/A if cmd_failed:
1516N/A assert lin
1516N/A assert len(cmd_failed) == 3
1516N/A op = cmd_failed[0]
926N/A exitrv = cmd_failed[1]
926N/A errout = cmd_failed[2]
3158N/A
3158N/A err = _("""
3158N/AA '%(op)s' operation failed for child '%(lin)s' with an unexpected
3158N/Areturn value of %(exitrv)d and the following error message:
3158N/A%(errout)s
3158N/A
3158N/A"""
3158N/A ) % {
926N/A "lin": lin,
3158N/A "op": op,
3158N/A "exitrv": exitrv,
3158N/A "errout": errout,
3158N/A }
3158N/A
926N/A if detach_child_notsup:
926N/A err = _("Linked image type does not support "
926N/A "child detach: %s") % detach_child_notsup
926N/A
926N/A if detach_from_parent:
926N/A if exitrv == None:
1516N/A exitrv = pkgdefs.EXIT_PARENTOP
1516N/A err = _("Parent linked to child, can not detach "
926N/A "child: %s") % detach_from_parent
926N/A
3158N/A if detach_parent_notsup:
3158N/A err = _("Linked image type does not support "
3158N/A "parent detach: %s") % detach_parent_notsup
3158N/A
3158N/A if img_linked:
3158N/A err = _("Image already a linked child: %s") % \
3158N/A img_linked
926N/A
3158N/A if lin_malformed:
3158N/A err = _("Invalid linked image name: %s") % \
3158N/A lin_malformed
3158N/A
926N/A if link_to_self:
926N/A err = _("Can't link image to itself.")
1254N/A
1254N/A if parent_bad_img:
1254N/A if exitrv == None:
1254N/A exitrv = pkgdefs.EXIT_EACCESS
1516N/A err = _("Can't initialize parent image at path: %s") % \
1516N/A parent_bad_img
1254N/A
1254N/A if parent_bad_notabs:
3158N/A err = _("Parent path not absolute: %s") % \
3158N/A parent_bad_notabs
3158N/A
3158N/A if parent_bad_path:
3158N/A if exitrv == None:
3158N/A exitrv = pkgdefs.EXIT_EACCESS
3158N/A err = _("Can't access parent image at path: %s") % \
1254N/A parent_bad_path
3158N/A
3158N/A if parent_not_in_altroot:
3158N/A path, altroot = parent_not_in_altroot
3158N/A err = _("Parent image '%(path)s' is not located "
1254N/A "within the child's altroot '%(altroot)s'") % {
1254N/A "path": path,
926N/A "altroot": altroot
926N/A }
926N/A
926N/A if self_linked:
1516N/A err = _("Current image already a linked child: %s") % \
1516N/A self_linked
926N/A
926N/A if self_not_child:
926N/A if exitrv == None:
3158N/A exitrv = pkgdefs.EXIT_NOPARENT
3158N/A err = _("Current image is not a linked child: %s") % \
3158N/A self_not_child
3158N/A
3158N/A # set default error return value
3158N/A if exitrv == None:
3158N/A exitrv = pkgdefs.EXIT_OOPS
926N/A
3158N/A self.lix_err = err
3158N/A self.lix_bundle = None
3158N/A self.lix_exitrv = exitrv
3158N/A
3158N/A def __str__(self):
926N/A assert self.lix_err or self.lix_bundle
926N/A assert not (self.lix_err and self.lix_bundle), \
926N/A "self.lix_err = %s, self.lix_bundle = %s" % \
926N/A (str(self.lix_err), str(self.lix_bundle))
926N/A
926N/A # single error
926N/A if self.lix_err:
1516N/A return self.lix_err
1516N/A
926N/A # concatenate multiple errors
926N/A bundle_str = []
3158N/A for e in self.lix_bundle:
3158N/A bundle_str.append(str(e))
3158N/A return "\n".join(bundle_str)
3158N/A