Package portage :: Module exception
[hide private]

Source Code for Module portage.exception

  1  # Copyright 1998-2015 Gentoo Foundation 
  2  # Distributed under the terms of the GNU General Public License v2 
  3   
  4  import signal 
  5  import sys 
  6  from portage import _encodings, _unicode_encode, _unicode_decode 
  7  from portage.localization import _ 
  8   
  9  if sys.hexversion >= 0x3000000: 
 10          # pylint: disable=W0622 
 11          basestring = str 
12 13 -class PortageException(Exception):
14 """General superclass for portage exceptions""" 15 if sys.hexversion >= 0x3000000:
16 - def __init__(self, value):
17 self.value = value[:]
18
19 - def __str__(self):
20 if isinstance(self.value, str): 21 return self.value 22 else: 23 return repr(self.value)
24 else:
25 - def __init__(self, value):
26 self.value = value[:] 27 if isinstance(self.value, basestring): 28 self.value = _unicode_decode(self.value, 29 encoding=_encodings['content'], errors='replace')
30
31 - def __unicode__(self):
32 if isinstance(self.value, unicode): 33 return self.value 34 else: 35 return _unicode_decode(repr(self.value), 36 encoding=_encodings['content'], errors='replace')
37
38 - def __str__(self):
39 if isinstance(self.value, unicode): 40 return _unicode_encode(self.value, 41 encoding=_encodings['content'], errors='backslashreplace') 42 else: 43 return repr(self.value)
44
45 -class PortageKeyError(KeyError, PortageException):
46 __doc__ = KeyError.__doc__
47
48 -class CorruptionError(PortageException):
49 """Corruption indication"""
50
51 -class InvalidDependString(PortageException):
52 """An invalid depend string has been encountered"""
53 - def __init__(self, value, errors=None):
54 PortageException.__init__(self, value) 55 self.errors = errors
56
57 -class InvalidVersionString(PortageException):
58 """An invalid version string has been encountered"""
59
60 -class SecurityViolation(PortageException):
61 """An incorrect formatting was passed instead of the expected one"""
62
63 -class IncorrectParameter(PortageException):
64 """A parameter of the wrong type was passed"""
65
66 -class MissingParameter(PortageException):
67 """A parameter is required for the action requested but was not passed"""
68
69 -class ParseError(PortageException):
70 """An error was generated while attempting to parse the request"""
71
72 -class InvalidData(PortageException):
73 """An incorrect formatting was passed instead of the expected one"""
74 - def __init__(self, value, category=None):
77
78 -class InvalidDataType(PortageException):
79 """An incorrect type was passed instead of the expected one"""
80
81 -class InvalidLocation(PortageException):
82 """Data was not found when it was expected to exist or was specified incorrectly"""
83
84 -class FileNotFound(InvalidLocation):
85 """A file was not found when it was expected to exist"""
86
87 -class DirectoryNotFound(InvalidLocation):
88 """A directory was not found when it was expected to exist"""
89
90 -class IsADirectory(PortageException):
91 """A directory was found when it was expected to be a file""" 92 from errno import EISDIR as errno
93
94 -class OperationNotPermitted(PortageException):
95 """An operation was not permitted operating system""" 96 from errno import EPERM as errno
97
98 -class OperationNotSupported(PortageException):
99 """Operation not supported""" 100 from errno import EOPNOTSUPP as errno
101
102 -class PermissionDenied(PortageException):
103 """Permission denied""" 104 from errno import EACCES as errno
105
106 -class TryAgain(PortageException):
107 """Try again""" 108 from errno import EAGAIN as errno
109
110 -class TimeoutException(PortageException):
111 """Operation timed out"""
112 # NOTE: ETIME is undefined on FreeBSD (bug #336875)
113 #from errno import ETIME as errno 114 115 -class AlarmSignal(TimeoutException):
116 - def __init__(self, value, signum=None, frame=None):
117 TimeoutException.__init__(self, value) 118 self.signum = signum 119 self.frame = frame
120 121 @classmethod
122 - def register(cls, time):
123 signal.signal(signal.SIGALRM, cls._signal_handler) 124 signal.alarm(time)
125 126 @classmethod
127 - def unregister(cls):
128 signal.alarm(0) 129 signal.signal(signal.SIGALRM, signal.SIG_DFL)
130 131 @classmethod
132 - def _signal_handler(cls, signum, frame):
133 signal.signal(signal.SIGALRM, signal.SIG_DFL) 134 raise AlarmSignal("alarm signal", 135 signum=signum, frame=frame)
136
137 -class ReadOnlyFileSystem(PortageException):
138 """Read-only file system""" 139 from errno import EROFS as errno
140
141 -class CommandNotFound(PortageException):
142 """A required binary was not available or executable"""
143
144 -class AmbiguousPackageName(ValueError, PortageException):
145 """Raised by portage.cpv_expand() when the package name is ambiguous due 146 to the existence of multiple matches in different categories. This inherits 147 from ValueError, for backward compatibility with calling code that already 148 handles ValueError."""
149 - def __str__(self):
150 return ValueError.__str__(self)
151
152 -class PortagePackageException(PortageException):
153 """Malformed or missing package data"""
154
155 -class PackageNotFound(PortagePackageException):
156 """Missing Ebuild or Binary"""
157
158 -class PackageSetNotFound(PortagePackageException):
159 """Missing package set"""
160
161 -class InvalidPackageName(PortagePackageException):
162 """Malformed package name"""
163
164 -class InvalidAtom(PortagePackageException):
165 """Malformed atom spec"""
166 - def __init__(self, value, category=None):
169
170 -class UnsupportedAPIException(PortagePackageException):
171 """Unsupported API"""
172 - def __init__(self, cpv, eapi):
173 self.cpv, self.eapi = cpv, eapi
174 - def __str__(self):
175 eapi = self.eapi 176 if not isinstance(eapi, basestring): 177 eapi = str(eapi) 178 eapi = eapi.lstrip("-") 179 msg = _("Unable to do any operations on '%(cpv)s', since " 180 "its EAPI is higher than this portage version's. Please upgrade" 181 " to a portage version that supports EAPI '%(eapi)s'.") % \ 182 {"cpv": self.cpv, "eapi": eapi} 183 return _unicode_decode(msg, 184 encoding=_encodings['content'], errors='replace')
185 186 if sys.hexversion < 0x3000000: 187 188 __unicode__ = __str__ 189
190 - def __str__(self):
191 return _unicode_encode(self.__unicode__(), 192 encoding=_encodings['content'], errors='backslashreplace')
193
194 -class SignatureException(PortageException):
195 """Signature was not present in the checked file"""
196
197 -class DigestException(SignatureException):
198 """A problem exists in the digest"""
199
200 -class MissingSignature(SignatureException):
201 """Signature was not present in the checked file"""
202
203 -class InvalidSignature(SignatureException):
204 """Signature was checked and was not a valid, current, nor trusted signature"""
205
206 -class UntrustedSignature(SignatureException):
207 """Signature was not certified to the desired security level"""
208