Package pybaz :: Module errors
[frames] | no frames]

Source Code for Module pybaz.errors

  1  # arch-tag: f82e5927-7118-40ff-b2ca-71279a6e68aa 
  2  # Copyright (C) 2004  David Allouche <david@allouche.net> 
  3  #                     Canonical Ltd. 
  4  # 
  5  #    This program is free software; you can redistribute it and/or modify 
  6  #    it under the terms of the GNU General Public License as published by 
  7  #    the Free Software Foundation; either version 2 of the License, or 
  8  #    (at your option) any later version. 
  9  # 
 10  #    This program is distributed in the hope that it will be useful, 
 11  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  #    GNU General Public License for more details. 
 14  # 
 15  #    You should have received a copy of the GNU General Public License 
 16  #    along with this program; if not, write to the Free Software 
 17  #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 18   
 19  """PyArch exceptions 
 20  """ 
 21   
 22   
23 -class ExecProblem(RuntimeError):
24
25 - def __init__(self, proc):
26 info = [ proc.command ] 27 status = [] 28 if proc.signal is not None: 29 status.append("got signal %d" % proc.signal) 30 if proc.status is not None: 31 status.append("exited with code %d" % proc.status) 32 info.append(",".join(status)) 33 if proc.status is not None: 34 codes = ' '.join(map(str, proc.expected)) 35 if len(proc.expected) == 1: 36 info.append("(expected exit code %s)" % codes) 37 else: 38 info.append("(expected exit codes %s)" % codes) 39 lines = [' '.join(info)] 40 if proc.args: lines.append('argv: ' + ", ".join(map(repr, proc.args))) 41 if proc.chdir: lines.append('chdir: ' + repr(proc.chdir)) 42 if proc.error is not None: 43 error = proc.error.rstrip() 44 else: 45 error = None 46 if error: lines.extend(("* error report", error)) 47 RuntimeError.__init__(self, '\n'.join(lines)) 48 self.proc = proc
49 50
51 -class SourceTreeError(Exception):
52 53 """Tried to create a source tree object from non-tree-root directory.""" 54
55 - def __init__(self, dirname):
56 message = "directory is not a tree-root: %r" % (dirname,) 57 Exception.__init__(self, message) 58 self.dirname = str(dirname)
59 60
61 -class TreeRootError(Exception):
62 63 """Could not find the Arch tree-root of a directory.""" 64
65 - def __init__(self, dirname):
66 message = "directory is not inside a project tree: %r" % (dirname,) 67 Exception.__init__(self, message) 68 self.dirname = str(dirname)
69 70
71 -class TreeVersionError(Exception):
72 73 """Arch source tree does not have a valid default version.""" 74
75 - def __init__(self, tree, bad_version=None):
76 if bad_version is None: 77 message = "tree has no default version set: %r" % (tree,) 78 else: 79 message = "invalid default version for tree: tree=%r, version=%r" \ 80 % (tree, bad_version) 81 Exception.__init__(self, message) 82 self.tree = tree 83 self.bad_version = bad_version
84 85
86 -class NamespaceError(Exception):
87 88 """Invalid Arch namespace name, or incorrect kind of name. 89 90 A value that does not make sense in the Arch namespace was 91 provided, or the wrong kind of name was used, for example a 92 revision where a patchlevel is expected. 93 """ 94
95 - def __init__(self, name, expected=None):
96 if expected is None: 97 message = "invalid name: %s" % (name,) 98 else: 99 message = "invalid %s: %s" % (expected, name) 100 Exception.__init__(self, message) 101 self.name = name 102 self.expected = expected
103 104
105 -class ArchiveNotRegistered(Exception):
106 """Tried to access an unregistered archive. 107 108 Namespace existence predicates, implementing `NamespaceObject.exists`, 109 return a boolean value for the existence of a name in the Arch namespace. 110 When the archive a name belongs to is not registered, existence cannot be 111 decided, so this exception is raised. 112 """ 113
114 - def __init__(self, name):
115 message = "archive not registered: %s" % (name,) 116 Exception.__init__(self, message) 117 self.name = name
118 119
120 -class LocationNotRegistered(Exception):
121 """Tried to unregister a location that is not registered. 122 123 `ArchiveLocation.unregister` raises this exception if the location was not 124 registered. 125 """ 126
127 - def __init__(self, url):
128 message = "location not registered: %s" % (url,) 129 Exception.__init__(self, message) 130 self.url = url
131 132
133 -class LocationAlreadyRegistered(Exception):
134 """Tried to register a location that was already registered. 135 136 `ArchiveLocation.register` raises this exception if the location was 137 already registered. 138 """ 139
140 - def __init__(self, url):
141 message = "location already registered: %s" % (url,) 142 Exception.__init__(self, message) 143 self.url = url
144 145
146 -class MirrorLocationMismatch(Exception):
147 """Tried to mirror to a location that contains a different archive. 148 149 `ArchiveLocation.make_mirrorer` raises this exception if the target was a 150 registered location for a different archive. 151 """ 152
153 - def __init__(self, source, target):
154 message = ("source location %r contains archive %r," 155 " but target location %r contains archive %r." 156 % (source, source.archive(), target, target.archive())) 157 Exception.__init__(self, message) 158 self.source = source 159 self.target = target
160 161
162 -class MetaInfoError(Exception):
163 """The requested archive meta-info was not present. 164 165 ArchiveLocation.meta_info raises this exception if the archive contained no 166 meta-info for the specified key. 167 """ 168
169 - def __init__(self, url, key):
170 message = "location %r has no meta-info %r" % (url, key) 171 Exception.__init__(self, message) 172 self.url = url 173 self.key = key
174 175
176 -class UntaggedFileError(Exception):
177 """Tried to get the id-tag of file which has none. 178 179 The id-tag of a file is an id which is set by an explicit id or a 180 tagline. Implicit-style taglines ("tag:") and name-based ids do 181 not count. 182 """ 183
184 - def __init__(self, name):
185 message = "file has not explicit id nor tagline: %s" % (name,) 186 Exception.__init__(self, message) 187 self.name = name
188
189 -class IllegalEscapeSequence(Exception):
190 """Illegal syntax in a pika-escaped string. 191 192 Pika-escaping is the syntax used to represent spaces, control 193 characters and non-ASCII characters in file names with Arch. 194 """ 195
196 - def __init__(self, text):
197 message = "illegal escape sequence in %r" % text 198 Exception.__init__(self, message) 199 self.text = text
200 201
202 -class NoPristineFoundError(Exception):
203 204 """Failed to find a pristine for the given revision. 205 206 `WorkingTree.find_pristine` raises this exception if no pristine 207 tree can be found for the given revision. 208 """ 209
210 - def __init__(self, tree, revision):
211 message = "no pristine found for revision %s in tree %r" \ 212 % (revision.fullname, str(tree)) 213 Exception.__init__(self, message) 214 self.revision, self.tree = revision, tree
215 216
217 -class MissingFileError(Exception):
218 219 """A request file is not present in the given revision. 220 221 `ArchSourceTree.file_find` raises this exception if the requested 222 does not exist in the specified revision. 223 """ 224
225 - def __init__(self, tree, name, revision):
226 message = "file %r from the tree %r is not present in revision %s" \ 227 % (str(name), str(tree), revision) 228 Exception.__init__(self, message) 229 self.tree, self.name, self.revision = tree, name, revision
230 231
232 -class ChangesetConflict(Exception):
233 234 """A conflict occured when applying a changeset.""" 235
236 - def __init__(self, tree, cset):
237 message = "conflict when applying %r to %s" % (cset, tree) 238 Exception.__init__(self, message) 239 self.tree, self.changeset = tree, cset
240