Package portage :: Module exception
[hide private]

Source Code for Module portage.exception

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