api_errors.py revision 941
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#!/usr/bin/python2.4
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# CDDL HEADER START
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# The contents of this file are subject to the terms of the
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# Common Development and Distribution License (the "License").
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# You may not use this file except in compliance with the License.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# or http://www.opensolaris.org/os/licensing.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# See the License for the specific language governing permissions
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# and limitations under the License.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# When distributing Covered Code, include this CDDL HEADER in each
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# If applicable, add the following below this CDDL HEADER, with the
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# fields enclosed by brackets "[]" replaced with your own identifying
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# information: Portions Copyright [yyyy] [name of copyright owner]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# CDDL HEADER END
250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77Stéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
7f95145833bb24f54e037f73ecc37444d6635697Dwight Engen# Use is subject to license terms.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber#
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberimport socket
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberimport urllib2
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberimport urlparse
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# EmptyI for argument defaults; can't import from misc due to circular
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber# dependency.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane GraberEmptyI = tuple()
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass ApiException(Exception):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass ImageNotFoundException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber """Used when an image was not found"""
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, user_specified, user_dir, root_dir):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.user_specified = user_specified
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.user_dir = user_dir
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.root_dir = root_dir
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass NetworkUnavailableException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, caught_exception):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.ex = caught_exception
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __str__(self):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return str(self.ex)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass VersionException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, expected_version, received_version):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.expected_version = expected_version
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.received_version = received_version
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass PlanExistsException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, plan_type):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.plan_type = plan_type
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass PrematureExecutionException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass AlreadyPreparedException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass AlreadyExecutedException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass ImageplanStateException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, state):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.state = state
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass IpkgOutOfDateException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass ImageUpdateOnLiveImageException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass CanceledException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass PlanMissingException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass NoPackagesInstalledException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass PermissionsException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, path):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.path = path
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __str__(self):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber if self.path:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return _("Could not operate on %s\nbecause of "
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "insufficient permissions. Please try the command "
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "again using pfexec\nor otherwise increase your "
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "privileges.") % self.path
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber else:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return _("""
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane GraberCould not complete the operation because of insufficient permissions. Please
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Grabertry the command again using pfexec or otherwise increase your privileges.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber""")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass FileInUseException(PermissionsException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, path):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber PermissionsException.__init__(self, path)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber assert path
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __str__(self):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return _("Could not operate on %s\nbecause the file is "
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "in use. Please stop using the file and try the\n"
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "operation again.") % self.path
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass PlanCreationException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, unfound_fmris=EmptyI, multiple_matches=EmptyI,
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber missing_matches=EmptyI, illegal=EmptyI,
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber constraint_violations=EmptyI, badarch=EmptyI):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.unfound_fmris = unfound_fmris
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.multiple_matches = multiple_matches
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.missing_matches = missing_matches
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.illegal = illegal
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.constraint_violations = constraint_violations
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.badarch = badarch
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __str__(self):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res = []
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber if self.unfound_fmris:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber s = _("""\
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberpkg: The following pattern(s) did not match any packages in the current
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Grabercatalog. Try relaxing the pattern, refreshing and/or examining the catalogs""")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += [s]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += ["\t%s" % p for p in self.unfound_fmris]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber if self.multiple_matches:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber s = _("pkg: '%s' matches multiple packages")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber for p, lst in self.multiple_matches:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res.append(s % p)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber for pfmri in lst:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res.append("\t%s" % pfmri)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber s = _("pkg: '%s' matches no installed packages")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += [ s % p for p in self.missing_matches ]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber s = _("pkg: '%s' is an illegal fmri")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += [ s % p for p in self.illegal ]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber if self.constraint_violations:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber s = _("pkg: the following package(s) violated "
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "constraints:")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += [s]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += ["\t%s" % p for p in self.constraint_violations]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber if self.badarch:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber s = _("'%s' supports the following architectures: %s")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber a = _("Image architecture is defined as: %s")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += [ s % (self.badarch[0],
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ", ".join(self.badarch[1]))]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber res += [ a % (self.badarch[2])]
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return '\n'.join(res)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass CatalogRefreshException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, failed, total, succeeded, message=None):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.failed = failed
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.total = total
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.succeeded = succeeded
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.message = message
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass InventoryException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, notfound=EmptyI, illegal=EmptyI):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.notfound = notfound
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.illegal = illegal
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber assert(self.notfound or self.illegal)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __str__(self):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber outstr = ""
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber for x in self.illegal:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber # Illegal FMRIs have their own __str__ method
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber outstr += "%s\n" % x
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber if self.notfound:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber outstr += _("No matching package could be found for "
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "the following FMRIs in any of the catalogs for "
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "the current publishers:\n")
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber for x in self.notfound:
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber outstr += "%s\n" % x
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return outstr
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass IndexingException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber """ The base class for all exceptions that can occur while indexing. """
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, private_exception):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.cause = private_exception.cause
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass CorruptedIndexException(IndexingException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber """This is used when the index is not in a correct state."""
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber pass
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass ProblematicPermissionsIndexException(IndexingException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber """ This is used when the indexer is unable to create, move, or remove
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber files or directories it should be able to. """
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __str__(self):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return "Could not remove or create " \
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "%s because of incorrect " \
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "permissions. Please correct this issue then " \
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber "rebuild the index." % self.cause
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass MainDictParsingException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber """This is used when the main dictionary could not parse a line."""
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __init__(self, e):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber ApiException.__init__(self)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber self.e = e
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber def __str__(self):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber return str(e)
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graberclass NonLeafPackageException(ApiException):
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber """Removal of a package which satisfies dependencies has been attempted.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber The first argument to the constructor is the FMRI which we tried to
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber remove, and is available as the "fmri" member of the exception. The
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber second argument is the list of dependent packages that prevent the
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber removal of the package, and is available as the "dependents" member.
4019712d198a7d50b08b326ade17f5ff1666efbbStéphane Graber """
def __init__(self, *args):
ApiException.__init__(self, *args)
self.fmri = args[0]
self.dependents = args[1]
class InvalidDepotResponseException(ApiException):
"""Raised when the depot doesn't have versions of operations
that the client needs to operate successfully."""
def __init__(self, url, data):
ApiException.__init__(self)
self.url = url
self.data = data
def __str__(self):
s = "Unable to contact valid package server"
if self.url:
s += ": %s" % self.url
if self.data:
s += "\nEncountered the following error(s):\n%s" % \
self.data
return s
class DataError(ApiException):
"""Base exception class used for all data related errors."""
def __init__(self, *args, **kwargs):
ApiException.__init__(self, *args)
if args:
self.data = args[0]
else:
self.data = None
self.args = kwargs
class InvalidP5IFile(DataError):
"""Used to indicate that the specified location does not contain a
valid p5i-formatted file."""
def __str__(self):
if self.data:
return _("The specified file is in an unrecognized "
"format or does not contain valid publisher "
"information: %s") % self.data
return _("The specified file is in an unrecognized format or "
"does not contain valid publisher information.")
class UnsupportedP5IFile(DataError):
"""Used to indicate that an attempt to read an unsupported version
of pkg(5) info file was attempted."""
def __str__(self):
return _("Unsupported pkg(5) publisher information data "
"format.")
class TransportError(ApiException):
"""Base exception class for all transfer exceptions."""
def __init__(self, *args, **kwargs):
ApiException.__init__(self, *args)
if args:
self.data = args[0]
else:
self.data = None
self.args = kwargs
def __str__(self):
return str(self.data)
class RetrievalError(TransportError):
"""Used to indicate that a a requested resource could not be
retrieved."""
def __str__(self):
location = self.args.get("location", None)
if location:
return _("Error encountered while retrieving data from "
"'%s':\n%s") % (location, self.data)
return _("Error encountered while retrieving data from: %s") % \
self.data
class InvalidResourceLocation(TransportError):
"""Used to indicate that an invalid transport location was provided."""
def __str__(self):
return _("'%s' is not a valid location.") % self.data
class BEException(ApiException):
def __init__(self):
ApiException.__init__(self)
class InvalidBENameException(BEException):
def __init__(self, be_name):
BEException.__init__(self)
self.be_name = be_name
def __str__(self):
return _("'%s' is not a valid boot envirnment name." %
self.be_name)
class BENamingNotSupported(BEException):
def __init__(self, be_name):
BEException.__init__(self)
self.be_name = be_name
def __str__(self):
return _("""\
Boot environment naming during package install is not supported on this
version of OpenSolaris. Please image-update without the --be-name option.""")
class UnableToCopyBE(BEException):
def __str__(self):
return _("Unable to clone the current boot environment.")
class UnableToRenameBE(BEException):
def __init__(self, orig, dest):
BEException.__init__(self)
self.original_name = orig
self.destination_name = dest
def __str__(self):
d = {
"orig": self.original_name,
"dest": self.destination_name
}
return _("""\
A problem occurred while attempting to rename the boot environment
currently named %(orig)s to %(dest)s.""") % d
class UnableToMountBE(BEException):
def __init__(self, be_name, be_dir):
BEException.__init__(self)
self.name = be_name
self.mountpoint = be_dir
def __str__(self):
return _("Unable to mount %(name)s at %(mt)s") % \
{"name": self.name, "mt": self.mountpoint}
class BENameGivenOnDeadBE(BEException):
def __init__(self, be_name):
BEException.__init__(self)
self.name = be_name
def __str__(self):
return _("""\
Naming a boot environment when operating on a non-live image is
not allowed.""")
class UnrecognizedOptionsToInfo(ApiException):
def __init__(self, opts):
ApiException.__init__(self)
self._opts = opts
def __str__(self):
s = _("Info does not recognize the following options:")
for o in self._opts:
s += _(" '") + str(o) + _("'")
return s
class ProblematicSearchServers(ApiException):
def __init__(self, failed, invalid):
self.failed_servers = failed
self.invalid_servers = invalid
def __str__(self):
s = _("Some servers failed to respond appropriately:\n")
for pub, err in self.failed_servers:
if isinstance(err, urllib2.HTTPError):
s += _(" %(o)s: %(msg)s (%(code)d)\n" % \
{ 'o':pub["origin"], 'msg':err.msg,
'code':err.code })
elif isinstance(err, urllib2.URLError):
if isinstance(err.args[0], socket.timeout):
s += _(" %(o)s: %(to)s\n" % \
{ 'o':pub["origin"],
'to':"timeout" })
else:
s += _(" %(o)s: %(other)s\n" % \
{ 'o':pub["origin"],
'other':err.args[0][1] })
elif isinstance(err, RuntimeError):
s += _(" %(o)s: %(msg)s\n" % \
{ 'o':pub["origin"], 'msg':str(err)})
else:
s += "FOO" + str(err)
for pub in self.invalid_servers:
s += _("%s appears not to be a valid package depot.\n" \
% pub['origin'])
return s
class IncorrectIndexFileHash(ApiException):
"""This is used when the index hash value doesn't match the hash of the
packages installed in the image."""
pass
class InconsistentIndexException(ApiException):
"""This is used when the existing index is found to have inconsistent
versions."""
def __init__(self, e):
self.exception = e
def __str__(self):
return str(self.exception)
class SlowSearchUsed(ApiException):
def __str__(self):
return _("Search capabilities and performance are degraded.\n"
"To improve, run 'pkg rebuild-index'.")
class BooleanQueryException(ApiException):
def __init__(self, ac, pc):
ApiException.__init__(self)
self.action_child = ac
self.package_child = pc
def __str__(self):
ac_s = _("This expression produces action results:\n")
ac_q = "%s\n" % self.action_child
pc_s = _("This expression produces package results:\n")
pc_q = "%s\n" % self.package_child
s = _("%(ac_s)s%(ac_q)s%(pc_s)s%(pc_q)s'AND' and 'OR' require "
"those expressions to produce the same type of results.") \
% { "ac_s" : ac_s, "ac_q" : ac_q, "pc_s" : pc_s,
"pc_q" : pc_q }
return s
class PublisherError(ApiException):
"""Base exception class for all publisher exceptions."""
def __init__(self, *args, **kwargs):
ApiException.__init__(self, *args)
if args:
self.data = args[0]
else:
self.data = None
self.args = kwargs
def __str__(self):
return str(self.data)
class BadPublisherPrefix(PublisherError):
"""Used to indicate that a publisher name is not valid."""
def __str__(self):
return _("'%s' is not a valid publisher name.") % self.data
class BadRepositoryAttributeValue(PublisherError):
"""Used to indicate that the specified repository attribute value is
invalid."""
def __str__(self):
return _("'%(value)s' is not a valid value for repository "
"attribute '%(attribute)s'.") % {
"value": self.args["value"], "attribute": self.data }
class BadRepositoryCollectionType(PublisherError):
"""Used to indicate that the specified repository collection type is
invalid."""
def __init__(self, *args, **kwargs):
PublisherError.__init__(self, *args, **kwargs)
def __str__(self):
return _("'%s' is not a valid repository collection type.") % \
self.data
class BadRepositoryURI(PublisherError):
"""Used to indicate that a repository URI is not syntactically valid."""
def __str__(self):
return _("'%s' is not a valid URI.") % self.data
class BadRepositoryURIPriority(PublisherError):
"""Used to indicate that the priority specified for a repository URI is
not valid."""
def __str__(self):
return _("'%s' is not a valid URI priority; integer value "
"expected.") % self.data
class BadRepositoryURISortPolicy(PublisherError):
"""Used to indicate that the specified repository URI sort policy is
invalid."""
def __init__(self, *args, **kwargs):
PublisherError.__init__(self, *args, **kwargs)
def __str__(self):
return _("'%s' is not a valid repository URI sort policy.") % \
self.data
class DisabledPublisher(PublisherError):
"""Used to indicate that an attempt to use a disabled publisher occurred
during an operation."""
def __str__(self):
return _("Publisher '%s' is disabled and cannot be used for "
"packaging operations.") % self.data
class DuplicatePublisher(PublisherError):
"""Used to indicate that a publisher with the same name or alias already
exists for an image."""
def __str__(self):
return _("A publisher with the same name or alias as '%s' "
"already exists.") % self.data
class DuplicateRepository(PublisherError):
"""Used to indicate that a repository with the same origin uris
already exists for a publisher."""
def __str__(self):
return _("A repository with the same name or origin URIs "
"already exists for publisher '%s'.") % self.data
class DuplicateRepositoryMirror(PublisherError):
"""Used to indicate that a repository URI is already in use by another
repository mirror."""
def __str__(self):
return _("Mirror '%s' already exists for the specified "
"repository.") % self.data
class DuplicateRepositoryOrigin(PublisherError):
"""Used to indicate that a repository URI is already in use by another
repository origin."""
def __str__(self):
return _("Origin '%s' already exists for the specified "
"repository.") % self.data
class RemovePreferredPublisher(PublisherError):
"""Used to indicate an attempt to remove the preferred publisher was
made."""
def __str__(self):
return _("The preferred publisher cannot be removed.")
class SelectedRepositoryRemoval(PublisherError):
"""Used to indicate that an attempt to remove the selected repository
for a publisher was made."""
def __str__(self):
return _("Cannot remove the selected repository for a "
"publisher.")
class SetPreferredPublisherDisabled(PublisherError):
"""Used to indicate an attempt to set a disabled publisher as the
preferred publisher was made."""
def __str__(self):
return _("Publisher '%(pub)s' is disabled and cannot be set as "
"the preferred publisher.") % self.data
class UnknownLegalURI(PublisherError):
"""Used to indicate that no matching legal URI could be found using the
provided criteria."""
def __str__(self):
return _("Unknown legal URI '%s'.") % self.data
class UnknownPublisher(PublisherError):
"""Used to indicate that no matching publisher could be found using the
provided criteria."""
def __str__(self):
return _("Unknown publisher '%s'.") % self.data
class UnknownRelatedURI(PublisherError):
"""Used to indicate that no matching related URI could be found using
the provided criteria."""
def __str__(self):
return _("Unknown related URI '%s'.") % self.data
class UnknownRepository(PublisherError):
"""Used to indicate that no matching repository could be found using the
provided criteria."""
def __str__(self):
return _("Unknown repository '%s'.") % self.data
class UnknownRepositoryMirror(PublisherError):
"""Used to indicate that a repository URI could not be found in the
list of repository mirrors."""
def __str__(self):
return _("Unknown repository mirror '%s'.") % self.data
class UnknownRepositoryOrigin(PublisherError):
"""Used to indicate that a repository URI could not be found in the
list of repository origins."""
def __str__(self):
return _("Unknown repository origin '%s'") % self.data
class UnsupportedRepositoryURI(PublisherError):
"""Used to indicate that the specified repository URI uses an
unsupported scheme."""
def __str__(self):
if self.data:
scheme = urlparse.urlsplit(self.data,
allow_fragments=0)[0]
return _("The URI '%(uri)s' contains an unsupported "
"scheme '%(scheme)s'.") % { "uri": self.data,
"scheme": scheme }
return _("The specified URI contains an unsupported scheme.")
class UnsupportedRepositoryURIAttribute(PublisherError):
"""Used to indicate that the specified repository URI attribute is not
supported for the URI's scheme."""
def __str__(self):
return _("'%(attr)s' is not supported for '%(scheme)s'.") % {
"attr": self.data, "scheme": self.args["scheme"] }
class CertificateError(ApiException):
"""Base exception class for all certificate exceptions."""
def __init__(self, *args, **kwargs):
ApiException.__init__(self, *args)
if args:
self.data = args[0]
else:
self.data = None
self.args = kwargs
def __str__(self):
return str(self.data)
class ExpiredCertificate(CertificateError):
"""Used to indicate that a certificate has expired."""
def __str__(self):
publisher = self.args.get("publisher", None)
uri = self.args.get("uri", None)
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s' needed to access '%(uri)s', "
"has expired. Please install a valid "
"certificate.") % { "cert": self.data,
"uri": uri }
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', has expired. Please install a valid "
"certificate.") % { "cert": self.data,
"pub": publisher }
if uri:
return _("Certificate '%(cert)s', needed to access "
"'%(uri)s', has expired. Please install a valid "
"certificate.") % { "cert": self.data, "uri": uri }
return _("Certificate '%s' has expired. Please install a "
"valid certificate.") % self.data
class ExpiringCertificate(CertificateError):
"""Used to indicate that a certificate has expired."""
def __str__(self):
publisher = self.args.get("publisher", None)
uri = self.args.get("uri", None)
days = self.args.get("days", 0)
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', needed to access '%(uri)s', "
"will expire in '%(days)s' days.") % {
"cert": self.data, "pub": publisher,
"uri": uri, "days": days }
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s' will expire in '%(days)s' days.") % {
"cert": self.data, "pub": publisher, "days": days }
if uri:
return _("Certificate '%(cert)s', needed to access "
"'%(uri)s', will expire in '%(days)s' days.") % {
"cert": self.data, "uri": uri, "days": days }
return _("Certificate '%(cert)s' will expire in "
"'%(days)s' days.") % { "cert": self.data, "days": days }
class InvalidCertificate(CertificateError):
"""Used to indicate that a certificate is invalid."""
def __str__(self):
publisher = self.args.get("publisher", None)
uri = self.args.get("uri", None)
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', needed to access '%(uri)s', is "
"invalid.") % { "cert": self.data,
"pub": publisher, "uri": uri }
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s' is invalid.") % { "cert": self.data,
"pub": publisher }
if uri:
return _("Certificate '%(cert)s' needed to access "
"'%(uri)s' is invalid.") % { "cert": self.data,
"uri": uri }
return _("Invalid certificate '%s'.") % self.data
class NoSuchCertificate(CertificateError):
"""Used to indicate that a certificate could not be found."""
def __str__(self):
publisher = self.args.get("publisher", None)
uri = self.args.get("uri", None)
if publisher:
if uri:
return _("Unable to locate certificate "
"'%(cert)s' for publisher '%(pub)s' needed "
"to access '%(uri)s'.") % {
"cert": self.data, "pub": publisher,
"uri": uri }
return _("Unable to locate certificate '%(cert)s' for "
"publisher '%(pub)s'.") % { "cert": self.data,
"pub": publisher }
if uri:
return _("Unable to locate certificate '%(cert)s' "
"needed to access '%(uri)s'.") % {
"cert": self.data, "uri": uri }
return _("Unable to locate certificate '%s'.") % self.data
class NotYetValidCertificate(CertificateError):
"""Used to indicate that a certificate is not yet valid (future
effective date)."""
def __str__(self):
publisher = self.args.get("publisher", None)
uri = self.args.get("uri", None)
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', needed to access '%(uri)s', "
"has a future effective date.") % {
"cert": self.data, "pub": publisher,
"uri": uri }
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s' has a future effective date.") % {
"cert": self.data, "pub": publisher }
if uri:
return _("Certificate '%(cert)s' needed to access "
"'%(uri)s' has a future effective date.") % {
"cert": self.data, "uri": uri }
return _("Certificate '%s' has a future effective date.") % \
self.data
class ServerReturnError(ApiException):
def __init__(self, line):
ApiException.__init__(self)
self.line = line
def __str__(self):
return _("Gave a bad response:%s") % line