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, 2016, Oracle and/or its affiliates. All rights reserved.
926N/A#
565N/A
2026N/Aimport errno
3094N/Aimport operator
1050N/Aimport os
3234N/Aimport six
2524N/Aimport xml.parsers.expat as expat
3245N/Afrom functools import total_ordering
3234N/Afrom six.moves.urllib.parse import urlsplit
926N/A
2339N/A# pkg classes
2339N/Aimport pkg.client.pkgdefs as pkgdefs
2339N/A
926N/A# EmptyI for argument defaults; can't import from misc due to circular
926N/A# dependency.
926N/AEmptyI = tuple()
838N/A
565N/Aclass ApiException(Exception):
2034N/A def __init__(self, *args):
2034N/A Exception.__init__(self)
2034N/A self.__verbose_info = []
1540N/A
2034N/A def add_verbose_info(self, info):
2034N/A self.__verbose_info.extend(info)
2200N/A
2034N/A @property
2034N/A def verbose_info(self):
2034N/A return self.__verbose_info
565N/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.""")
2339N/A
2339N/A
2524N/Aclass HistoryException(ApiException):
2524N/A """Private base exception class for all History exceptions."""
2524N/A
2524N/A def __init__(self, *args):
2524N/A Exception.__init__(self, *args)
2524N/A self.error = args[0]
2524N/A
2524N/A def __str__(self):
2524N/A return str(self.error)
2524N/A
2524N/A
2524N/Aclass HistoryLoadException(HistoryException):
2524N/A """Used to indicate that an unexpected error occurred while loading
2524N/A History operation information.
2524N/A
2524N/A The first argument should be an exception object related to the
2524N/A error encountered.
2524N/A """
2524N/A def __init__(self, *args):
2524N/A HistoryException.__init__(self, *args)
2524N/A self.parse_failure = isinstance(self.error, expat.ExpatError)
2524N/A
2524N/A
2524N/Aclass HistoryRequestException(HistoryException):
2524N/A """Used to indicate that invalid time / range values were provided to
2524N/A history API functions."""
2524N/A pass
2524N/A
2524N/A
2524N/Aclass HistoryStoreException(HistoryException):
2524N/A """Used to indicate that an unexpected error occurred while storing
2524N/A History operation information.
2524N/A
2524N/A The first argument should be an exception object related to the
2524N/A error encountered.
2524N/A """
2524N/A pass
2524N/A
2524N/A
2524N/Aclass HistoryPurgeException(HistoryException):
2524N/A """Used to indicate that an unexpected error occurred while purging
2524N/A History operation information.
2524N/A
2524N/A The first argument should be an exception object related to the
2524N/A error encountered.
2524N/A """
2524N/A pass
2524N/A
2524N/A
1710N/Aclass ImageLockedError(ApiException):
1710N/A """Used to indicate that the image is currently locked by another thread
1710N/A or process and cannot be modified."""
1710N/A
1710N/A def __init__(self, hostname=None, pid=None, pid_name=None):
1710N/A ApiException.__init__(self)
1710N/A self.hostname = hostname
1710N/A self.pid = pid
1710N/A self.pid_name = pid_name
1710N/A
1710N/A def __str__(self):
1710N/A if self.pid is not None and self.pid_name is not None and \
1710N/A self.hostname is not None:
1710N/A return _("The image cannot be modified as it is "
1710N/A "currently in use by another package client: "
3158N/A "{pid_name} on {host}, pid {pid}.").format(
3158N/A pid_name=self.pid_name, pid=self.pid,
3158N/A host=self.hostname)
1710N/A if self.pid is not None and self.pid_name is not None:
1710N/A return _("The image cannot be modified as it is "
1710N/A "currently in use by another package client: "
3158N/A "{pid_name} on an unknown host, pid {pid}.").format(
3158N/A pid_name=self.pid_name, pid=self.pid)
1710N/A elif self.pid is not None:
1710N/A return _("The image cannot be modified as it is "
1710N/A "currently in use by another package client: "
3158N/A "pid {pid} on {host}.").format(
3158N/A pid=self.pid, host=self.hostname)
1710N/A return _("The image cannot be modified as it is currently "
1710N/A "in use by another package client.")
1710N/A
565N/Aclass ImageNotFoundException(ApiException):
565N/A """Used when an image was not found"""
565N/A def __init__(self, user_specified, user_dir, root_dir):
565N/A ApiException.__init__(self)
565N/A self.user_specified = user_specified
565N/A self.user_dir = user_dir
565N/A self.root_dir = root_dir
565N/A
2976N/A def __str__(self):
3158N/A return _("No image rooted at '{0}'").format(self.user_dir)
2976N/A
2144N/A
2144N/Aclass ImageFormatUpdateNeeded(ApiException):
2144N/A """Used to indicate that an image cannot be used until its format is
2144N/A updated."""
2144N/A
2144N/A def __init__(self, path):
2144N/A ApiException.__init__(self)
2144N/A self.path = path
2144N/A
2144N/A def __str__(self):
3158N/A return _("The image rooted at {0} is written in an older format "
2144N/A "and must be updated before the requested operation can be "
3158N/A "performed.").format(self.path)
2144N/A
2407N/Aclass ImageInsufficentSpace(ApiException):
2407N/A """Used when insuffcient space exists for proposed operation"""
2407N/A def __init__(self, needed, avail, use):
2407N/A self.needed = needed
2407N/A self.avail = avail
2407N/A self.use = use
2407N/A
2407N/A def __str__(self):
2407N/A from pkg.misc import bytes_to_str
3158N/A return _("Insufficient disk space available ({avail}) "
3158N/A "for estimated need ({needed}) for {use}").format(
3158N/A avail=bytes_to_str(self.avail),
3158N/A needed=bytes_to_str(self.needed),
3158N/A use=self.use
3158N/A )
2875N/A
2144N/A
565N/Aclass VersionException(ApiException):
565N/A def __init__(self, expected_version, received_version):
565N/A ApiException.__init__(self)
565N/A self.expected_version = expected_version
565N/A self.received_version = received_version
565N/A
2144N/A
565N/Aclass PlanExistsException(ApiException):
565N/A def __init__(self, plan_type):
565N/A ApiException.__init__(self)
565N/A self.plan_type = plan_type
565N/A
1618N/A
1618N/Aclass PlanPrepareException(ApiException):
1618N/A """Base exception class for plan preparation errors."""
1618N/A pass
1618N/A
1618N/A
1755N/Aclass InvalidPackageErrors(ApiException):
1755N/A """Used to indicate that the requested operation could not be completed
1755N/A as one or more packages contained invalid metadata."""
1755N/A
1755N/A def __init__(self, errors):
1755N/A """'errors' should be a list of exceptions or strings
1755N/A indicating what packages had errors and why."""
1755N/A
1755N/A ApiException.__init__(self)
1755N/A self.errors = errors
1755N/A
1755N/A def __str__(self):
1755N/A return _("The requested operation cannot be completed due "
1755N/A "to invalid package metadata. Details follow:\n\n"
3158N/A "{0}").format("\n".join(str(e) for e in self.errors))
1755N/A
1755N/A
1618N/Aclass LicenseAcceptanceError(ApiException):
1618N/A """Used to indicate that license-related errors occurred during
1618N/A plan evaluation or execution."""
1618N/A
1618N/A def __init__(self, pfmri, src=None, dest=None, accepted=None,
1618N/A displayed=None):
1618N/A ApiException.__init__(self)
1618N/A self.fmri = pfmri
1618N/A self.src = src
1618N/A self.dest = dest
1618N/A self.accepted = accepted
1618N/A self.displayed = displayed
1618N/A
1618N/A
1618N/Aclass PkgLicenseErrors(PlanPrepareException):
1618N/A """Used to indicate that plan evaluation or execution failed due
1618N/A to license-related errors for a package."""
1618N/A
1618N/A def __init__(self, errors):
1618N/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"
3158N/A output += _("Package: {0}\n\n").format(sfmri)
1618N/A for e in self.__errors[sfmri]:
1618N/A lic_name = e.dest.attrs["license"]
3158N/A output += _("License: {0}\n").format(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
3459N/Aclass InvalidVarcetNames(PlanPrepareException):
3459N/A """Used to indicate that image plan evaluation or execution failed due
3459N/A to illegal characters in variant/facet names."""
3459N/A
3459N/A def __init__(self, invalid_names):
3459N/A PlanPrepareException.__init__(self)
3459N/A self.names = invalid_names
3459N/A
3459N/A def __str__(self):
3459N/A return _(", ".join(self.names) + " are not valid variant/facet "
3459N/A "names; variant/facet names cannot contain whitespace.")
3459N/A
3459N/A
1019N/Aclass ActuatorException(ApiException):
1019N/A def __init__(self, e):
1019N/A ApiException.__init__(self)
1019N/A self.exception = e
1019N/A
1019N/A def __str__(self):
1019N/A return str(self.exception)
1019N/A
1618N/A
565N/Aclass PrematureExecutionException(ApiException):
565N/A pass
565N/A
1618N/A
1618N/Aclass AlreadyPreparedException(PlanPrepareException):
565N/A pass
565N/A
1618N/A
565N/Aclass AlreadyExecutedException(ApiException):
565N/A pass
565N/A
1618N/A
565N/Aclass ImageplanStateException(ApiException):
565N/A def __init__(self, state):
565N/A ApiException.__init__(self)
565N/A self.state = state
565N/A
1369N/A
1710N/Aclass InvalidPlanError(ApiException):
1710N/A """Used to indicate that the image plan is no longer valid, likely as a
1710N/A result of an image state change since the plan was created."""
1710N/A
1710N/A def __str__(self):
1710N/A return _("The plan for the current operation is no longer "
1710N/A "valid. The image has likely been modified by another "
1710N/A "process or client. Please try the operation again.")
1710N/A
1710N/A
1372N/Aclass ImagePkgStateError(ApiException):
1369N/A
1369N/A def __init__(self, fmri, states):
1369N/A ApiException.__init__(self)
1369N/A self.fmri = fmri
1369N/A self.states = states
1369N/A
1369N/A def __str__(self):
3158N/A return _("Invalid package state change attempted '{states}' "
3158N/A "for package '{fmri}'.").format(states=self.states,
3158N/A fmri=self.fmri)
1369N/A
1369N/A
565N/Aclass IpkgOutOfDateException(ApiException):
2976N/A def __str__(self):
3356N/A return _("pkg(7) out of date")
2976N/A
565N/A
565N/Aclass ImageUpdateOnLiveImageException(ApiException):
2976N/A def __str__(self):
2976N/A return _("Requested operation cannot be performed "
2976N/A "in live image.")
2976N/A
565N/A
1328N/Aclass RebootNeededOnLiveImageException(ApiException):
2976N/A def __str__(self):
2976N/A return _("Requested operation cannot be performed "
2976N/A "in live image.")
2976N/A
1328N/A
565N/Aclass CanceledException(ApiException):
565N/A pass
565N/A
565N/Aclass PlanMissingException(ApiException):
565N/A pass
565N/A
565N/Aclass NoPackagesInstalledException(ApiException):
565N/A pass
565N/A
685N/Aclass PermissionsException(ApiException):
685N/A def __init__(self, path):
685N/A ApiException.__init__(self)
685N/A self.path = path
685N/A
685N/A def __str__(self):
685N/A if self.path:
3158N/A return _("Could not operate on {0}\nbecause of "
2126N/A "insufficient permissions. Please try the "
3158N/A "command again as a privileged user.").format(
3158N/A self.path)
685N/A else:
685N/A return _("""
2126N/ACould not complete the operation because of insufficient permissions.
2126N/APlease try the command again as a privileged user.
685N/A""")
685N/A
879N/Aclass FileInUseException(PermissionsException):
879N/A def __init__(self, path):
879N/A PermissionsException.__init__(self, path)
879N/A assert path
879N/A
879N/A def __str__(self):
3158N/A return _("Could not operate on {0}\nbecause the file is "
879N/A "in use. Please stop using the file and try the\n"
3158N/A "operation again.").format(self.path)
879N/A
1335N/A
2612N/Aclass UnprivilegedUserError(PermissionsException):
2612N/A def __init__(self, path):
2612N/A PermissionsException.__init__(self, path)
2612N/A
2612N/A def __str__(self):
2612N/A return _("Insufficient access to complete the requested "
2612N/A "operation.\nPlease try the operation again as a "
2612N/A "privileged user.")
2612N/A
2612N/A
1335N/Aclass ReadOnlyFileSystemException(PermissionsException):
1945N/A """Used to indicate that the operation was attempted on a
1335N/A read-only filesystem"""
1335N/A
1335N/A def __init__(self, path):
1335N/A ApiException.__init__(self)
1335N/A self.path = path
1335N/A
1335N/A def __str__(self):
1335N/A if self.path:
3158N/A return _("Could not complete the operation on {0}: "
3158N/A "read-only filesystem.").format(self.path)
1335N/A return _("Could not complete the operation: read-only "
1335N/A "filesystem.")
1335N/A
1335N/A
2974N/Aclass InvalidLockException(ApiException):
2974N/A def __init__(self, path):
2974N/A ApiException.__init__(self)
2974N/A self.path = path
2974N/A
2974N/A def __str__(self):
3158N/A return _("Unable to obtain or operate on lock at {0}.\n"
3158N/A "Please try the operation again as a privileged "
3158N/A "user.").format(self.path)
2974N/A
2974N/A
2301N/Aclass PackageMatchErrors(ApiException):
2510N/A """Used to indicate which patterns were not matched or illegal during
2510N/A a package name matching operation."""
2510N/A
2301N/A def __init__(self, unmatched_fmris=EmptyI, multiple_matches=EmptyI,
2301N/A illegal=EmptyI, multispec=EmptyI):
2301N/A ApiException.__init__(self)
2301N/A self.unmatched_fmris = unmatched_fmris
2301N/A self.multiple_matches = multiple_matches
2301N/A self.illegal = illegal
2301N/A self.multispec = multispec
2301N/A
2301N/A def __str__(self):
2301N/A res = []
2301N/A if self.unmatched_fmris:
2301N/A s = _("The following pattern(s) did not match any "
2301N/A "packages:")
2301N/A
2301N/A res += [s]
3158N/A res += ["\t{0}".format(p) for p in self.unmatched_fmris]
2301N/A
2301N/A if self.multiple_matches:
3158N/A s = _("'{0}' matches multiple packages")
2301N/A for p, lst in self.multiple_matches:
3158N/A res.append(s.format(p))
2301N/A for pfmri in lst:
3158N/A res.append("\t{0}".format(pfmri))
2301N/A
2301N/A if self.illegal:
3158N/A s = _("'{0}' is an illegal FMRI")
3158N/A res += [ s.format(p) for p in self.illegal ]
2301N/A
2301N/A if self.multispec:
2301N/A s = _("The following different patterns specify the "
2301N/A "same package(s):")
2301N/A res += [s]
2301N/A for t in self.multispec:
2301N/A res += [
2301N/A ", ".join([t[i] for i in range(1, len(t))])
3158N/A + ": {0}".format(t[0])
2301N/A ]
2301N/A
2301N/A return "\n".join(res)
2301N/A
2301N/A
3384N/Aclass PlanExecutionError(InvalidPlanError):
3384N/A """Used to indicate that the requested operation could not be executed
3384N/A due to unexpected changes in image state after planning was completed.
3384N/A """
3384N/A
3384N/A def __init__(self, paths):
3384N/A self.paths = paths
3384N/A
3384N/A def __str__(self):
3384N/A return _("The files listed below were modified after operation "
3384N/A "planning was complete or were missing during plan "
3384N/A "execution; this may indicate an administrative issue or "
3384N/A "system configuration issue:\n{0}".format(
3384N/A "\n".join(list(self.paths))))
3384N/A
3384N/A
565N/Aclass PlanCreationException(ApiException):
2339N/A def __init__(self,
2339N/A already_installed=EmptyI,
2339N/A badarch=EmptyI,
2339N/A illegal=EmptyI,
2339N/A installed=EmptyI,
2453N/A invalid_mediations=EmptyI,
2339N/A linked_pub_error=EmptyI,
2339N/A missing_dependency=EmptyI,
2339N/A missing_matches=EmptyI,
2339N/A multiple_matches=EmptyI,
2339N/A multispec=EmptyI,
2339N/A no_solution=False,
2339N/A no_tmp_origins=False,
2339N/A no_version=EmptyI,
2505N/A not_avoided=EmptyI,
2339N/A nofiles=EmptyI,
2339N/A obsolete=EmptyI,
2339N/A pkg_updates_required=EmptyI,
2445N/A rejected_pats=EmptyI,
2339N/A solver_errors=EmptyI,
3110N/A no_repo_pubs=EmptyI,
2339N/A unmatched_fmris=EmptyI,
2339N/A would_install=EmptyI,
2339N/A wrong_publishers=EmptyI,
2339N/A wrong_variants=EmptyI):
2339N/A
565N/A ApiException.__init__(self)
2339N/A self.already_installed = already_installed
2339N/A self.badarch = badarch
2339N/A self.illegal = illegal
2339N/A self.installed = installed
2453N/A self.invalid_mediations = invalid_mediations
2339N/A self.linked_pub_error = linked_pub_error
2339N/A self.missing_dependency = missing_dependency
2339N/A self.missing_matches = missing_matches
1505N/A self.multiple_matches = multiple_matches
1505N/A self.multispec = multispec
2339N/A self.no_solution = no_solution
2339N/A self.no_tmp_origins = no_tmp_origins
2339N/A self.no_version = no_version
2505N/A self.not_avoided = not_avoided
2339N/A self.nofiles = nofiles
2207N/A self.obsolete = obsolete
2339N/A self.pkg_updates_required = pkg_updates_required
2445N/A self.rejected_pats = rejected_pats
2339N/A self.solver_errors = solver_errors
2339N/A self.unmatched_fmris = unmatched_fmris
3110N/A self.no_repo_pubs = no_repo_pubs
2339N/A self.would_install = would_install
1505N/A self.wrong_publishers = wrong_publishers
2212N/A self.wrong_variants = wrong_variants
2339N/A
565N/A def __str__(self):
616N/A res = []
1141N/A if self.unmatched_fmris:
616N/A s = _("""\
2339N/AThe following pattern(s) did not match any allowable packages. Try
2445N/Ausing a different matching pattern, or refreshing publisher information:
2339N/A""")
926N/A res += [s]
3158N/A res += ["\t{0}".format(p) for p in self.unmatched_fmris]
565N/A
2445N/A if self.rejected_pats:
2445N/A s = _("""\
2445N/AThe following pattern(s) only matched packages rejected by user request. Try
2445N/Ausing a different matching pattern, or refreshing publisher information:
2445N/A""")
2445N/A res += [s]
3158N/A res += ["\t{0}".format(p) for p in self.rejected_pats]
2445N/A
2212N/A if self.wrong_variants:
2212N/A s = _("""\
2212N/AThe following pattern(s) only matched packages that are not available
2212N/Afor the current image's architecture, zone type, and/or other variant:""")
2212N/A res += [s]
3158N/A res += ["\t{0}".format(p) for p in self.wrong_variants]
2212N/A
1505N/A if self.wrong_publishers:
1505N/A s = _("The following patterns only matched packages "
1505N/A "that are from publishers other than that which "
1505N/A "supplied the already installed version of this package")
1505N/A res += [s]
3158N/A res += ["\t{0}: {1}".format(p[0], ", ".join(p[1])) for p in self.wrong_publishers]
1505N/A
565N/A if self.multiple_matches:
3158N/A s = _("'{0}' matches multiple packages")
565N/A for p, lst in self.multiple_matches:
3158N/A res.append(s.format(p))
922N/A for pfmri in lst:
3158N/A res.append("\t{0}".format(pfmri))
616N/A
1505N/A if self.missing_matches:
3158N/A s = _("'{0}' matches no installed packages")
3158N/A res += [ s.format(p) for p in self.missing_matches ]
616N/A
1505N/A if self.illegal:
3158N/A s = _("'{0}' is an illegal fmri")
3158N/A res += [ s.format(p) for p in self.illegal ]
655N/A
838N/A if self.badarch:
3158N/A s = _("'{p}' supports the following architectures: "
3158N/A "{archs}")
3158N/A a = _("Image architecture is defined as: {0}")
3158N/A res += [ s.format(p=self.badarch[0],
3158N/A archs=", ".join(self.badarch[1]))]
3158N/A res += [ a.format(self.badarch[2])]
3158N/A
3158N/A s = _("'{p}' depends on obsolete package '{op}'")
3158N/A res += [ s.format(p=p, op=op) for p, op in self.obsolete ]
1461N/A
1352N/A if self.installed:
1352N/A s = _("The proposed operation can not be performed for "
1352N/A "the following package(s) as they are already "
1352N/A "installed: ")
1352N/A res += [s]
3158N/A res += ["\t{0}".format(p) for p in self.installed]
1352N/A
2453N/A if self.invalid_mediations:
2453N/A s = _("The following mediations are not syntactically "
2453N/A "valid:")
3234N/A for m, entries in six.iteritems(self.invalid_mediations):
2453N/A for value, error in entries.values():
2453N/A res.append(error)
2453N/A
1505N/A if self.multispec:
2681N/A s = _("The following patterns specify different "
2681N/A "versions of the same package(s):")
1505N/A res += [s]
1505N/A for t in self.multispec:
1505N/A res += [
1505N/A ", ".join(
1505N/A [t[i] for i in range(1, len(t))])
3158N/A + ": {0}".format(t[0])
1945N/A ]
1505N/A if self.no_solution:
1505N/A res += [_("No solution was found to satisfy constraints")]
2197N/A if isinstance(self.no_solution, list):
2197N/A res.extend(self.no_solution)
2207N/A
2339N/A if self.pkg_updates_required:
2339N/A s = _("""\
2339N/ASyncing this linked image would require the following package updates:
2339N/A""")
2339N/A res += [s]
2339N/A for (oldfmri, newfmri) in self.pkg_updates_required:
3158N/A res += ["{oldfmri} -> {newfmri}\n".format(
3158N/A oldfmri=oldfmri, newfmri=newfmri)]
2339N/A
1505N/A if self.no_version:
1505N/A res += self.no_version
1505N/A
2339N/A if self.no_tmp_origins:
2339N/A s = _("""
2339N/AThe proposed operation on this parent image can not be performed because
2339N/Atemporary origins were specified and this image has children. Please either
2339N/Aretry the operation again without specifying any temporary origins, or if
2339N/Apackages from additional origins are required, please configure those origins
2339N/Apersistently.""")
2339N/A res = [s]
2339N/A
1505N/A if self.missing_dependency:
3158N/A res += [_("Package {pkg} is missing a dependency: "
3158N/A "{dep}").format(
3158N/A pkg=self.missing_dependency[0],
3158N/A dep=self.missing_dependency[1])]
2200N/A if self.nofiles:
2200N/A res += [_("The following files are not packaged in this image:")]
3158N/A res += ["\t{0}".format(f) for f in self.nofiles]
1945N/A
2207N/A if self.solver_errors:
2207N/A res += ["\n"]
2207N/A res += [_("Solver dependency errors:")]
2207N/A res.extend(self.solver_errors)
2207N/A
2228N/A if self.already_installed:
2339N/A res += [_("The following packages are already "
2339N/A "installed in this image; use uninstall to "
2339N/A "avoid these:")]
3158N/A res += [ "\t{0}".format(s) for s in self.already_installed]
2228N/A
2228N/A if self.would_install:
2339N/A res += [_("The following packages are a target "
2339N/A "of group dependencies; use install to unavoid "
2339N/A "these:")]
3158N/A res += [ "\t{0}".format(s) for s in self.would_install]
2228N/A
2505N/A if self.not_avoided:
2505N/A res += [_("The following packages are not on the "
2505N/A "avoid list, so they\ncannot be removed from it.")]
3158N/A res += [ "\t{0}".format(s) for s in sorted(self.not_avoided)]
2505N/A
2339N/A def __format_li_pubs(pubs, res):
2339N/A i = 0
2339N/A for pub, sticky in pubs:
3158N/A s = " {0} {1:d}: {2}".format(_("PUBLISHER"),
3158N/A i, pub)
2339N/A mod = []
2339N/A if not sticky:
2339N/A mod.append(_("non-sticky"))
2339N/A if mod:
3158N/A s += " ({0})".format(",".join(mod))
2339N/A res.append(s)
2339N/A i += 1
2339N/A
2339N/A if self.linked_pub_error:
2339N/A res = []
2339N/A (pubs, parent_pubs) = self.linked_pub_error
2339N/A
2339N/A res.append(_("""
2339N/AInvalid child image publisher configuration. Child image publisher
2364N/Aconfiguration must be a superset of the parent image publisher configuration.
2339N/APlease update the child publisher configuration to match the parent. If the
2339N/Achild image is a zone this can be done automatically by detaching and
2339N/Aattaching the zone.
2339N/A
2339N/AThe parent image has the following enabled publishers:"""))
2339N/A __format_li_pubs(parent_pubs, res)
2339N/A res.append(_("""
2339N/AThe child image has the following enabled publishers:"""))
2339N/A __format_li_pubs(pubs, res)
2339N/A
3110N/A if self.no_repo_pubs:
3110N/A res += [_("The following publishers do not have any "
3110N/A "configured package repositories and cannot be "
3110N/A "used in package dehydration or rehydration "
3110N/A "operations:\n")]
3158N/A res += ["\t{0}".format(s) for s in sorted(
3110N/A self.no_repo_pubs)]
3110N/A
1352N/A return "\n".join(res)
565N/A
2228N/A
2205N/Aclass ConflictingActionError(ApiException):
2205N/A """Used to indicate that the imageplan would result in one or more sets
2205N/A of conflicting actions, meaning that more than one action would exist on
2205N/A the system with the same key attribute value in the same namespace.
2205N/A There are three categories, each with its own subclass:
2205N/A
2205N/A - multiple files delivered to the same path or drivers, users, groups,
2205N/A etc, delivered with the same key attribute;
2205N/A
2205N/A - multiple objects delivered to the same path which aren't the same
2205N/A type;
2205N/A
2205N/A - multiple directories, links, or hardlinks delivered to the same path
2205N/A but with conflicting attributes.
2205N/A """
2205N/A
2205N/A def __init__(self, data):
2205N/A self._data = data
2205N/A
2205N/Aclass ConflictingActionErrors(ApiException):
2205N/A """A container for multiple ConflictingActionError exception objects
2205N/A that can be raised as a single exception."""
2205N/A
2205N/A def __init__(self, errors):
2205N/A self.__errors = errors
2205N/A
2205N/A def __str__(self):
2205N/A return "\n\n".join((str(err) for err in self.__errors))
2205N/A
2205N/Aclass DuplicateActionError(ConflictingActionError):
2205N/A """Multiple actions of the same type have been delivered with the same
2205N/A key attribute (when not allowed)."""
2205N/A
2205N/A def __str__(self):
2205N/A pfmris = set((a[1] for a in self._data))
2205N/A kv = self._data[0][0].attrs[self._data[0][0].key_attr]
2205N/A action = self._data[0][0].name
2205N/A if len(pfmris) > 1:
3158N/A s = _("The following packages all deliver {action} "
3158N/A "actions to {kv}:\n").format(**locals())
2205N/A for a, p in self._data:
3158N/A s += "\n {0}".format(p)
3347N/A s += _("\n\nThese packages cannot be installed "
3347N/A "together. Any non-conflicting subset\nof "
3347N/A "the above packages can be installed.")
2205N/A else:
2205N/A pfmri = pfmris.pop()
3158N/A s = _("The package {pfmri} delivers multiple copies "
3158N/A "of {action} {kv}").format(**locals())
2205N/A s += _("\nThis package must be corrected before it "
2205N/A "can be installed.")
2205N/A
2205N/A return s
2205N/A
2205N/Aclass InconsistentActionTypeError(ConflictingActionError):
2205N/A """Multiple actions of different types have been delivered with the same
2205N/A 'path' attribute. While this exception could represent other action
2205N/A groups which share a single namespace, none such exist."""
2205N/A
2205N/A def __str__(self):
2205N/A ad = {}
2205N/A pfmris = set()
2205N/A kv = self._data[0][0].attrs[self._data[0][0].key_attr]
2205N/A for a, p in self._data:
2205N/A ad.setdefault(a.name, []).append(p)
2205N/A pfmris.add(p)
2205N/A
2205N/A if len(pfmris) > 1:
2205N/A s = _("The following packages deliver conflicting "
3158N/A "action types to {0}:\n").format(kv)
3234N/A for name, pl in six.iteritems(ad):
3158N/A s += "\n {0}:".format(name)
3158N/A s += "".join("\n {0}".format(p) for p in pl)
3347N/A s += _("\n\nThese packages cannot be installed "
3347N/A "together. Any non-conflicting subset\nof "
3347N/A "the above packages can be installed.")
2205N/A else:
2205N/A pfmri = pfmris.pop()
3234N/A types = list_to_lang(list(ad.keys()))
3158N/A s = _("The package {pfmri} delivers conflicting "
3158N/A "action types ({types}) to {kv}").format(**locals())
2205N/A s += _("\nThis package must be corrected before it "
2205N/A "can be installed.")
2205N/A return s
2205N/A
2205N/Aclass InconsistentActionAttributeError(ConflictingActionError):
2205N/A """Multiple actions of the same type representing the same object have
2205N/A have been delivered, but with conflicting attributes, such as two
2205N/A directories at /usr with groups 'root' and 'sys', or two 'root' users
2205N/A with uids '0' and '7'."""
2205N/A
2205N/A def __str__(self):
2205N/A actions = self._data
2205N/A keyattr = actions[0][0].attrs[actions[0][0].key_attr]
2205N/A actname = actions[0][0].name
2205N/A
2205N/A # Trim the action's attributes to only those required to be
2205N/A # unique.
2205N/A def ou(action):
2205N/A ua = dict(
2205N/A (k, v)
3234N/A for k, v in six.iteritems(action.attrs)
2453N/A if ((k in action.unique_attrs and
2453N/A not (k == "preserve" and "overlay" in action.attrs)) or
2453N/A ((action.name == "link" or action.name == "hardlink") and
2453N/A k.startswith("mediator")))
2205N/A )
2205N/A action.attrs = ua
2205N/A return action
2205N/A
2205N/A d = {}
2205N/A for a in actions:
2232N/A if a[0].attrs.get("implicit", "false") == "false":
2232N/A d.setdefault(str(ou(a[0])), set()).add(a[1])
2205N/A l = sorted([
2205N/A (len(pkglist), action, pkglist)
3234N/A for action, pkglist in six.iteritems(d)
2205N/A ])
2205N/A
2205N/A s = _("The requested change to the system attempts to install "
3158N/A "multiple actions\nfor {a} '{k}' with conflicting "
3158N/A "attributes:\n\n").format(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:
3158N/A t = _(" {n:d} package delivers '{a}':\n")
2205N/A else:
3158N/A t = _(" {n:d} packages deliver '{a}':\n")
3158N/A s += t.format(n=num, a=action)
2205N/A for pkg in sorted(pkglist):
3158N/A s += _(" {0}\n").format(pkg)
2205N/A else:
3158N/A t = _(" {n:d} packages deliver '{a}', including:\n")
3158N/A s += t.format(n=num, a=action)
2205N/A for pkg in sorted(pkglist)[:5]:
3158N/A s += _(" {0}\n").format(pkg)
2205N/A
2205N/A if len(allpkgs) == 1:
2239N/A s += _("\nThis package must be corrected before it "
2205N/A "can be installed.")
2205N/A else:
3347N/A s += _("\n\nThese packages cannot be installed "
3347N/A "together. Any non-conflicting subset\nof "
3347N/A "the above packages can be installed.")
2205N/A
2205N/A return s
2205N/A
3206N/A
3206N/Aclass ImageBoundaryError(ApiException):
3206N/A """Used to indicate that a file is delivered to image dir"""
3206N/A
3206N/A GENERIC = "generic" # generic image boundary violation
3206N/A OUTSIDE_BE = "outside_be" # deliver items outside boot environment
3206N/A RESERVED = "reserved" # deliver items to reserved dirs
3206N/A
3206N/A def __init__(self, fmri, actions=None):
3206N/A """fmri is the package fmri
3206N/A actions should be a dictionary of which key is the
3206N/A error type and value is a list of actions"""
3206N/A
3206N/A ApiException.__init__(self)
3206N/A self.fmri = fmri
3206N/A generic = _("The following items are outside the boundaries "
3206N/A "of the target image:\n\n")
3206N/A outside_be = _("The following items are delivered outside "
3206N/A "the target boot environment:\n\n")
3206N/A reserved = _("The following items are delivered to "
3206N/A "reserved directories:\n\n")
3206N/A
3206N/A self.message = {
3206N/A self.GENERIC: generic,
3206N/A self.OUTSIDE_BE: outside_be,
3206N/A self.RESERVED: reserved
3206N/A }
3206N/A
3206N/A if actions:
3206N/A self.actions = actions
3206N/A else:
3206N/A self.actions = {}
3206N/A
3206N/A def append_error(self, action, err_type=GENERIC):
3206N/A """This function is used to append errors in the error
3206N/A dictionary"""
3206N/A
3206N/A if action:
3206N/A self.actions.setdefault(err_type, []).append(action)
3206N/A
3206N/A def isEmpty(self):
3206N/A """Return whether error dictionary is empty"""
3206N/A
3206N/A return len(self.actions) == 0
3206N/A
3206N/A def __str__(self):
3206N/A error_list = [self.GENERIC, self.OUTSIDE_BE, self.RESERVED]
3458N/A s = ""
3206N/A for err_type in error_list:
3206N/A if not err_type in self.actions:
3206N/A continue
3206N/A if self.actions[err_type]:
3458N/A if err_type == self.GENERIC:
3458N/A s += ("The package {0} delivers items"
3458N/A " outside the boundaries of"
3458N/A " the target image and can not be"
3458N/A " installed.\n\n").format(self.fmri)
3458N/A elif err_type == self.OUTSIDE_BE:
3458N/A s += ("The package {0} delivers items"
3458N/A " outside the target boot"
3458N/A " environment and can not be"
3458N/A " installed.\n\n").format(self.fmri)
3458N/A else:
3458N/A s += ("The package {0} delivers items"
3458N/A " to reserved directories and can"
3458N/A " not be installed.\n\n").format(self.fmri)
3206N/A s += self.message[err_type]
3206N/A for action in self.actions[err_type]:
3206N/A s += (" {0} {1}\n").format(
3206N/A action.name, action.attrs["path"])
3206N/A return s
3206N/A
3206N/A
3206N/Aclass ImageBoundaryErrors(ApiException):
3206N/A """A container for multiple ImageBoundaryError exception objects
3206N/A that can be raised as a single exception."""
3206N/A
3206N/A def __init__(self, errors):
3206N/A ApiException.__init__(self)
3206N/A self.__errors = errors
3206N/A
3206N/A generic = _("The following packages deliver items outside "
3206N/A "the boundaries of the target image and can not be "
3206N/A "installed:\n\n")
3206N/A outside_be = _("The following packages deliver items outside "
3206N/A "the target boot environment and can not be "
3206N/A "installed:\n\n")
3206N/A reserved = _("The following packages deliver items to reserved "
3206N/A "directories and can not be installed:\n\n")
3206N/A
3206N/A self.message = {
3206N/A ImageBoundaryError.GENERIC: generic,
3206N/A ImageBoundaryError.OUTSIDE_BE: outside_be,
3206N/A ImageBoundaryError.RESERVED: reserved
3206N/A }
3206N/A
3206N/A def __str__(self):
3206N/A if len(self.__errors) <= 1:
3206N/A return "\n".join([str(err) for err in self.__errors])
3206N/A
3206N/A s = ""
3206N/A for err_type in self.message:
3206N/A cur_errs = []
3206N/A for err in self.__errors:
3206N/A # If err does not contain this error type
3206N/A # we just ignore this.
3206N/A if not err_type in err.actions or \
3206N/A not err.actions[err_type]:
3206N/A continue
3206N/A cur_errs.append(err)
3206N/A
3206N/A if not cur_errs:
3206N/A continue
3206N/A
3206N/A if len(cur_errs) == 1:
3458N/A s += str(cur_errs[0]) + "\n"
3206N/A continue
3206N/A
3206N/A s += self.message[err_type]
3206N/A for err in cur_errs:
3206N/A s += (" {0}\n").format(err.fmri)
3206N/A for action in err.actions[err_type]:
3206N/A s += (" {0} {1}\n").format(
3206N/A action.name, action.attrs["path"])
3206N/A s += "\n"
3206N/A return s
3206N/A
3206N/A
2205N/Adef list_to_lang(l):
2205N/A """Takes a list of items and puts them into a string, with commas in
2205N/A between items, and an "and" between the last two items. Special cases
2205N/A for lists of two or fewer items, and uses the Oxford comma."""
2205N/A
2205N/A if not l:
2205N/A return ""
2205N/A if len(l) == 1:
2205N/A return l[0]
2205N/A if len(l) == 2:
2205N/A # Used for a two-element list
3158N/A return _("{penultimate} and {ultimate}").format(
3158N/A penultimate=l[0],
3158N/A ultimate=l[1]
3158N/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
3158N/A elementtemplate = _("{0}, ")
2205N/A # 'listtemplate' concatenates the concatenation of non-ultimate elements
2205N/A # and the ultimate element.
3158N/A listtemplate = _("{list}and {tail}")
3158N/A return listtemplate.format(
3158N/A list="".join(elementtemplate.format(i) for i in l[:-1]),
3158N/A tail=l[-1]
3158N/A )
1068N/A
1050N/Aclass ActionExecutionError(ApiException):
1859N/A """Used to indicate that action execution (such as install, remove,
1859N/A etc.) failed even though the action is valid.
1050N/A
1050N/A In particular, this exception indicates that something went wrong in the
1859N/A application (or unapplication) of the action to the system, and is most
3356N/A likely not an error in the pkg(7) code."""
1859N/A
1859N/A def __init__(self, action, details=None, error=None, fmri=None,
1859N/A use_errno=None):
1859N/A """'action' is the object for the action that failed during the
1859N/A requested operation.
1859N/A
1859N/A 'details' is an optional message explaining what operation
1859N/A failed, why it failed, and why it cannot continue. It should
1859N/A also include a suggestion as to how to resolve the situation
1859N/A if possible.
1859N/A
1859N/A 'error' is an optional exception object that may have been
1859N/A raised when the operation failed.
1050N/A
1859N/A 'fmri' is an optional package FMRI indicating what package
1859N/A was being operated on at the time the error occurred.
1859N/A
1859N/A 'use_errno' is an optional boolean value indicating whether
1859N/A the strerror() text of the exception should be used. If
1859N/A 'details' is provided, the default value is False, otherwise
1859N/A True."""
1050N/A
1859N/A assert (details or error)
1050N/A self.action = action
1859N/A self.details = details
1859N/A self.error = error
1859N/A self.fmri = fmri
1859N/A if use_errno == None:
1859N/A # If details were provided, don't use errno unless
1859N/A # explicitly requested.
1859N/A use_errno = not details
1859N/A self.use_errno = use_errno
1050N/A
1050N/A def __str__(self):
1050N/A errno = ""
1859N/A if self.use_errno and self.error and \
1859N/A hasattr(self.error, "errno"):
3158N/A errno = "[errno {0:d}: {1}]".format(self.error.errno,
1859N/A os.strerror(self.error.errno))
1050N/A
1859N/A details = self.details or ""
1050N/A
1050N/A # Fall back on the wrapped exception if we don't have anything
1050N/A # useful.
1859N/A if not errno and not details:
1859N/A return str(self.error)
1859N/A
1859N/A if errno and details:
3158N/A details = "{0}: {1}".format(errno, details)
1050N/A
1859N/A if details and not self.fmri:
1859N/A details = _("Requested operation failed for action "
3158N/A "{action}:\n{details}").format(
3158N/A action=self.action,
3158N/A details=details)
1859N/A elif details:
1859N/A details = _("Requested operation failed for package "
3158N/A "{fmri}:\n{details}").format(fmri=self.fmri,
3158N/A details=details)
1050N/A
1050N/A # If we only have one of the two, no need for the colon.
3158N/A return "{0}{1}".format(errno, details)
1050N/A
1068N/A
3293N/Aclass CatalogOriginRefreshException(ApiException):
3293N/A def __init__(self, failed, total, errmessage=None):
3293N/A ApiException.__init__(self)
3293N/A self.failed = failed
3293N/A self.total = total
3293N/A self.errmessage = errmessage
3293N/A
3293N/A
565N/Aclass CatalogRefreshException(ApiException):
1603N/A def __init__(self, failed, total, succeeded, errmessage=None):
565N/A ApiException.__init__(self)
565N/A self.failed = failed
565N/A self.total = total
565N/A self.succeeded = succeeded
1603N/A self.errmessage = errmessage
565N/A
1068N/A
1352N/Aclass CatalogError(ApiException):
1352N/A """Base exception class for all catalog exceptions."""
1352N/A
1352N/A def __init__(self, *args, **kwargs):
565N/A ApiException.__init__(self)
1352N/A if args:
1352N/A self.data = args[0]
1352N/A else:
1352N/A self.data = None
1516N/A self._args = kwargs
1352N/A
1352N/A def __str__(self):
1352N/A return str(self.data)
1352N/A
1352N/A
1352N/Aclass AnarchicalCatalogFMRI(CatalogError):
1352N/A """Used to indicate that the specified FMRI is not valid for catalog
1352N/A operations because it is missing publisher information."""
1352N/A
1352N/A def __str__(self):
3158N/A return _("The FMRI '{0}' does not contain publisher information "
3158N/A "and cannot be used for catalog operations.").format(
3158N/A self.data)
1352N/A
1352N/A
1352N/Aclass BadCatalogMetaRoot(CatalogError):
1352N/A """Used to indicate an operation on the catalog's meta_root failed
1352N/A because the meta_root is invalid."""
1352N/A
1352N/A def __str__(self):
3158N/A return _("Catalog meta_root '{root}' is invalid; unable "
3158N/A "to complete operation: '{op}'.").format(root=self.data,
3158N/A op=self._args.get("operation", None))
1352N/A
1352N/A
1352N/Aclass BadCatalogPermissions(CatalogError):
1352N/A """Used to indicate the server catalog files do not have the expected
1352N/A permissions."""
1352N/A
1352N/A def __init__(self, files):
1352N/A """files should contain a list object with each entry consisting
1352N/A of a tuple of filename, expected_mode, received_mode."""
1352N/A if not files:
1352N/A files = []
1352N/A CatalogError.__init__(self, files)
1352N/A
1352N/A def __str__(self):
1352N/A msg = _("The following catalog files have incorrect "
1352N/A "permissions:\n")
2614N/A for f in self.data:
1352N/A fname, emode, fmode = f
3158N/A msg += _("\t{fname}: expected mode: {emode}, found "
3158N/A "mode: {fmode}\n").format(fname=fname,
3158N/A emode=emode, fmode=fmode)
1352N/A return msg
1352N/A
1352N/A
1352N/Aclass BadCatalogSignatures(CatalogError):
1352N/A """Used to indicate that the Catalog signatures are not valid."""
1352N/A
1352N/A def __str__(self):
3158N/A return _("The signature data for the '{0}' catalog file is not "
3158N/A "valid.").format(self.data)
1352N/A
1352N/A
1352N/Aclass BadCatalogUpdateIdentity(CatalogError):
1352N/A """Used to indicate that the requested catalog updates could not be
1352N/A applied as the new catalog data is significantly different such that
1352N/A the old catalog cannot be updated to match it."""
1352N/A
1352N/A def __str__(self):
1352N/A return _("Unable to determine the updates needed for "
1352N/A "the current catalog using the provided catalog "
3158N/A "update data in '{0}'.").format(self.data)
1352N/A
1352N/A
1352N/Aclass DuplicateCatalogEntry(CatalogError):
1352N/A """Used to indicate that the specified catalog operation could not be
1352N/A performed since it would result in a duplicate catalog entry."""
1352N/A
1352N/A def __str__(self):
3158N/A return _("Unable to perform '{op}' operation for catalog "
3158N/A "{name}; completion would result in a duplicate entry "
3158N/A "for package '{fmri}'.").format(op=self._args.get(
3158N/A "operation", None), name=self._args.get("catalog_name",
3158N/A None), fmri=self.data)
1352N/A
1352N/A
1352N/Aclass CatalogUpdateRequirements(CatalogError):
1352N/A """Used to indicate that an update request for the catalog could not
1352N/A be performed because update requirements were not satisfied."""
1352N/A
1352N/A def __str__(self):
1352N/A return _("Catalog updates can only be applied to an on-disk "
1352N/A "catalog.")
1352N/A
1352N/A
1352N/Aclass InvalidCatalogFile(CatalogError):
1352N/A """Used to indicate a Catalog file could not be loaded."""
1352N/A
1352N/A def __str__(self):
3158N/A return _("Catalog file '{0}' is invalid.\nUse 'pkgrepo rebuild' "
3158N/A "to create a new package catalog.").format(self.data)
1352N/A
1352N/A
2022N/Aclass MismatchedCatalog(CatalogError):
2022N/A """Used to indicate that a Catalog's attributes and parts do not
2022N/A match. This is likely the result of an attributes file being
2022N/A retrieved which doesn't match the parts that were retrieved such
2022N/A as in a misconfigured or stale cache case."""
2022N/A
2022N/A def __str__(self):
3158N/A return _("The content of the catalog for publisher '{0}' "
2022N/A "doesn't match the catalog's attributes. This is "
2022N/A "likely the result of a mix of older and newer "
3158N/A "catalog files being provided for the publisher.").format(
3158N/A self.data)
2022N/A
2022N/A
1352N/Aclass ObsoleteCatalogUpdate(CatalogError):
1352N/A """Used to indicate that the specified catalog updates are for an older
1352N/A version of the catalog and cannot be applied."""
1352N/A
1352N/A def __str__(self):
1352N/A return _("Unable to determine the updates needed for the "
3158N/A "catalog using the provided catalog update data in '{0}'. "
1352N/A "The specified catalog updates are for an older version "
3158N/A "of the catalog and cannot be used.").format(self.data)
1352N/A
1352N/A
1352N/Aclass UnknownCatalogEntry(CatalogError):
1352N/A """Used to indicate that an entry for the specified package FMRI or
1352N/A pattern could not be found in the catalog."""
1352N/A
1352N/A def __str__(self):
3158N/A return _("'{0}' could not be found in the catalog.").format(
3158N/A self.data)
1352N/A
1352N/A
1352N/Aclass UnknownUpdateType(CatalogError):
1352N/A """Used to indicate that the specified CatalogUpdate operation is
1352N/A unknown."""
1352N/A
1352N/A def __str__(self):
3158N/A return _("Unknown catalog update type '{0}'").format(self.data)
1352N/A
1352N/A
1431N/Aclass UnrecognizedCatalogPart(CatalogError):
1431N/A """Raised when the catalog finds a CatalogPart that is unrecognized
1431N/A or invalid."""
1431N/A
1431N/A def __str__(self):
3158N/A return _("Unrecognized, unknown, or invalid CatalogPart '{0}'").format(
3158N/A self.data)
1431N/A
1431N/A
1352N/Aclass InventoryException(ApiException):
1352N/A """Used to indicate that some of the specified patterns to a catalog
1970N/A matching function did not match any catalog entries, or were invalid
1970N/A patterns."""
1352N/A
1352N/A def __init__(self, illegal=EmptyI, matcher=EmptyI, notfound=EmptyI,
1352N/A publisher=EmptyI, version=EmptyI):
1352N/A ApiException.__init__(self)
838N/A self.illegal = illegal
1352N/A self.matcher = matcher
1352N/A self.notfound = set(notfound)
1352N/A self.publisher = publisher
1352N/A self.version = version
1352N/A
1352N/A self.notfound.update(matcher)
1352N/A self.notfound.update(publisher)
1352N/A self.notfound.update(version)
3107N/A self.notfound = sorted(list(self.notfound))
1352N/A
1945N/A assert self.illegal or self.notfound
565N/A
596N/A def __str__(self):
596N/A outstr = ""
596N/A for x in self.illegal:
596N/A # Illegal FMRIs have their own __str__ method
3158N/A outstr += "{0}\n".format(x)
614N/A
1352N/A if self.matcher or self.publisher or self.version:
614N/A outstr += _("No matching package could be found for "
614N/A "the following FMRIs in any of the catalogs for "
926N/A "the current publishers:\n")
614N/A
1352N/A for x in self.matcher:
3158N/A outstr += \
3158N/A _("{0} (pattern did not match)\n").format(x)
1352N/A for x in self.publisher:
3158N/A outstr += _("{0} (publisher did not "
3158N/A "match)\n").format(x)
1352N/A for x in self.version:
3158N/A outstr += \
3158N/A _("{0} (version did not match)\n").format(x)
596N/A return outstr
565N/A
1027N/A
1191N/A# SearchExceptions
1191N/A
1027N/Aclass SearchException(ApiException):
1027N/A """Based class used for all search-related api exceptions."""
1027N/A pass
1027N/A
1027N/A
1191N/Aclass MalformedSearchRequest(SearchException):
1191N/A """Raised when the server cannot understand the format of the
1191N/A search request."""
1191N/A
1191N/A def __init__(self, url):
1191N/A SearchException.__init__(self)
1191N/A self.url = url
1191N/A
1191N/A def __str__(self):
1191N/A return str(self.url)
1191N/A
1191N/A
1191N/Aclass NegativeSearchResult(SearchException):
1191N/A """Returned when the search cannot find any matches."""
1191N/A
1191N/A def __init__(self, url):
1191N/A SearchException.__init__(self)
1191N/A self.url = url
1191N/A
1191N/A def __str__(self):
3158N/A return _("The search at url {0} returned no results.").format(
3158N/A self.url)
1191N/A
1191N/A
1191N/Aclass ProblematicSearchServers(SearchException):
1191N/A """This class wraps exceptions which could appear while trying to
1191N/A do a search request."""
1191N/A
1191N/A def __init__(self, failed=EmptyI, invalid=EmptyI, unsupported=EmptyI):
1191N/A SearchException.__init__(self)
1191N/A self.failed_servers = failed
1191N/A self.invalid_servers = invalid
1191N/A self.unsupported_servers = unsupported
1191N/A
1191N/A def __str__(self):
1895N/A s = _("Some repositories failed to respond appropriately:\n")
1191N/A for pub, err in self.failed_servers:
3158N/A s += _("{o}:\n{msg}\n").format(
3158N/A o=pub, msg=err)
1191N/A for pub in self.invalid_servers:
3158N/A s += _("{0} did not return a valid "
3158N/A "response.\n".format(pub))
1191N/A if len(self.unsupported_servers) > 0:
1895N/A s += _("Some repositories don't support requested "
1895N/A "search operation:\n")
1191N/A for pub, err in self.unsupported_servers:
3158N/A s += _("{o}:\n{msg}\n").format(
3158N/A o=pub, msg=err)
1191N/A
1191N/A return s
1191N/A
1191N/A
1191N/Aclass SlowSearchUsed(SearchException):
1191N/A """This exception is thrown when a local search is performed without
1191N/A an index. It's raised after all results have been yielded."""
1191N/A
1191N/A def __str__(self):
1191N/A return _("Search performance is degraded.\n"
1191N/A "Run 'pkg rebuild-index' to improve search speed.")
1191N/A
1191N/A
3245N/A@total_ordering
1191N/Aclass UnsupportedSearchError(SearchException):
1191N/A """Returned when a search protocol is not supported by the
1191N/A remote server."""
1191N/A
1191N/A def __init__(self, url=None, proto=None):
1191N/A SearchException.__init__(self)
1191N/A self.url = url
1191N/A self.proto = proto
1191N/A
1191N/A def __str__(self):
1895N/A s = _("Search repository does not support the requested "
1895N/A "protocol:")
1191N/A if self.url:
3158N/A s += "\nRepository URL: {0}".format(self.url)
1191N/A if self.proto:
3158N/A s += "\nRequested operation: {0}".format(self.proto)
1191N/A return s
1191N/A
3245N/A def __eq__(self, other):
3245N/A if not isinstance(other, UnsupportedSearchError):
3245N/A return False
3245N/A return self.url == other.url and \
3245N/A self.proto == other.proto
3245N/A
3245N/A def __le__(self, other):
1191N/A if not isinstance(other, UnsupportedSearchError):
3245N/A return True
3245N/A if self.url < other.url:
3245N/A return True
3245N/A if self.url != other.url:
3245N/A return False
3245N/A return self.proto < other.proto
3245N/A
3245N/A def __hash__(self):
3245N/A return hash((self.url, self.proto))
1191N/A
1191N/A
1191N/A# IndexingExceptions.
1191N/A
1027N/Aclass IndexingException(SearchException):
565N/A """ The base class for all exceptions that can occur while indexing. """
1027N/A
565N/A def __init__(self, private_exception):
1027N/A SearchException.__init__(self)
565N/A self.cause = private_exception.cause
565N/A
1027N/A
565N/Aclass CorruptedIndexException(IndexingException):
565N/A """This is used when the index is not in a correct state."""
2976N/A def __str__(self):
2976N/A return _("The search index appears corrupted.")
565N/A
1027N/A
1191N/Aclass InconsistentIndexException(IndexingException):
1191N/A """This is used when the existing index is found to have inconsistent
1191N/A versions."""
1191N/A def __init__(self, e):
1191N/A IndexingException.__init__(self, e)
1191N/A self.exception = e
1191N/A
1191N/A def __str__(self):
1191N/A return str(self.exception)
1191N/A
1191N/A
2028N/Aclass IndexLockedException(IndexingException):
2028N/A """This is used when an attempt to modify an index locked by another
2028N/A process or thread is made."""
2028N/A
2028N/A def __init__(self, e):
2028N/A IndexingException.__init__(self, e)
2028N/A self.exception = e
2028N/A
2028N/A def __str__(self):
2028N/A return str(self.exception)
2028N/A
2028N/A
565N/Aclass ProblematicPermissionsIndexException(IndexingException):
565N/A """ This is used when the indexer is unable to create, move, or remove
565N/A files or directories it should be able to. """
565N/A def __str__(self):
565N/A return "Could not remove or create " \
3158N/A "{0} because of incorrect " \
565N/A "permissions. Please correct this issue then " \
3158N/A "rebuild the index.".format(self.cause)
941N/A
1286N/Aclass WrapIndexingException(ApiException):
1286N/A """This exception is used to wrap an indexing exception during install,
2089N/A uninstall, or update so that a more appropriate error message can be
2089N/A displayed to the user."""
1286N/A
1286N/A def __init__(self, e, tb, stack):
1286N/A ApiException.__init__(self)
1286N/A self.wrapped = e
1286N/A self.tb = tb
1286N/A self.stack = stack
1286N/A
1286N/A def __str__(self):
1286N/A tmp = self.tb.split("\n")
1286N/A res = tmp[:1] + [s.rstrip("\n") for s in self.stack] + tmp[1:]
1286N/A return "\n".join(res)
1286N/A
1286N/A
1286N/Aclass WrapSuccessfulIndexingException(WrapIndexingException):
1286N/A """This exception is used to wrap an indexing exception during install,
2089N/A uninstall, or update which was recovered from by performing a full
2089N/A reindex."""
1286N/A pass
1286N/A
1286N/A
1191N/A# Query Parsing Exceptions
1191N/Aclass BooleanQueryException(ApiException):
1191N/A """This exception is used when the children of a boolean operation
1191N/A have different return types. The command 'pkg search foo AND <bar>'
1191N/A is the simplest example of this."""
941N/A
941N/A def __init__(self, e):
1191N/A ApiException.__init__(self)
1191N/A self.e = e
1191N/A
1191N/A def __str__(self):
1191N/A return str(self.e)
1191N/A
1191N/A
1191N/Aclass ParseError(ApiException):
1191N/A def __init__(self, e):
1191N/A ApiException.__init__(self)
941N/A self.e = e
941N/A
941N/A def __str__(self):
1027N/A return str(self.e)
1027N/A
565N/A
565N/Aclass NonLeafPackageException(ApiException):
565N/A """Removal of a package which satisfies dependencies has been attempted.
1027N/A
565N/A The first argument to the constructor is the FMRI which we tried to
565N/A remove, and is available as the "fmri" member of the exception. The
565N/A second argument is the list of dependent packages that prevent the
565N/A removal of the package, and is available as the "dependents" member.
565N/A """
565N/A
565N/A def __init__(self, *args):
565N/A ApiException.__init__(self, *args)
565N/A
565N/A self.fmri = args[0]
565N/A self.dependents = args[1]
835N/A
2976N/A def __str__(self):
3094N/A s = _("Unable to remove '{0}' due to the following packages "
3094N/A "that depend on it:\n").format(self.fmri.get_short_fmri(
3094N/A anarchy=True, include_scheme=False))
3094N/A skey = operator.attrgetter('pkg_name')
3094N/A s += "\n".join(
3094N/A " {0}".format(f.get_short_fmri(anarchy=True,
3094N/A include_scheme=False))
3094N/A for f in sorted(self.dependents, key=skey)
3094N/A )
2976N/A return s
2976N/A
3293N/A
2205N/Adef _str_autofix(self):
2205N/A
2205N/A if getattr(self, "_autofix_pkgs", []):
2205N/A s = _("\nThis is happening because the following "
2205N/A "packages needed to be repaired as\npart of this "
2205N/A "operation:\n\n ")
2205N/A s += "\n ".join(str(f) for f in self._autofix_pkgs)
2205N/A s += _("\n\nYou will need to reestablish your access to the "
2205N/A "repository or remove the\npackages in the list above.")
2205N/A return s
2205N/A return ""
2205N/A
3293N/A
835N/Aclass InvalidDepotResponseException(ApiException):
835N/A """Raised when the depot doesn't have versions of operations
835N/A that the client needs to operate successfully."""
835N/A def __init__(self, url, data):
926N/A ApiException.__init__(self)
835N/A self.url = url
835N/A self.data = data
835N/A
835N/A def __str__(self):
2205N/A s = _("Unable to contact valid package repository")
835N/A if self.url:
3158N/A s += _(": {0}").format(self.url)
835N/A if self.data:
3158N/A s += ("\nEncountered the following error(s):\n{0}").format(
3158N/A self.data)
2205N/A
2205N/A s += _str_autofix(self)
2205N/A
835N/A return s
884N/A
3293N/A
926N/Aclass DataError(ApiException):
926N/A """Base exception class used for all data related errors."""
926N/A
926N/A def __init__(self, *args, **kwargs):
926N/A ApiException.__init__(self, *args)
926N/A if args:
926N/A self.data = args[0]
926N/A else:
926N/A self.data = None
1516N/A self._args = kwargs
926N/A
926N/A
926N/Aclass InvalidP5IFile(DataError):
926N/A """Used to indicate that the specified location does not contain a
926N/A valid p5i-formatted file."""
926N/A
926N/A def __str__(self):
926N/A if self.data:
1736N/A return _("The provided p5i data is in an unrecognized "
926N/A "format or does not contain valid publisher "
3158N/A "information: {0}").format(self.data)
1736N/A return _("The provided p5i data is in an unrecognized format "
1736N/A "or does not contain valid publisher information.")
926N/A
926N/A
2310N/Aclass InvalidP5SFile(DataError):
2310N/A """Used to indicate that the specified location does not contain a
2310N/A valid p5i-formatted file."""
2310N/A
2310N/A def __str__(self):
2310N/A if self.data:
2310N/A return _("The provided p5s data is in an unrecognized "
2310N/A "format or does not contain valid publisher "
3158N/A "information: {0}").format(self.data)
2310N/A return _("The provided p5s data is in an unrecognized format "
2310N/A "or does not contain valid publisher information.")
2310N/A
2310N/A
926N/Aclass UnsupportedP5IFile(DataError):
926N/A """Used to indicate that an attempt to read an unsupported version
3356N/A of pkg(7) info file was attempted."""
926N/A
926N/A def __str__(self):
3356N/A return _("Unsupported pkg(7) publisher information data "
926N/A "format.")
926N/A
926N/A
2310N/Aclass UnsupportedP5SFile(DataError):
2310N/A """Used to indicate that an attempt to read an unsupported version
3356N/A of pkg(7) info file was attempted."""
2310N/A
2310N/A def __str__(self):
3356N/A return _("Unsupported pkg(7) publisher and image information "
2310N/A "data format.")
2310N/A
2310N/A
2310N/Aclass UnsupportedP5SVersion(ApiException):
2310N/A """Used to indicate that an attempt to read an unsupported version
3356N/A of pkg(7) info file was attempted."""
2310N/A
2310N/A def __init__(self, v):
2310N/A self.version = v
2875N/A
2310N/A def __str__(self):
3158N/A return _("{0} is not a supported version for creating a "
3158N/A "syspub response.").format(self.version)
2310N/A
2310N/A
926N/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."""
926N/A
926N/A def __str__(self):
1540N/A raise NotImplementedError()
926N/A
2205N/A def _str_autofix(self):
2205N/A return _str_autofix(self)
2205N/A
926N/A
1191N/Aclass RetrievalError(ApiException):
926N/A """Used to indicate that a a requested resource could not be
926N/A retrieved."""
926N/A
1191N/A def __init__(self, data, location=None):
1191N/A ApiException.__init__(self)
1191N/A self.data = data
1191N/A self.location = location
1191N/A
926N/A def __str__(self):
1191N/A if self.location:
926N/A return _("Error encountered while retrieving data from "
3158N/A "'{location}':\n{data}").format(
3158N/A location=self.location, data=self.data)
3158N/A return _("Error encountered while retrieving data from: {0}").format(
3158N/A self.data)
926N/A
926N/A
1191N/Aclass InvalidResourceLocation(ApiException):
926N/A """Used to indicate that an invalid transport location was provided."""
926N/A
1191N/A def __init__(self, data):
1191N/A ApiException.__init__(self)
1191N/A self.data = data
1191N/A
926N/A def __str__(self):
3158N/A return _("'{0}' is not a valid location.").format(self.data)
926N/A
941N/Aclass BEException(ApiException):
941N/A def __init__(self):
941N/A ApiException.__init__(self)
926N/A
884N/Aclass InvalidBENameException(BEException):
884N/A def __init__(self, be_name):
884N/A BEException.__init__(self)
884N/A self.be_name = be_name
884N/A
884N/A def __str__(self):
3158N/A return _("'{0}' is not a valid boot environment name.").format(
3158N/A self.be_name)
1076N/A
1076N/Aclass DuplicateBEName(BEException):
1945N/A """Used to indicate that there is an existing boot environment
1076N/A with this name"""
1076N/A
3401N/A def __init__(self, be_name, zonename=None):
1076N/A BEException.__init__(self)
1076N/A self.be_name = be_name
3401N/A self.zonename = zonename
1076N/A
1076N/A def __str__(self):
3401N/A if not self.zonename:
3401N/A return _("The boot environment '{0}' already "
3401N/A "exists.").format(self.be_name)
3401N/A d = {
3401N/A "be_name": self.be_name,
3401N/A "zonename": self.zonename
3401N/A }
3401N/A return _("The boot environment '{be_name}' already "
3401N/A "exists in zone '{zonename}'.").format(**d)
884N/A
884N/Aclass BENamingNotSupported(BEException):
884N/A def __init__(self, be_name):
884N/A BEException.__init__(self)
884N/A self.be_name = be_name
884N/A
884N/A def __str__(self):
884N/A return _("""\
884N/ABoot environment naming during package install is not supported on this
3401N/Aversion of Solaris. Please update without the --be-name option.""")
884N/A
884N/Aclass UnableToCopyBE(BEException):
884N/A def __str__(self):
884N/A return _("Unable to clone the current boot environment.")
884N/A
884N/Aclass UnableToRenameBE(BEException):
884N/A def __init__(self, orig, dest):
884N/A BEException.__init__(self)
884N/A self.original_name = orig
884N/A self.destination_name = dest
884N/A
884N/A def __str__(self):
884N/A d = {
884N/A "orig": self.original_name,
884N/A "dest": self.destination_name
884N/A }
884N/A return _("""\
884N/AA problem occurred while attempting to rename the boot environment
3158N/Acurrently named {orig} to {dest}.""").format(**d)
884N/A
884N/Aclass UnableToMountBE(BEException):
884N/A def __init__(self, be_name, be_dir):
884N/A BEException.__init__(self)
884N/A self.name = be_name
884N/A self.mountpoint = be_dir
884N/A
884N/A def __str__(self):
3158N/A return _("Unable to mount {name} at {mt}").format(
3158N/A name=self.name, mt=self.mountpoint)
884N/A
884N/Aclass BENameGivenOnDeadBE(BEException):
884N/A def __init__(self, be_name):
884N/A BEException.__init__(self)
884N/A self.name = be_name
884N/A
884N/A def __str__(self):
884N/A return _("""\
884N/ANaming a boot environment when operating on a non-live image is
884N/Anot allowed.""")
926N/A
926N/A
917N/Aclass UnrecognizedOptionsToInfo(ApiException):
917N/A def __init__(self, opts):
917N/A ApiException.__init__(self)
917N/A self._opts = opts
917N/A
917N/A def __str__(self):
917N/A s = _("Info does not recognize the following options:")
917N/A for o in self._opts:
917N/A s += _(" '") + str(o) + _("'")
917N/A return s
926N/A
941N/Aclass IncorrectIndexFileHash(ApiException):
941N/A """This is used when the index hash value doesn't match the hash of the
941N/A packages installed in the image."""
941N/A pass
941N/A
941N/A
926N/Aclass PublisherError(ApiException):
926N/A """Base exception class for all publisher exceptions."""
926N/A
926N/A def __init__(self, *args, **kwargs):
926N/A ApiException.__init__(self, *args)
926N/A if args:
926N/A self.data = args[0]
926N/A else:
926N/A self.data = None
1516N/A self._args = kwargs
926N/A
926N/A def __str__(self):
926N/A return str(self.data)
926N/A
926N/A
1087N/Aclass BadPublisherMetaRoot(PublisherError):
1087N/A """Used to indicate an operation on the publisher's meta_root failed
1087N/A because the meta_root is invalid."""
1087N/A
1087N/A def __str__(self):
3158N/A return _("Publisher meta_root '{root}' is invalid; unable "
3158N/A "to complete operation: '{op}'.").format(root=self.data,
3158N/A op=self._args.get("operation", None))
1087N/A
1087N/A
2028N/Aclass BadPublisherAlias(PublisherError):
2028N/A """Used to indicate that a publisher alias is not valid."""
2028N/A
2028N/A def __str__(self):
3158N/A return _("'{0}' is not a valid publisher alias.").format(
3158N/A self.data)
2028N/A
2028N/A
926N/Aclass BadPublisherPrefix(PublisherError):
926N/A """Used to indicate that a publisher name is not valid."""
926N/A
926N/A def __str__(self):
3158N/A return _("'{0}' is not a valid publisher name.").format(
3158N/A self.data)
926N/A
926N/A
2339N/Aclass ReservedPublisherPrefix(PublisherError):
2339N/A """Used to indicate that a publisher name is not valid."""
2339N/A
2339N/A def __str__(self):
2339N/A fmri = self._args["fmri"]
3158N/A return _("'{pkg_pub}' is a reserved publisher and does not "
3158N/A "contain the requested package: pkg:/{pkg_name}").format(
3158N/A pkg_pub=fmri.publisher, pkg_name=fmri.pkg_name)
2339N/A
2339N/A
926N/Aclass BadRepositoryAttributeValue(PublisherError):
926N/A """Used to indicate that the specified repository attribute value is
926N/A invalid."""
926N/A
926N/A def __str__(self):
3158N/A return _("'{value}' is not a valid value for repository "
3158N/A "attribute '{attribute}'.").format(
3158N/A value=self._args["value"], attribute=self.data)
926N/A
926N/A
926N/Aclass BadRepositoryCollectionType(PublisherError):
926N/A """Used to indicate that the specified repository collection type is
926N/A invalid."""
926N/A
926N/A def __init__(self, *args, **kwargs):
926N/A PublisherError.__init__(self, *args, **kwargs)
926N/A
926N/A def __str__(self):
3158N/A return _("'{0}' is not a valid repository collection type.").format(
3158N/A self.data)
926N/A
926N/A
926N/Aclass BadRepositoryURI(PublisherError):
926N/A """Used to indicate that a repository URI is not syntactically valid."""
926N/A
926N/A def __str__(self):
3158N/A return _("'{0}' is not a valid URI.").format(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."""
926N/A
926N/A def __str__(self):
3158N/A return _("'{0}' is not a valid URI priority; integer value "
3158N/A "expected.").format(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."""
926N/A
926N/A def __init__(self, *args, **kwargs):
926N/A PublisherError.__init__(self, *args, **kwargs)
926N/A
926N/A def __str__(self):
3158N/A return _("'{0}' is not a valid repository URI sort policy.").format(
3158N/A self.data)
926N/A
926N/A
926N/Aclass DisabledPublisher(PublisherError):
926N/A """Used to indicate that an attempt to use a disabled publisher occurred
926N/A during an operation."""
926N/A
926N/A def __str__(self):
3158N/A return _("Publisher '{0}' is disabled and cannot be used for "
3158N/A "packaging operations.").format(self.data)
926N/A
926N/A
926N/Aclass DuplicatePublisher(PublisherError):
926N/A """Used to indicate that a publisher with the same name or alias already
926N/A exists for an image."""
926N/A
926N/A def __str__(self):
3158N/A return _("A publisher with the same name or alias as '{0}' "
3158N/A "already exists.").format(self.data)
926N/A
926N/A
926N/Aclass DuplicateRepository(PublisherError):
926N/A """Used to indicate that a repository with the same origin uris
926N/A already exists for a publisher."""
926N/A
926N/A def __str__(self):
926N/A return _("A repository with the same name or origin URIs "
3158N/A "already exists for publisher '{0}'.").format(self.data)
926N/A
926N/A
926N/Aclass DuplicateRepositoryMirror(PublisherError):
926N/A """Used to indicate that a repository URI is already in use by another
926N/A repository mirror."""
926N/A
926N/A def __str__(self):
3158N/A return _("Mirror '{0}' already exists for the specified "
3158N/A "publisher.").format(self.data)
926N/A
926N/A
2701N/Aclass DuplicateSyspubMirror(PublisherError):
2701N/A """Used to indicate that a repository URI is already in use by the
2701N/A system publisher."""
2701N/A
2701N/A def __str__(self):
3158N/A return _("Mirror '{0}' is already accessible through the "
3158N/A "system repository.").format(self.data)
2701N/A
2701N/A
926N/Aclass DuplicateRepositoryOrigin(PublisherError):
926N/A """Used to indicate that a repository URI is already in use by another
926N/A repository origin."""
926N/A
926N/A def __str__(self):
3158N/A return _("Origin '{0}' already exists for the specified "
3158N/A "publisher.").format(self.data)
1504N/A
1504N/A
2701N/Aclass DuplicateSyspubOrigin(PublisherError):
2701N/A """Used to indicate that a repository URI is already in use by the
2701N/A system publisher."""
2701N/A
2701N/A def __str__(self):
3158N/A return _("Origin '{0}' is already accessible through the "
3158N/A "system repository.").format(self.data)
2701N/A
2701N/A
2701N/Aclass RemoveSyspubOrigin(PublisherError):
2701N/A """Used to indicate that a system publisher origin may not be
2701N/A removed."""
2701N/A
2701N/A def __str__(self):
3158N/A return _("Unable to remove origin '{0}' since it is provided "
3158N/A "by the system repository.").format(self.data)
2701N/A
2701N/Aclass RemoveSyspubMirror(PublisherError):
2701N/A """Used to indicate that a system publisher mirror may not be
2701N/A removed."""
2701N/A
2701N/A def __str__(self):
3158N/A return _("Unable to remove mirror '{0}' since it is provided "
3158N/A "by the system repository.").format(self.data)
2701N/A
2701N/A
2322N/Aclass NoPublisherRepositories(TransportError):
2219N/A """Used to indicate that a Publisher has no repository information
2219N/A configured and so transport operations cannot be performed."""
1504N/A
2322N/A def __init__(self, prefix):
2322N/A TransportError.__init__(self)
2322N/A self.publisher = prefix
2322N/A
1504N/A def __str__(self):
3167N/A return _("""
3167N/AThe requested operation requires that one or more package repositories are
3167N/Aconfigured for publisher '{0}'.
3167N/A
3167N/AUse 'pkg set-publisher' to add new package repositories or restore previously
3167N/Aconfigured package repositories for publisher '{0}'.""").format(self.publisher)
926N/A
926N/A
1505N/Aclass MoveRelativeToSelf(PublisherError):
1505N/A """Used to indicate an attempt to search a repo before or after itself"""
1505N/A
1505N/A def __str__(self):
1505N/A return _("Cannot search a repository before or after itself")
1505N/A
1505N/A
2409N/Aclass MoveRelativeToUnknown(PublisherError):
2409N/A """Used to indicate an attempt to order a publisher relative to an
2409N/A unknown publisher."""
2409N/A
2409N/A def __init__(self, unknown_pub):
2409N/A self.__unknown_pub = unknown_pub
2409N/A
2409N/A def __str__(self):
3158N/A return _("{0} is an unknown publisher; no other publishers can "
3158N/A "be ordered relative to it.").format(self.__unknown_pub)
2409N/A
2409N/A
926N/Aclass SelectedRepositoryRemoval(PublisherError):
926N/A """Used to indicate that an attempt to remove the selected repository
926N/A for a publisher was made."""
926N/A
926N/A def __str__(self):
926N/A return _("Cannot remove the selected repository for a "
926N/A "publisher.")
926N/A
926N/A
926N/Aclass UnknownLegalURI(PublisherError):
926N/A """Used to indicate that no matching legal URI could be found using the
926N/A provided criteria."""
926N/A
926N/A def __str__(self):
3158N/A return _("Unknown legal URI '{0}'.").format(self.data)
926N/A
926N/A
926N/Aclass UnknownPublisher(PublisherError):
926N/A """Used to indicate that no matching publisher could be found using the
926N/A provided criteria."""
926N/A
926N/A def __str__(self):
3158N/A return _("Unknown publisher '{0}'.").format(self.data)
926N/A
926N/A
1736N/Aclass UnknownRepositoryPublishers(PublisherError):
1736N/A """Used to indicate that one or more publisher prefixes are unknown by
1736N/A the specified repository."""
1736N/A
1736N/A def __init__(self, known=EmptyI, unknown=EmptyI, location=None,
1736N/A origins=EmptyI):
1736N/A ApiException.__init__(self)
1736N/A self.known = known
1736N/A self.location = location
1736N/A self.origins = origins
1736N/A self.unknown = unknown
1736N/A
1736N/A def __str__(self):
1736N/A if self.location:
3158N/A return _("The repository at {location} does not "
3158N/A "contain package data for {unknown}; only "
3158N/A "{known}.\n\nThis is either because the "
1736N/A "repository location is not valid, or because the "
1736N/A "provided publisher does not match those known by "
3158N/A "the repository.").format(
3158N/A unknown=", ".join(self.unknown),
3158N/A location=self.location,
3158N/A known=", ".join(self.known))
1736N/A if self.origins:
1736N/A return _("One or more of the repository origin(s) "
1736N/A "listed below contains package data for "
3158N/A "{known}; not {unknown}:\n\n{origins}\n\n"
1736N/A "This is either because one of the repository "
1736N/A "origins is not valid for this publisher, or "
1736N/A "because the list of known publishers retrieved "
1736N/A "from the repository origin does not match the "
3158N/A "client.").format(unknown=", ".join(self.unknown),
3158N/A known=", ".join(self.known),
3158N/A origins="\n".join(str(o) for o in self.origins))
1736N/A return _("The specified publisher repository does not "
3158N/A "contain any package data for {unknown}; only "
3158N/A "{known}.").format(unknown=", ".join(self.unknown),
3158N/A known=", ".join(self.known))
1736N/A
1736N/A
926N/Aclass UnknownRelatedURI(PublisherError):
926N/A """Used to indicate that no matching related URI could be found using
926N/A the provided criteria."""
926N/A
926N/A def __str__(self):
3158N/A return _("Unknown related URI '{0}'.").format(self.data)
926N/A
926N/A
926N/Aclass UnknownRepository(PublisherError):
926N/A """Used to indicate that no matching repository could be found using the
926N/A provided criteria."""
926N/A
926N/A def __str__(self):
3158N/A return _("Unknown repository '{0}'.").format(self.data)
926N/A
926N/A
926N/Aclass UnknownRepositoryMirror(PublisherError):
926N/A """Used to indicate that a repository URI could not be found in the
926N/A list of repository mirrors."""
926N/A
926N/A def __str__(self):
3158N/A return _("Unknown repository mirror '{0}'.").format(self.data)
926N/A
2316N/Aclass UnsupportedRepositoryOperation(TransportError):
1431N/A """The publisher has no active repositories that support the
1431N/A requested operation."""
1431N/A
1431N/A def __init__(self, pub, operation):
1431N/A ApiException.__init__(self)
1431N/A self.data = None
1431N/A self.kwargs = None
1431N/A self.pub = pub
1431N/A self.op = operation
1431N/A
1431N/A def __str__(self):
3158N/A return _("Publisher '{pub}' has no repositories that support "
3158N/A "the '{op}' operation.").format(**self.__dict__)
1736N/A
1736N/A
1736N/Aclass RepoPubConfigUnavailable(PublisherError):
1736N/A """Used to indicate that the specified repository does not provide
1736N/A publisher configuration information."""
1736N/A
1736N/A def __init__(self, location=None, pub=None):
1736N/A ApiException.__init__(self)
1736N/A self.location = location
1736N/A self.pub = pub
1736N/A
1736N/A def __str__(self):
1736N/A if not self.location and not self.pub:
1736N/A return _("The specified package repository does not "
1736N/A "provide publisher configuration information.")
1736N/A if self.location:
3158N/A return _("The package repository at {0} does not "
1736N/A "provide publisher configuration information or "
3158N/A "the information provided is incomplete.").format(
3158N/A self.location)
3158N/A return _("One of the package repository origins for {0} does "
1736N/A "not provide publisher configuration information or the "
3158N/A "information provided is incomplete.").format(self.pub)
1736N/A
926N/A
926N/Aclass UnknownRepositoryOrigin(PublisherError):
926N/A """Used to indicate that a repository URI could not be found in the
926N/A list of repository origins."""
926N/A
926N/A def __str__(self):
3158N/A return _("Unknown repository origin '{0}'").format(self.data)
926N/A
926N/A
926N/Aclass UnsupportedRepositoryURI(PublisherError):
926N/A """Used to indicate that the specified repository URI uses an
926N/A unsupported scheme."""
926N/A
2839N/A def __init__(self, uris=[]):
3234N/A if isinstance(uris, six.string_types):
2839N/A uris = [uris]
2839N/A
2839N/A assert isinstance(uris, (list, tuple, set))
2839N/A
2839N/A self.uris = uris
2839N/A
926N/A def __str__(self):
2839N/A illegals = []
2839N/A
2839N/A for u in self.uris:
3234N/A assert isinstance(u, six.string_types)
3234N/A scheme = urlsplit(u,
926N/A allow_fragments=0)[0]
2839N/A illegals.append((u, scheme))
2839N/A
2839N/A if len(illegals) > 1:
2839N/A msg = _("The follwing URIs use unsupported "
2839N/A "schemes. Supported schemes are "
2839N/A "file://, http://, and https://.")
2839N/A for i, s in illegals:
3158N/A msg += _("\n {uri} (scheme: "
3158N/A "{scheme})").format(uri=i, scheme=s)
2839N/A return msg
2839N/A elif len(illegals) == 1:
2839N/A i, s = illegals[0]
3158N/A return _("The URI '{uri}' uses the unsupported "
3158N/A "scheme '{scheme}'. Supported schemes are "
3158N/A "file://, http://, and https://.").format(
3158N/A uri=i, scheme=s)
2144N/A return _("The specified URI uses an unsupported scheme."
2839N/A " Supported schemes are: file://, http://, and "
2840N/A "https://.")
926N/A
926N/A
926N/Aclass UnsupportedRepositoryURIAttribute(PublisherError):
926N/A """Used to indicate that the specified repository URI attribute is not
926N/A supported for the URI's scheme."""
926N/A
926N/A def __str__(self):
3158N/A return _("'{attr}' is not supported for '{scheme}'.").format(
3158N/A attr=self.data, scheme=self._args["scheme"])
926N/A
926N/A
2701N/Aclass UnsupportedProxyURI(PublisherError):
2701N/A """Used to indicate that the specified proxy URI is unsupported."""
2701N/A
2701N/A def __str__(self):
2701N/A if self.data:
3234N/A scheme = urlsplit(self.data,
2701N/A allow_fragments=0)[0]
3158N/A return _("The proxy URI '{uri}' uses the unsupported "
3244N/A "scheme '{scheme}'. Currently the only supported "
3244N/A "scheme is http://.").format(
3158N/A uri=self.data, scheme=scheme)
2701N/A return _("The specified proxy URI uses an unsupported scheme."
3244N/A " Currently the only supported scheme is: http://.")
2701N/A
2701N/Aclass BadProxyURI(PublisherError):
2701N/A """Used to indicate that a proxy URI is not syntactically valid."""
2701N/A
2701N/A def __str__(self):
3158N/A return _("'{0}' is not a valid URI.").format(self.data)
2701N/A
2701N/A
2310N/Aclass UnknownSysrepoConfiguration(ApiException):
2310N/A """Used when a pkg client needs to communicate with the system
2310N/A repository but can't find the configuration for it."""
2310N/A
2310N/A def __str__(self):
2310N/A return _("""\
2310N/Apkg is configured to use the system repository (via the use-system-repo
2310N/Aproperty) but it could not get the host and port from
2367N/Asvc:/application/pkg/zones-proxy-client nor svc:/application/pkg/system-repository, and
2335N/Athe PKG_SYSREPO_URL environment variable was not set. Please try enabling one
2335N/Aof those services or setting the PKG_SYSREPO_URL environment variable.
2310N/A""")
2310N/A
2310N/A
2310N/Aclass ModifyingSyspubException(ApiException):
2310N/A """This exception is raised when a user attempts to modify a system
2310N/A publisher."""
2310N/A
2310N/A def __init__(self, s):
2310N/A self.s = s
2310N/A
2310N/A def __str__(self):
2310N/A return self.s
2310N/A
2310N/A
2026N/Aclass SigningException(ApiException):
2026N/A """The base class for exceptions related to manifest signing."""
2026N/A
2026N/A def __init__(self, pfmri=None, sig=None):
2026N/A self.pfmri = pfmri
2026N/A self.sig = sig
2026N/A
2026N/A # This string method is used by subclasses to fill in the details
2026N/A # about the package and signature involved.
2026N/A def __str__(self):
2026N/A if self.pfmri:
2026N/A if self.sig:
2026N/A return _("The relevant signature action is "
3158N/A "found in {pfmri} and has a hash of "
3158N/A "{hsh}").format(
3158N/A pfmri=self.pfmri, hsh=self.sig.hash)
3158N/A return _("The package involved is {0}").format(
3158N/A self.pfmri)
2026N/A if self.sig:
2026N/A return _("The relevant signature action's value "
3158N/A "attribute is {0}").format(self.sig.attrs["value"])
2026N/A return ""
2026N/A
2026N/A
2026N/Aclass BadFileFormat(SigningException):
2026N/A """Exception used when a key, certificate or CRL file is not in a
2026N/A recognized format."""
2026N/A
2026N/A def __init__(self, txt):
2026N/A self.txt = txt
2026N/A
2026N/A def __str__(self):
2026N/A return self.txt
2200N/A
2026N/A
2026N/Aclass UnsupportedSignatureVersion(SigningException):
2026N/A """Exception used when a signature reports a version which this version
3356N/A of pkg(7) doesn't support."""
2026N/A
2026N/A def __init__(self, version, *args, **kwargs):
2026N/A SigningException.__init__(self, *args, **kwargs)
2026N/A self.version = version
2026N/A
2026N/A def __str__(self):
3158N/A return _("The signature action {act} was made using a "
3356N/A "version ({ver}) this version of pkg(7) doesn't "
3158N/A "understand.").format(act=self.sig, ver=self.version)
2026N/A
2026N/A
2026N/Aclass CertificateException(SigningException):
2026N/A """Base class for exceptions encountered while establishing the chain
2026N/A of trust."""
2026N/A
2026N/A def __init__(self, cert, pfmri=None):
2026N/A SigningException.__init__(self, pfmri)
2026N/A self.cert = cert
2026N/A
2026N/A
2026N/Aclass ModifiedCertificateException(CertificateException):
2026N/A """Exception used when a certificate does not match its expected hash
2026N/A value."""
2026N/A
2026N/A def __init__(self, cert, path, pfmri=None):
2026N/A CertificateException.__init__(self, cert, pfmri)
2026N/A self.path = path
2200N/A
2026N/A def __str__(self):
3158N/A return _("Certificate {0} has been modified on disk. Its hash "
3158N/A "value is not what was expected.").format(self.path)
2026N/A
2026N/A
2026N/Aclass UntrustedSelfSignedCert(CertificateException):
2026N/A """Exception used when a chain of trust is rooted in an untrusted
2026N/A self-signed certificate."""
2026N/A
2026N/A def __str__(self):
2026N/A return _("Chain was rooted in an untrusted self-signed "
2026N/A "certificate.\n") + CertificateException.__str__(self)
2026N/A
2026N/A
2026N/Aclass BrokenChain(CertificateException):
2026N/A """Exception used when a chain of trust can not be established between
2026N/A the leaf certificate and a trust anchor."""
2026N/A
2026N/A def __init__(self, cert, cert_exceptions, *args, **kwargs):
2026N/A CertificateException.__init__(self, cert, *args, **kwargs)
2026N/A self.ext_exs = cert_exceptions
2200N/A
2026N/A def __str__(self):
2026N/A s = ""
2026N/A if self.ext_exs:
2026N/A s = _("The following problems were encountered:\n") + \
2026N/A "\n".join([str(e) for e in self.ext_exs])
2026N/A return _("The certificate which issued this "
3158N/A "certificate: {subj} could not be found. The issuer "
3321N/A "is: {issuer}\n").format(subj="/".join("{0}={1}".format(
3321N/A sub.oid._name, sub.value) for sub in self.cert.subject),
3321N/A issuer="/".join("{0}={1}".format(i.oid._name, i.value)
3321N/A for i in self.cert.issuer)) + s + "\n" + \
2026N/A CertificateException.__str__(self)
2026N/A
2026N/A
2026N/Aclass RevokedCertificate(CertificateException):
2026N/A """Exception used when a chain of trust contains a revoked certificate.
2026N/A """
2026N/A
2026N/A def __init__(self, cert, reason, *args, **kwargs):
2026N/A CertificateException.__init__(self, cert, *args, **kwargs)
2026N/A self.reason = reason
2026N/A
2026N/A def __str__(self):
3158N/A return _("This certificate was revoked:{cert} for this "
3321N/A "reason:\n{reason}\n").format(cert="/".join("{0}={1}".format(
3321N/A s.oid._name, s.value) for s in self.cert.subject),
3158N/A reason=self.reason) + CertificateException.__str__(self)
2026N/A
2026N/A
2026N/Aclass UnverifiedSignature(SigningException):
2026N/A """Exception used when a signature could not be verified by the
2026N/A expected certificate."""
2026N/A
2026N/A def __init__(self, sig, reason, pfmri=None):
2026N/A SigningException.__init__(self, pfmri)
2026N/A self.sig = sig
2026N/A self.reason = reason
2026N/A
2026N/A def __str__(self):
2026N/A if self.pfmri:
3158N/A return _("A signature in {pfmri} could not be "
2026N/A "verified for "
3158N/A "this reason:\n{reason}\nThe signature's hash is "
3158N/A "{hash}").format(pfmri=self.pfmri,
3158N/A reason=self.reason,
3158N/A hash=self.sig.hash)
2026N/A return _("The signature with this signature value:\n"
3158N/A "{sigval}\n could not be verified for this reason:\n"
3158N/A "{reason}\n").format(reason=self.reason,
3158N/A sigval=self.sig.attrs["value"])
2026N/A
2026N/A
2026N/Aclass RequiredSignaturePolicyException(SigningException):
2026N/A """Exception used when signatures were required but none were found."""
2026N/A
2026N/A def __init__(self, pub, pfmri=None):
2026N/A SigningException.__init__(self, pfmri)
2026N/A self.pub = pub
2026N/A
2026N/A def __str__(self):
2026N/A pub_str = self.pub.prefix
2026N/A if self.pfmri:
3158N/A return _("The policy for {pub_str} requires "
2026N/A "signatures to be present but no signature was "
3158N/A "found in {fmri_str}.").format(
3158N/A pub_str=pub_str, fmri_str=self.pfmri)
3158N/A return _("The policy for {pub_str} requires signatures to be "
3158N/A "present but no signature was found.").format(
3158N/A pub_str=pub_str)
2026N/A
2026N/A
2026N/Aclass MissingRequiredNamesException(SigningException):
2026N/A """Exception used when a signature policy required names to be seen
2026N/A which weren't seen."""
2026N/A
2026N/A def __init__(self, pub, missing_names, pfmri=None):
2026N/A SigningException.__init__(self, pfmri)
2026N/A self.pub = pub
2026N/A self.missing_names = missing_names
2026N/A
2026N/A def __str__(self):
2026N/A pub_str = self.pub.prefix
2026N/A if self.pfmri:
3158N/A return _("The policy for {pub_str} requires certain "
2026N/A "CNs to be seen in a chain of trust. The following "
2026N/A "required names couldn't be found for this "
3158N/A "package:{fmri_str}.\n{missing}").format(
3158N/A pub_str=pub_str, fmri_str=self.pfmri,
3158N/A missing="\n".join(self.missing_names))
3158N/A return _("The policy for {pub_str} requires certain CNs to "
2026N/A "be seen in a chain of trust. The following required names "
3158N/A "couldn't be found.\n{missing}").format(pub_str=pub_str,
3158N/A missing="\n".join(self.missing_names))
2026N/A
2026N/Aclass UnsupportedCriticalExtension(SigningException):
2026N/A """Exception used when a certificate in the chain of trust uses a
3321N/A critical extension pkg doesn't understand."""
2026N/A
2026N/A def __init__(self, cert, ext):
2026N/A SigningException.__init__(self)
2026N/A self.cert = cert
2026N/A self.ext = ext
2026N/A
2026N/A def __str__(self):
3158N/A return _("The certificate whose subject is {cert} could not "
3321N/A "be verified because it uses an unsupported critical "
3321N/A "extension.\nExtension name: {name}\nExtension "
3321N/A "value: {val}").format(cert="/".join("{0}={1}".format(
3321N/A s.oid._name, s.value) for s in self.cert.subject),
3321N/A name=self.ext.oid._name, val=self.ext.value)
2026N/A
3321N/Aclass InvalidCertificateExtensions(SigningException):
3321N/A """Exception used when a certificate in the chain of trust has
3321N/A invalid extensions."""
3321N/A
3321N/A def __init__(self, cert, error):
3321N/A SigningException.__init__(self)
3321N/A self.cert = cert
3321N/A self.error = error
3321N/A
3321N/A def __str__(self):
3321N/A s = _("The certificate whose subject is {cert} could not be "
3321N/A "verified because it has invalid extensions:\n{error}"
3321N/A ).format(cert="/".join("{0}={1}".format(
3321N/A s.oid._name, s.value) for s in self.cert.subject),
3321N/A error=self.error)
2215N/A return s
2215N/A
2215N/Aclass InappropriateCertificateUse(SigningException):
2215N/A """Exception used when a certificate in the chain of trust has been used
2215N/A inappropriately. An example would be a certificate which was only
2215N/A supposed to be used to sign code being used to sign other certificates.
2215N/A """
2215N/A
3321N/A def __init__(self, cert, ext, use, val):
2215N/A SigningException.__init__(self)
2215N/A self.cert = cert
2215N/A self.ext = ext
2215N/A self.use = use
3321N/A self.val = val
2215N/A
2215N/A def __str__(self):
3158N/A return _("The certificate whose subject is {cert} could not "
2215N/A "be verified because it has been used inappropriately. "
2215N/A "The way it is used means that the value for extension "
3158N/A "{name} must include '{use}' but the value was "
3321N/A "'{val}'.").format(cert="/".join("{0}={1}".format(
3321N/A s.oid._name, s.value) for s in self.cert.subject),
3321N/A use=self.use, name=self.ext.oid._name,
3321N/A val=self.val)
2286N/A
2286N/Aclass PathlenTooShort(InappropriateCertificateUse):
2286N/A """Exception used when a certificate in the chain of trust has been used
2286N/A inappropriately. An example would be a certificate which was only
2286N/A supposed to be used to sign code being used to sign other certificates.
2286N/A """
2286N/A
2286N/A def __init__(self, cert, actual_length, cert_length):
2286N/A SigningException.__init__(self)
2286N/A self.cert = cert
2286N/A self.al = actual_length
2286N/A self.cl = cert_length
2286N/A
2286N/A def __str__(self):
3158N/A return _("The certificate whose subject is {cert} could not "
2286N/A "be verified because it has been used inappropriately. "
3158N/A "There can only be {cl} certificates between this "
3158N/A "certificate and the leaf certificate. There are {al} "
2286N/A "certificates between this certificate and the leaf in "
3158N/A "this chain.").format(
3321N/A cert="/".join("{0}={1}".format(
3321N/A s.oid._name, s.value) for s in self.cert.subject),
3158N/A al=self.al,
3158N/A cl=self.cl
3158N/A )
2286N/A
2286N/A
2286N/Aclass AlmostIdentical(ApiException):
2286N/A """Exception used when a package already has a signature action which is
2286N/A nearly identical to the one being added but differs on some
2286N/A attributes."""
2286N/A
2286N/A def __init__(self, hsh, algorithm, version, pkg=None):
2286N/A self.hsh = hsh
2286N/A self.algorithm = algorithm
2286N/A self.version = version
2286N/A self.pkg = pkg
2286N/A
2286N/A def __str__(self):
2286N/A s = _("The signature to be added to the package has the same "
3158N/A "hash ({hash}), algorithm ({algorithm}), and "
3158N/A "version ({version}) as an existing signature, but "
2286N/A "doesn't match the signature exactly. For this signature "
3158N/A "to be added, the existing signature must be removed.").format(
3158N/A hash=self.hsh,
3158N/A algorithm=self.algorithm,
3158N/A version=self.version
3158N/A )
2286N/A if self.pkg:
3158N/A s += _("The package being signed was {pkg}").format(
3158N/A pkg=self.pkg)
2286N/A return s
2286N/A
2286N/A
2286N/Aclass DuplicateSignaturesAlreadyExist(ApiException):
2286N/A """Exception used when a package already has a signature action which is
2286N/A nearly identical to the one being added but differs on some
2286N/A attributes."""
2286N/A
2286N/A def __init__(self, pfmri):
2286N/A self.pfmri = pfmri
2286N/A
2286N/A def __str__(self):
3158N/A return _("{0} could not be signed because it already has two "
2286N/A "copies of this signature in it. One of those signature "
2286N/A "actions must be removed before the package is given to "
3158N/A "users.").format(self.pfmri)
2286N/A
2286N/A
2026N/Aclass InvalidPropertyValue(ApiException):
2026N/A """Exception used when a property was set to an invalid value."""
2026N/A
2026N/A def __init__(self, s):
2026N/A ApiException.__init__(self)
2026N/A self.str = s
2026N/A
2026N/A def __str__(self):
2026N/A return self.str
2026N/A
2026N/A
926N/Aclass CertificateError(ApiException):
926N/A """Base exception class for all certificate exceptions."""
926N/A
926N/A def __init__(self, *args, **kwargs):
926N/A ApiException.__init__(self, *args)
926N/A if args:
926N/A self.data = args[0]
926N/A else:
926N/A self.data = None
1516N/A self._args = kwargs
926N/A
926N/A def __str__(self):
926N/A return str(self.data)
926N/A
926N/A
926N/Aclass ExpiredCertificate(CertificateError):
926N/A """Used to indicate that a certificate has expired."""
926N/A
2980N/A def __init__(self, *args, **kwargs):
2980N/A CertificateError.__init__(self, *args, **kwargs)
2980N/A self.publisher = self._args.get("publisher", None)
2980N/A self.uri = self._args.get("uri", None)
2980N/A
926N/A def __str__(self):
2980N/A if self.publisher:
2980N/A if self.uri:
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}' needed to access '{uri}', "
926N/A "has expired. Please install a valid "
3158N/A "certificate.").format(cert=self.data,
3158N/A pub=self.publisher, uri=self.uri)
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}', has expired. Please install a valid "
3158N/A "certificate.").format(cert=self.data,
3158N/A pub=self.publisher)
2980N/A if self.uri:
3158N/A return _("Certificate '{cert}', needed to access "
3158N/A "'{uri}', has expired. Please install a valid "
3158N/A "certificate.").format(cert=self.data,
3158N/A uri=self.uri)
3158N/A return _("Certificate '{0}' has expired. Please install a "
3158N/A "valid certificate.").format(self.data)
926N/A
926N/A
2980N/Aclass ExpiredCertificates(CertificateError):
2980N/A """Used to collect ExpiredCertficate exceptions."""
2980N/A
2980N/A def __init__(self, errors):
3043N/A
2980N/A self.errors = []
2980N/A
2980N/A assert (isinstance(errors, (list, tuple,
2980N/A set, ExpiredCertificate)))
2980N/A
2980N/A if isinstance(errors, ExpiredCertificate):
2980N/A self.errors.append(errors)
2980N/A else:
2980N/A self.errors = errors
2980N/A
2980N/A def __str__(self):
2980N/A pdict = dict()
2980N/A for e in self.errors:
2980N/A if e.publisher in pdict:
2980N/A pdict[e.publisher].append(e.uri)
2980N/A else:
2980N/A pdict[e.publisher] = [e.uri]
2980N/A
2980N/A msg = ""
2980N/A for pub, uris in pdict.items():
3158N/A msg += "\n{0}:".format(_("Publisher"))
3158N/A msg += " {0}".format(pub)
2980N/A for uri in uris:
3158N/A msg += "\n {0}:\n".format(_("Origin URI"))
3158N/A msg += " {0}\n".format(uri)
3158N/A msg += " {0}:\n".format(_("Certificate"))
3158N/A msg += " {0}\n".format(uri.ssl_cert)
3158N/A msg += " {0}:\n".format(_("Key"))
3158N/A msg += " {0}\n".format(uri.ssl_key)
2980N/A return _("One or more client key and certificate files have "
2980N/A "expired. Please\nupdate the configuration for the "
3158N/A "publishers or origins listed below:\n {0}").format(msg)
2980N/A
2980N/A
926N/Aclass ExpiringCertificate(CertificateError):
926N/A """Used to indicate that a certificate has expired."""
926N/A
926N/A def __str__(self):
1516N/A publisher = self._args.get("publisher", None)
1516N/A uri = self._args.get("uri", None)
1516N/A days = self._args.get("days", 0)
926N/A if publisher:
926N/A if uri:
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}', needed to access '{uri}', "
3158N/A "will expire in '{days}' days.").format(
3158N/A cert=self.data, pub=publisher,
3158N/A uri=uri, days=days)
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}' will expire in '{days}' days.").format(
3158N/A cert=self.data, pub=publisher, days=days)
926N/A if uri:
3158N/A return _("Certificate '{cert}', needed to access "
3158N/A "'{uri}', will expire in '{days}' days.").format(
3158N/A cert=self.data, uri=uri, days=days)
3158N/A return _("Certificate '{cert}' will expire in "
3158N/A "'{days}' days.").format(cert=self.data, days=days)
926N/A
926N/A
926N/Aclass InvalidCertificate(CertificateError):
926N/A """Used to indicate that a certificate is invalid."""
926N/A
926N/A def __str__(self):
1516N/A publisher = self._args.get("publisher", None)
1516N/A uri = self._args.get("uri", None)
926N/A if publisher:
926N/A if uri:
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}', needed to access '{uri}', is "
3158N/A "invalid.").format(cert=self.data,
3158N/A pub=publisher, uri=uri)
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}' is invalid.").format(cert=self.data,
3158N/A pub=publisher)
926N/A if uri:
3158N/A return _("Certificate '{cert}' needed to access "
3158N/A "'{uri}' is invalid.").format(cert=self.data,
3158N/A uri=uri)
3158N/A return _("Invalid certificate '{0}'.").format(self.data)
926N/A
926N/A
1254N/Aclass NoSuchKey(CertificateError):
1254N/A """Used to indicate that a key could not be found."""
1254N/A
1254N/A def __str__(self):
1516N/A publisher = self._args.get("publisher", None)
1516N/A uri = self._args.get("uri", None)
1254N/A if publisher:
1254N/A if uri:
3158N/A return _("Unable to locate key '{key}' for "
3158N/A "publisher '{pub}' needed to access "
3158N/A "'{uri}'.").format(key=self.data,
3158N/A pub=publisher, uri=uri)
3158N/A return _("Unable to locate key '{key}' for publisher "
3158N/A "'{pub}'.").format(key=self.data, pub=publisher
3158N/A )
1254N/A if uri:
3158N/A return _("Unable to locate key '{key}' needed to "
3158N/A "access '{uri}'.").format(key=self.data,
3158N/A uri=uri)
3158N/A return _("Unable to locate key '{0}'.").format(self.data)
1254N/A
1254N/A
926N/Aclass NoSuchCertificate(CertificateError):
926N/A """Used to indicate that a certificate could not be found."""
926N/A
926N/A def __str__(self):
1516N/A publisher = self._args.get("publisher", None)
1516N/A uri = self._args.get("uri", None)
926N/A if publisher:
926N/A if uri:
926N/A return _("Unable to locate certificate "
3158N/A "'{cert}' for publisher '{pub}' needed "
3158N/A "to access '{uri}'.").format(
3158N/A cert=self.data, pub=publisher,
3158N/A uri=uri)
3158N/A return _("Unable to locate certificate '{cert}' for "
3158N/A "publisher '{pub}'.").format(cert=self.data,
3158N/A pub=publisher)
926N/A if uri:
3158N/A return _("Unable to locate certificate '{cert}' "
3158N/A "needed to access '{uri}'.").format(
3158N/A cert=self.data, uri=uri)
3158N/A return _("Unable to locate certificate '{0}'.").format(
3158N/A self.data)
926N/A
926N/A
926N/Aclass NotYetValidCertificate(CertificateError):
926N/A """Used to indicate that a certificate is not yet valid (future
926N/A effective date)."""
926N/A
926N/A def __str__(self):
1516N/A publisher = self._args.get("publisher", None)
1516N/A uri = self._args.get("uri", None)
926N/A if publisher:
926N/A if uri:
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}', needed to access '{uri}', "
3158N/A "has a future effective date.").format(
3158N/A cert=self.data, pub=publisher,
3158N/A uri=uri)
3158N/A return _("Certificate '{cert}' for publisher "
3158N/A "'{pub}' has a future effective date.").format(
3158N/A cert=self.data, pub=publisher)
926N/A if uri:
3158N/A return _("Certificate '{cert}' needed to access "
3158N/A "'{uri}' has a future effective date.").format(
3158N/A cert=self.data, uri=uri)
3158N/A return _("Certificate '{0}' has a future effective date.").format(
3158N/A self.data)
941N/A
941N/A
941N/Aclass ServerReturnError(ApiException):
2028N/A """This exception is used when the server returns a line which the
1100N/A client cannot parse correctly."""
1100N/A
941N/A def __init__(self, line):
941N/A ApiException.__init__(self)
941N/A self.line = line
941N/A
941N/A def __str__(self):
3158N/A return _("Gave a bad response:{0}").format(self.line)
1337N/A
1352N/A
1337N/Aclass MissingFileArgumentException(ApiException):
1337N/A """This exception is used when a file was given as an argument but
1337N/A no such file could be found."""
1337N/A def __init__(self, path):
1337N/A ApiException.__init__(self)
1337N/A self.path = path
1337N/A
1337N/A def __str__(self):
3158N/A return _("Could not find {0}").format(self.path)
1352N/A
1352N/A
1352N/Aclass ManifestError(ApiException):
1352N/A """Base exception class for all manifest exceptions."""
1352N/A
1352N/A def __init__(self, *args, **kwargs):
1352N/A ApiException.__init__(self, *args, **kwargs)
1352N/A if args:
1352N/A self.data = args[0]
1352N/A else:
1352N/A self.data = None
1516N/A self._args = kwargs
1352N/A
1352N/A def __str__(self):
1352N/A return str(self.data)
1352N/A
1352N/A
1352N/Aclass BadManifestSignatures(ManifestError):
1352N/A """Used to indicate that the Manifest signatures are not valid."""
1352N/A
1352N/A def __str__(self):
1352N/A if self.data:
1352N/A return _("The signature data for the manifest of the "
3158N/A "'{0}' package is not valid.").format(self.data)
1352N/A return _("The signature data for the manifest is not valid.")
1370N/A
1736N/A
1736N/Aclass UnknownErrors(ApiException):
1736N/A """Used to indicate that one or more exceptions were encountered.
1736N/A This is intended for use with where multiple exceptions for multiple
1736N/A files are encountered and the errors have been condensed into a
1736N/A single exception and re-raised. One example case would be rmtree()
1736N/A with shutil.Error."""
1736N/A
1736N/A def __init__(self, msg):
1736N/A ApiException.__init__(self)
1736N/A self.__msg = msg
1736N/A
1736N/A def __str__(self):
1736N/A return self.__msg
1736N/A
1736N/A
1370N/A# Image creation exceptions
1370N/Aclass ImageCreationException(ApiException):
1370N/A def __init__(self, path):
1736N/A ApiException.__init__(self)
1370N/A self.path = path
1370N/A
1370N/A def __str__(self):
1370N/A raise NotImplementedError()
1370N/A
1370N/A
1370N/Aclass ImageAlreadyExists(ImageCreationException):
1370N/A def __str__(self):
3158N/A return _("there is already an image at: {0}.\nTo override, use "
3158N/A "the -f (force) option.").format(self.path)
1370N/A
1370N/A
2097N/Aclass ImageCfgEmptyError(ApiException):
2097N/A """Used to indicate that the image configuration is invalid."""
2097N/A
2097N/A def __str__(self):
2144N/A return _("The configuration data for the image rooted at "
3158N/A "{0} is empty or missing.").format(self.data)
2144N/A
2144N/A
2144N/Aclass UnsupportedImageError(ApiException):
2144N/A """Used to indicate that the image at a specific location is in a format
3356N/A not supported by this version of the pkg(7) API."""
2144N/A
2144N/A def __init__(self, path):
2144N/A ApiException.__init__(self)
2144N/A self.path = path
2144N/A
2144N/A def __str__(self):
3158N/A return _("The image rooted at {0} is invalid or is not "
3158N/A "supported by this version of the packaging system.").format(
3158N/A self.path)
2097N/A
2097N/A
1370N/Aclass CreatingImageInNonEmptyDir(ImageCreationException):
1370N/A def __str__(self):
3158N/A return _("the specified image path is not empty: {0}.\nTo "
3158N/A "override, use the -f (force) option.").format(self.path)
2026N/A
2026N/A
2073N/Adef _convert_error(e, ignored_errors=EmptyI):
2073N/A """Converts the provided exception into an ApiException equivalent if
2073N/A possible. Returns a new exception object if converted or the original
2073N/A if not.
2073N/A
2073N/A 'ignored_errors' is an optional list of errno values for which None
2073N/A should be returned.
2073N/A """
2073N/A
2073N/A if not hasattr(e, "errno"):
2073N/A return e
2026N/A if e.errno in ignored_errors:
2026N/A return None
2026N/A if e.errno in (errno.EACCES, errno.EPERM):
2026N/A return PermissionsException(e.filename)
2026N/A if e.errno == errno.EROFS:
2026N/A return ReadOnlyFileSystemException(e.filename)
2026N/A return e
2339N/A
2339N/Aclass LinkedImageException(ApiException):
2339N/A
2339N/A def __init__(self, bundle=None, lin=None, exitrv=None,
2339N/A attach_bad_prop=None,
2339N/A attach_bad_prop_value=None,
2339N/A attach_child_notsup=None,
2339N/A attach_parent_notsup=None,
2339N/A attach_root_as_child=None,
3020N/A attach_with_curpath=None,
2339N/A child_bad_img=None,
2339N/A child_diverged=None,
2339N/A child_dup=None,
2339N/A child_not_in_altroot=None,
2339N/A child_not_nested=None,
3020N/A child_op_failed=None,
2339N/A child_path_notabs=None,
2339N/A child_unknown=None,
2410N/A cmd_failed=None,
3043N/A cmd_output_invalid=None,
2339N/A detach_child_notsup=None,
2339N/A detach_from_parent=None,
2339N/A detach_parent_notsup=None,
2339N/A img_linked=None,
3020N/A intermediate_image=None,
2743N/A lin_malformed=None,
3020N/A link_to_self=None,
2339N/A parent_bad_img=None,
2339N/A parent_bad_notabs=None,
2339N/A parent_bad_path=None,
3020N/A parent_nested=None,
2339N/A parent_not_in_altroot=None,
2444N/A pkg_op_failed=None,
2339N/A self_linked=None,
2690N/A self_not_child=None,
2690N/A unparsable_output=None):
2339N/A
2339N/A self.attach_bad_prop = attach_bad_prop
2339N/A self.attach_bad_prop_value = attach_bad_prop_value
2339N/A self.attach_child_notsup = attach_child_notsup
2339N/A self.attach_parent_notsup = attach_parent_notsup
2339N/A self.attach_root_as_child = attach_root_as_child
3020N/A self.attach_with_curpath = attach_with_curpath
2339N/A self.child_bad_img = child_bad_img
2339N/A self.child_diverged = child_diverged
2339N/A self.child_dup = child_dup
2339N/A self.child_not_in_altroot = child_not_in_altroot
2339N/A self.child_not_nested = child_not_nested
3020N/A self.child_op_failed = child_op_failed
2339N/A self.child_path_notabs = child_path_notabs
2339N/A self.child_unknown = child_unknown
2410N/A self.cmd_failed = cmd_failed
3043N/A self.cmd_output_invalid = cmd_output_invalid
2339N/A self.detach_child_notsup = detach_child_notsup
2339N/A self.detach_from_parent = detach_from_parent
2339N/A self.detach_parent_notsup = detach_parent_notsup
2339N/A self.img_linked = img_linked
3020N/A self.intermediate_image = intermediate_image
2339N/A self.lin_malformed = lin_malformed
2339N/A self.link_to_self = link_to_self
2339N/A self.parent_bad_img = parent_bad_img
2339N/A self.parent_bad_notabs = parent_bad_notabs
2339N/A self.parent_bad_path = parent_bad_path
3020N/A self.parent_nested = parent_nested
2339N/A self.parent_not_in_altroot = parent_not_in_altroot
2444N/A self.pkg_op_failed = pkg_op_failed
2339N/A self.self_linked = self_linked
2339N/A self.self_not_child = self_not_child
2690N/A self.unparsable_output = unparsable_output
2339N/A
2339N/A # first deal with an error bundle
2339N/A if bundle:
2339N/A assert type(bundle) in [tuple, list, set]
2339N/A for e in bundle:
2339N/A assert isinstance(e, LinkedImageException)
2339N/A
2339N/A # set default error return value
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_OOPS
2339N/A
2339N/A self.lix_err = None
2339N/A self.lix_bundle = bundle
2339N/A self.lix_exitrv = exitrv
2339N/A return
2339N/A
2339N/A err = None
2339N/A
2743N/A if attach_bad_prop is not None:
3158N/A err = _("Invalid linked image attach property: {0}").format(
3158N/A attach_bad_prop)
2339N/A
2743N/A if attach_bad_prop_value is not None:
2339N/A assert type(attach_bad_prop_value) in [tuple, list]
2339N/A assert len(attach_bad_prop_value) == 2
2339N/A err = _("Invalid linked image attach property "
3158N/A "value: {0}").format(
3158N/A "=".join(attach_bad_prop_value))
2339N/A
2743N/A if attach_child_notsup is not None:
2339N/A err = _("Linked image type does not support child "
3158N/A "attach: {0}").format(attach_child_notsup)
2339N/A
2743N/A if attach_parent_notsup is not None:
2339N/A err = _("Linked image type does not support parent "
3158N/A "attach: {0}").format(attach_parent_notsup)
2339N/A
2743N/A if attach_root_as_child is not None:
3158N/A err = _("Cannot attach root image as child: {0}".format(
3158N/A attach_root_as_child))
3020N/A
3020N/A if attach_with_curpath is not None:
3020N/A path, curpath = attach_with_curpath
3020N/A err = _("Cannot link images when an image is not at "
3020N/A "its default location. The image currently "
3158N/A "located at:\n {curpath}\n"
3158N/A "is normally located at:\n {path}\n").format(
3158N/A path=path,
3158N/A curpath=curpath,
3158N/A )
2339N/A
2743N/A if child_bad_img is not None:
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_EACCESS
2339N/A if lin:
2339N/A err = _("Can't initialize child image "
3158N/A "({lin}) at path: {path}").format(
3158N/A lin=lin,
3158N/A path=child_bad_img
3158N/A )
2339N/A else:
2339N/A err = _("Can't initialize child image "
3158N/A "at path: {0}").format(child_bad_img)
2339N/A
2743N/A if child_diverged is not None:
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_DIVERGED
3158N/A err = _("Linked image is diverged: {0}").format(
3158N/A child_diverged)
2339N/A
2743N/A if child_dup is not None:
2339N/A err = _("A linked child image with this name "
3158N/A "already exists: {0}").format(child_dup)
2339N/A
2743N/A if child_not_in_altroot is not None:
2339N/A path, altroot = child_not_in_altroot
3158N/A err = _("Child image '{path}' is not located "
3158N/A "within the parent's altroot '{altroot}'").format(
3158N/A path=path,
3158N/A altroot=altroot
3158N/A )
2339N/A
2743N/A if child_not_nested is not None:
2339N/A cpath, ppath = child_not_nested
3158N/A err = _("Child image '{cpath}' is not nested "
3158N/A "within the parent image '{ppath}'").format(
3158N/A cpath=cpath,
3158N/A ppath=ppath,
3158N/A )
2339N/A
3020N/A if child_op_failed is not None:
3020N/A op, cpath, e = child_op_failed
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_EACCESS
2339N/A if lin:
3158N/A err = _("Failed '{op}' for child image "
3158N/A "({lin}) at path: {path}: "
3158N/A "{strerror}").format(
3158N/A op=op,
3158N/A lin=lin,
3158N/A path=cpath,
3158N/A strerror=e,
3158N/A )
2339N/A else:
3158N/A err = _("Failed '{op}' for child image "
3158N/A "at path: {path}: {strerror}").format(
3158N/A op=op,
3158N/A path=cpath,
3158N/A strerror=e,
3158N/A )
2339N/A
2743N/A if child_path_notabs is not None:
3158N/A err = _("Child path not absolute: {0}").format(
3158N/A child_path_notabs)
2339N/A
2743N/A if child_unknown is not None:
3158N/A err = _("Unknown child linked image: {0}").format(
3158N/A child_unknown)
2339N/A
2743N/A if cmd_failed is not None:
2444N/A (rv, cmd, errout) = cmd_failed
2444N/A err = _("The following subprocess returned an "
3158N/A "unexpected exit code of {rv:d}:\n {cmd}").format(
3158N/A rv=rv, cmd=cmd)
3375N/A if errout:
3375N/A err += _("\nAnd generated the following error "
3375N/A "message:\n{errout}".format(errout=errout))
2410N/A
3043N/A if cmd_output_invalid is not None:
3043N/A (cmd, output) = cmd_output_invalid
3043N/A err = _(
3043N/A "The following subprocess:\n"
3158N/A " {cmd}\n"
3043N/A "Generated the following unexpected output:\n"
3158N/A "{output}\n".format(
3158N/A cmd=" ".join(cmd), output="\n".join(output)))
3043N/A
2743N/A if detach_child_notsup is not None:
2339N/A err = _("Linked image type does not support "
3158N/A "child detach: {0}").format(detach_child_notsup)
2339N/A
2743N/A if detach_from_parent is not None:
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_PARENTOP
2339N/A err = _("Parent linked to child, can not detach "
3158N/A "child: {0}").format(detach_from_parent)
2339N/A
2743N/A if detach_parent_notsup is not None:
2339N/A err = _("Linked image type does not support "
3158N/A "parent detach: {0}").format(detach_parent_notsup)
2339N/A
2743N/A if img_linked is not None:
3158N/A err = _("Image already a linked child: {0}").format(
3158N/A img_linked)
2339N/A
3020N/A if intermediate_image is not None:
3020N/A ppath, cpath, ipath = intermediate_image
3020N/A err = _(
3158N/A "Intermediate image '{ipath}' found between "
3158N/A "child '{cpath}' and "
3158N/A "parent '{ppath}'").format(
3158N/A ppath=ppath,
3158N/A cpath=cpath,
3158N/A ipath=ipath,
3158N/A )
3020N/A
2743N/A if lin_malformed is not None:
3158N/A err = _("Invalid linked image name '{0}'. "
2823N/A "Linked image names have the following format "
3158N/A "'<linked_image plugin>:<linked_image name>'").format(
3158N/A lin_malformed)
2339N/A
3020N/A if link_to_self is not None:
3158N/A err = _("Can't link image to itself: {0}")
2339N/A
2743N/A if parent_bad_img is not None:
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_EACCESS
3158N/A err = _("Can't initialize parent image at path: {0}").format(
3158N/A parent_bad_img)
2339N/A
2743N/A if parent_bad_notabs is not None:
3158N/A err = _("Parent path not absolute: {0}").format(
3158N/A parent_bad_notabs)
2339N/A
2743N/A if parent_bad_path is not None:
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_EACCESS
3158N/A err = _("Can't access parent image at path: {0}").format(
3158N/A parent_bad_path)
2339N/A
3020N/A if parent_nested is not None:
3020N/A ppath, cpath = parent_nested
3158N/A err = _("A parent image '{ppath}' can not be nested "
3158N/A "within a child image '{cpath}'").format(
3158N/A ppath=ppath,
3158N/A cpath=cpath,
3158N/A )
3020N/A
2743N/A if parent_not_in_altroot is not None:
2339N/A path, altroot = parent_not_in_altroot
3158N/A err = _("Parent image '{path}' is not located "
3158N/A "within the child's altroot '{altroot}'").format(
3158N/A path=path,
3158N/A altroot=altroot
3158N/A )
2339N/A
2743N/A if pkg_op_failed is not None:
2444N/A assert lin
2690N/A (op, exitrv, errout, e) = pkg_op_failed
2743N/A assert op is not None
2690N/A
2690N/A if e is None:
2690N/A err = _("""
3158N/AA '{op}' operation failed for child '{lin}' with an unexpected
3158N/Areturn value of {exitrv:d} and generated the following output:
3158N/A{errout}
2444N/A
2444N/A"""
3158N/A ).format(
3158N/A lin=lin,
3158N/A op=op,
3158N/A exitrv=exitrv,
3158N/A errout=errout,
3158N/A )
2690N/A else:
2690N/A err = _("""
3158N/AA '{op}' operation failed for child '{lin}' with an unexpected
2690N/Aexception:
3158N/A{e}
2690N/A
2690N/AThe child generated the following output:
3158N/A{errout}
2690N/A
2690N/A"""
3158N/A ).format(
3158N/A lin=lin,
3158N/A op=op,
3158N/A errout=errout,
3158N/A e=e,
3158N/A )
2444N/A
2743N/A if self_linked is not None:
3158N/A err = _("Current image already a linked child: {0}").format(
3158N/A self_linked)
2339N/A
2743N/A if self_not_child is not None:
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_NOPARENT
3158N/A err = _("Current image is not a linked child: {0}").format(
3158N/A self_not_child)
2339N/A
2743N/A if unparsable_output is not None:
2690N/A (op, errout, e) = unparsable_output
2690N/A err = _("""
3158N/AA '{op}' operation for child '{lin}' generated non-json output.
2690N/AThe json parser failed with the following error:
3158N/A{e}
2690N/A
2690N/AThe child generated the following output:
3158N/A{errout}
2690N/A
2690N/A"""
3158N/A ).format(
3158N/A lin=lin,
3158N/A op=op,
3158N/A e=e,
3158N/A errout=errout,
3158N/A )
2690N/A
2339N/A # set default error return value
2339N/A if exitrv == None:
2339N/A exitrv = pkgdefs.EXIT_OOPS
2339N/A
2339N/A self.lix_err = err
2339N/A self.lix_bundle = None
2339N/A self.lix_exitrv = exitrv
2339N/A
2339N/A def __str__(self):
2339N/A assert self.lix_err or self.lix_bundle
2339N/A assert not (self.lix_err and self.lix_bundle), \
3158N/A "self.lix_err = {0}, self.lix_bundle = {1}".format(
3158N/A str(self.lix_err), str(self.lix_bundle))
2339N/A
2339N/A # single error
2339N/A if self.lix_err:
2339N/A return self.lix_err
2339N/A
2339N/A # concatenate multiple errors
2339N/A bundle_str = []
2339N/A for e in self.lix_bundle:
2339N/A bundle_str.append(str(e))
2339N/A return "\n".join(bundle_str)
2452N/A
2452N/A
2452N/Aclass FreezePkgsException(ApiException):
2452N/A """Used if an argument to pkg freeze isn't valid."""
2452N/A
2452N/A def __init__(self, multiversions=None, unmatched_wildcards=None,
2452N/A version_mismatch=None, versionless_uninstalled=None):
2452N/A ApiException.__init__(self)
2452N/A self.multiversions = multiversions
2452N/A self.unmatched_wildcards = unmatched_wildcards
2452N/A self.version_mismatch = version_mismatch
2452N/A self.versionless_uninstalled = versionless_uninstalled
2452N/A
2452N/A def __str__(self):
2452N/A res = []
2452N/A if self.multiversions:
2452N/A s = _("""\
2452N/AThe following packages were frozen at two different versions by
2452N/Athe patterns provided. The package stem and the versions it was frozen at are
2452N/Aprovided:""")
2452N/A res += [s]
3158N/A res += ["\t{0}\t{1}".format(stem, " ".join([
3339N/A str(v) for v in sorted(versions)]))
2452N/A for stem, versions in sorted(self.multiversions)]
2452N/A
2452N/A if self.unmatched_wildcards:
2452N/A s = _("""\
2452N/AThe following patterns contained wildcards but matched no
2452N/Ainstalled packages.""")
2452N/A res += [s]
3158N/A res += ["\t{0}".format(pat) for pat in sorted(
2452N/A self.unmatched_wildcards)]
2452N/A
2452N/A if self.version_mismatch:
2452N/A s = _("""\
2452N/AThe following patterns attempted to freeze the listed packages
2452N/Aat a version different from the version at which the packages are installed.""")
2452N/A res += [s]
2452N/A for pat in sorted(self.version_mismatch):
3158N/A res += ["\t{0}".format(pat)]
2452N/A if len(self.version_mismatch[pat]) > 1:
2452N/A res += [
3158N/A "\t\t{0}".format(stem)
2452N/A for stem
3339N/A in sorted(self.version_mismatch[pat])
2452N/A ]
2452N/A
2452N/A if self.versionless_uninstalled:
2452N/A s = _("""\
2452N/AThe following patterns don't match installed packages and
2452N/Acontain no version information. Uninstalled packages can only be frozen by
2452N/Aproviding a version at which to freeze them.""")
2452N/A res += [s]
3158N/A res += ["\t{0}".format(p) for p in sorted(
2452N/A self.versionless_uninstalled)]
2452N/A return "\n".join(res)
2452N/A
2452N/Aclass InvalidFreezeFile(ApiException):
2452N/A """Used to indicate the freeze state file could not be loaded."""
2452N/A
2452N/A def __str__(self):
3158N/A return _("The freeze state file '{0}' is invalid.").format(
3158N/A self.data)
2452N/A
2452N/Aclass UnknownFreezeFileVersion(ApiException):
2452N/A """Used when the version on the freeze state file isn't the version
2452N/A that's expected."""
2452N/A
2452N/A def __init__(self, found_ver, expected_ver, location):
2452N/A self.found = found_ver
2452N/A self.expected = expected_ver
2452N/A self.loc = location
2452N/A
2452N/A def __str__(self):
3158N/A return _("The freeze state file '{loc}' was expected to have "
3158N/A "a version of {exp}, but its version was {found}").format(
3158N/A exp=self.expected,
3158N/A found=self.found,
3158N/A loc=self.loc,
3158N/A )
2839N/A
2839N/Aclass InvalidOptionError(ApiException):
2839N/A """Used to indicate an issue with verifying options passed to a certain
2839N/A operation."""
2839N/A
3185N/A GENERIC = "generic" # generic option violation
3185N/A OPT_REPEAT = "opt_repeat" # option repetition is not allowed
3185N/A ARG_REPEAT = "arg_repeat" # argument repetition is not allowed
3185N/A ARG_INVALID = "arg_invalid" # argument is invalid
3185N/A INCOMPAT = "incompat" # option 'a' can not be specified with option 'b'
3185N/A REQUIRED = "required" # option 'a' requires option 'b'
3185N/A REQUIRED_ANY = "required_any" # option 'a' requires option 'b', 'c' or more
3185N/A XOR = "xor" # either option 'a' or option 'b' must be specified
3185N/A
3185N/A def __init__(self, err_type=GENERIC, options=[], msg=None,
3185N/A valid_args=[]):
2839N/A
2839N/A self.err_type = err_type
2839N/A self.options = options
2839N/A self.msg = msg
3185N/A self.valid_args = valid_args
2839N/A
2839N/A def __str__(self):
2839N/A
2839N/A # In case the user provided a custom message we just take it and
2839N/A # append the according options.
2839N/A if self.msg is not None:
2839N/A if self.options:
2839N/A self.msg += ": "
2839N/A self.msg += " ".join(self.options)
2839N/A return self.msg
2839N/A
2980N/A if self.err_type == self.OPT_REPEAT:
2839N/A assert len(self.options) == 1
3158N/A return _("Option '{option}' may not be repeated.").format(
3158N/A option=self.options[0])
2875N/A elif self.err_type == self.ARG_REPEAT:
2875N/A assert len(self.options) == 2
3158N/A return _("Argument '{op1}' for option '{op2}' may "
3158N/A "not be repeated.").format(op1=self.options[0],
3158N/A op2=self.options[1])
3031N/A elif self.err_type == self.ARG_INVALID:
3031N/A assert len(self.options) == 2
3185N/A s = _("Argument '{op1}' for option '{op2}' is "
3158N/A "invalid.").format(op1=self.options[0],
3158N/A op2=self.options[1])
3185N/A if self.valid_args:
3185N/A s += _("\nSupported: {0}").format(", ".join(
3336N/A [str(va) for va in self.valid_args]))
3185N/A return s
2839N/A elif self.err_type == self.INCOMPAT:
2839N/A assert len(self.options) == 2
3158N/A return _("The '{op1}' and '{op2}' option may "
3158N/A "not be combined.").format(op1=self.options[0],
3158N/A op2=self.options[1])
2839N/A elif self.err_type == self.REQUIRED:
2839N/A assert len(self.options) == 2
3158N/A return _("'{op1}' may only be used with "
3158N/A "'{op2}'.").format(op1=self.options[0],
3158N/A op2=self.options[1])
3185N/A elif self.err_type == self.REQUIRED_ANY:
3185N/A assert len(self.options) > 2
3185N/A return _("'{op1}' may only be used with "
3185N/A "'{op2}' or {op3}.").format(op1=self.options[0],
3185N/A op2=", ".join(self.options[1:-1]),
3185N/A op3=self.options[-1])
2839N/A elif self.err_type == self.XOR:
2839N/A assert len(self.options) == 2
3158N/A return _("Either '{op1}' or '{op2}' must be "
3158N/A "specified").format(op1=self.options[0],
3158N/A op2=self.options[1])
2839N/A else:
2839N/A return _("invalid option(s): ") + " ".join(self.options)
2839N/A
2839N/Aclass InvalidOptionErrors(ApiException):
2839N/A
2839N/A def __init__(self, errors):
2839N/A
2839N/A self.errors = []
2839N/A
2839N/A assert (isinstance(errors, list) or isinstance(errors, tuple) or
2839N/A isinstance(errors, set) or
2839N/A isinstance(errors, InvalidOptionError))
2839N/A
2839N/A if isinstance(errors, InvalidOptionError):
2839N/A self.errors.append(errors)
2839N/A else:
2839N/A self.errors = errors
2839N/A
2839N/A def __str__(self):
2839N/A msgs = []
2839N/A for e in self.errors:
2839N/A msgs.append(str(e))
2839N/A return "\n".join(msgs)
2840N/A
3065N/Aclass UnexpectedLinkError(ApiException):
3065N/A """Used to indicate that an image state file has been replaced
3065N/A with a symlink."""
3065N/A
3065N/A def __init__(self, path, filename, errno):
3065N/A self.path = path
3065N/A self.filename = filename
3065N/A self.errno = errno
3065N/A
3065N/A def __str__(self):
3195N/A return _("Cannot update file: '{file}' at path "
3195N/A "'{path}', contains a symlink. "
3195N/A "[Error '{errno:d}': '{error}']").format(
3195N/A error=os.strerror(self.errno),
3195N/A errno=self.errno,
3195N/A path=self.path,
3195N/A file=self.filename,
3195N/A )
3195N/A
3195N/A
3195N/Aclass InvalidConfigFile(ApiException):
3195N/A """Used to indicate that a configuration file is invalid
3195N/A or broken"""
3195N/A
3195N/A def __init__(self, path):
3195N/A self.path = path
3195N/A
3195N/A def __str__(self):
3195N/A return _("Cannot parse configuration file "
3195N/A "{path}'.").format(path=self.path)
3339N/A
3339N/A
3339N/Aclass PkgUnicodeDecodeError(UnicodeDecodeError):
3339N/A def __init__(self, obj, *args):
3339N/A self.obj = obj
3339N/A UnicodeDecodeError.__init__(self, *args)
3339N/A
3339N/A def __str__(self):
3339N/A s = UnicodeDecodeError.__str__(self)
3339N/A return "{0}. You passed in {1!r} {2}".format(s, self.obj,
3339N/A type(self.obj))
3339N/A
3418N/Aclass UnsupportedVariantGlobbing(ApiException):
3418N/A """Used to indicate that globbing for variant is not supported."""
3418N/A
3418N/A def __str__(self):
3418N/A return _("Globbing is not supported for variants.")