Package portage :: Module exception
[hide private]

Source Code for Module portage.exception

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