1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
# Copyright (C) 2004 Aaron Bentley
# <aaron.bentley@utoronto.ca>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
__docformat__ = "restructuredtext"
__doc__ = "Exception classes"
import pybaz.errors
def exception_str(exception):
answer = ""
if len(str(exception)) > 0:
answer +="%s" % str(exception)
elif hasattr(exception, "__class__"):
answer += exception.__class__.__name__+"\n"
if answer == "":
answer = "Unknown exception"
return answer
class CommandFailed(Exception):
"""Abstract base class. Raise when a subcommand fails."""
pass
class CommandFailedWrapper(CommandFailed):
"""
Raise to cite another exception as a cause of command failure
"""
def __init__(self, e):
"""
Initialize with the wrapped type.
:param e: The exception that caused the command to fail
"""
self.e=e
def __str__(self):
return exception_str(self.e)
class NoVersionLogs(CommandFailed):
"""Raise when commit fails because the tree has no logs for the version"""
def __init__(self, version):
"""
Initialize with the version that has no logs in the tree.
:param version: The version that has no logs in the tree
:type version: `arch.Version`
"""
self.version=version
def __str__(self):
return "No logs in tree for version \""+str(self.version)+"\"."
class OutOfDate(CommandFailed):
"""Raise when commit fails because the tree is not up to date"""
def __str__(self):
return "Tree is not up-to-date"
class EmptyCommit(CommandFailed):
"""Raise when commit fails because the tree contains no changes."""
def __str__(self):
return "Aborting empty commit."
class NoLogMessage(CommandFailed):
"""Raise when commit fails because there is no log message."""
def __str__(self):
return "No log message available."
class NoLogSummary(CommandFailed):
"""Raise when commit fails because there is no log message."""
def __str__(self):
return "Log summary is missing or blank."
class CommitToMirror(CommandFailed):
"""Raise when commit fails because it attempts to write to a mirror."""
def __init__(self, archive):
self.archive=archive
def __str__(self):
return "Attempt to commit to mirror \""+str(self.archive)+"\"."
class CommitFailed(CommandFailed):
"""Raise when commit fails"""
def __str__(self):
return "Unable to commit"
class MissingID(CommandFailed):
"""
Raise to indicate a missing ID error.
"""
def __init__(self, err):
"""
Initialize with base error.
:param err: The original error that was thrown
:type err: `arch.util.ExecProblem`
"""
self.err = err
def __str__(self):
return str(self.err.proc.error).rstrip("\n")
class LintFailure(CommandFailed):
"""
Raise to indicate that some files are 'unrecognized'.
"""
def __init__(self, err):
"""
Initialize with lint text.
:param err: The original error that was thrown
:type err: `str`
"""
self.err = err
def __str__(self):
return str(self.err).rstrip("\n")
class UncommittedChanges(CommandFailed):
"""Raise when merge fails because the tree has uncommitted changes."""
def __init__(self, tree):
"""
Initialize with the tree that has uncommitted changes.
:param tree: The tree that has uncommitted changes
:type tree: `arch.WorkingTree`
"""
self.tree=tree
def __str__(self):
return "Project tree \"%s\" has has uncommitted changes." % self.tree
class DirectoryExists(CommandFailed):
"""Raise when get fails because the tree has no logs for the version"""
def __init__(self, directory):
"""
Initialize with the directory that exists.
:param directory: The directory that exists
:type directory: str
"""
self.directory=directory
def __str__(self):
return "Can't create directory. \""+str(self.directory)+\
"\" already exists."
class NoSuchAlias(CommandFailed):
"""Raise when command fails because there is no such alias"""
def __init__(self, alias):
"""
Initialize with the alias that's missing.
:param alias: The fictional alias
:type alias: str
"""
self.alias=alias
def __str__(self):
return "No such alias: "+self.alias
class MergeProblem(Exception):
"""An error occured during merging"""
def __init__(self):
message = "An error occured during merging"
Exception.__init__(self, message)
class CantDetermineArchive(Exception):
"""Raise when no archive can be determined"""
def __init__(self, spec, explanation):
if spec is not None:
spectext = "from \"%s\"" % spec
else:
spectext = "with no archive specification"
message = "Unable to determine archive %s:\n%s" % \
(spectext, explanation)
Exception.__init__(self, message)
class CantDetermineVersion(Exception):
"""Raise when no version can be determined"""
def __init__(self, spec, explain=""):
"""
Initialize with the spec and optional explanation.
:param spec: The version specifier that was used
:type spec: string
:param explain: An explanation of why the revision specifier didn't work
:type explain: string
"""
if spec != None:
self.spec=spec
else:
self.spec=""
self.explain=explain
def __str__(self):
return "Unable to determine version from \""+str(self.spec)+"\".\n"+\
self.explain
class CantDetermineRevision(Exception):
"""Raise when no revision can be determined"""
def __init__(self, spec, explain=""):
"""
Initialize with the spec and optional explanation.
:param spec: The revision specifier that was used
:type spec: string
:param explain: An explanation of why the revision specifier didn't work
:type explain: string
"""
if spec != None:
self.spec=spec
else:
self.spec=""
self.explain=explain
def __str__(self):
return "Unable to determine revision from \""+str(self.spec)+"\".\n"+self.explain
class NoLatestRevision(CantDetermineRevision):
"""Two trees have merges in common, but merge sequence differs"""
def __init__(self, mine, other):
message = """Neither tree is the unambiguous latest revision
MINE candidiate: %s
OTHER candidate: %s""" % (mine, other)
Exception.__init__(self, message)
self.mine = mine
self.other = other
self.message = message
__str__ = Exception.__str__
class UnrelatedTrees(CantDetermineRevision):
"""Two trees have no merges in common"""
def __init__(self, mine, other):
message = "No relationship could be found between these trees"
Exception.__init__(self, message)
self.mine = mine
self.other = other
__str__ = Exception.__str__
class CantParseAlias(Exception):
"Raise to indicate that alias parsing failed"
def __init__(self, text):
self.text=text
def __str__(self):
return "Can't parse alias:\""+self.text+"\""
class ForbiddenAliasSyntax(Exception):
"Raise to indicate that alias name uses forbidden syntax"
def __init__(self, text):
self.text=text
def __str__(self):
return "Forbidden alias syntax:\""+self.text+"\""
class BadOption(Exception):
"""Raise if a prompting option is set to a bogus value"""
pass
class NoEditorSpecified(Exception):
"""
Raise when an editor is requested, but none is available.
"""
def __str__(self):
return "No editor specified."
class GetHelp(Exception):
"""Indicate that help is required, not normal command execution"""
class TreeNotContain(Exception):
"""Indicates that tree does not contain a given path.
"""
def __init__(self, tree, path):
self.path = path
self.tree = tree
def __str__(self):
return "The tree \"%s\" does not contain \"%s\"." % \
(self.tree, self.path)
class ArchiveLookupError(Exception):
"""Raise to indicate an error that prevented the lookup from completing
"""
def __init__(self, exception, arch_name, resource):
self.exception = exception
self.arch_name = arch_name
self.resource = resource
def __str__(self):
return "Error encountered looking up \"%s\" at %s.\n%s" % \
(self.arch_name, self.resource, exception_str(self.exception))
class SubmitError(Exception):
"""Error submitting an archive to an arch registry"""
def __init__(self, archive, location, registry, result):
message = """Failed to register location.
Archive: %s
Location: %s
Registry: %s
Result: %s""" % (archive, location, registry, result)
self.archive = archive
self.location = location
self.registry = registry
self.result = result
Exception.__init__(self, message)
class NoSuchRevision(Exception):
"""Raise when a required revision does not exist."""
def __init__(self, revision):
self.revision=revision
def __str__(self):
return "This revision does not exist:\n"+str(self.revision)
class NoVersionRevisions(Exception):
"""The tree has no revisions for the desired version."""
def __init__(self, tree, version):
self.tree = tree
self.version = version
def __str__(self):
return "No logs for %s present in tree %s" % (self.version, self.tree)
class WrongArchName(Exception):
"""Attempt to register the archive with the wrong name"""
def __init__(self, location, right_name, wrong_name):
self.location = location
self.right_name = right_name
self.wrong_name = wrong_name
def __str__(self):
return "Attempt to register %s with location %s, but that's really %s" \
% (self.right_name, self.location, self.wrong_name)
class BlandSubject(CommandFailed):
"""The subject line of an email has no useful information"""
def __init__(self):
CommandFailed.__init__(self, "No meaningful subject line")
class NoArchParams(Exception):
"""The user's parameter directory does not exist/cannot be found"""
def __init__(self, dir):
self.dir = dir
message = "Arch parameter directory does not exist\ndir: %s" % dir
Exception.__init__(self, message)
class InvalidChangeset(Exception):
"""The user's parameter directory does not exist/cannot be found"""
def __init__(self, dir):
self.dir = dir
message = "Directory is not a valid changeset.\ndir: %s" % dir
Exception.__init__(self, message)
class NotLibrary(Exception):
"""A directory that was not library was spcified as if it was one."""
def __init__(self, dir):
self.dir = dir
message = "Specified directory is not a library.\ndir: %s" % dir
Exception.__init__(self, message)
class NoGreedy(Exception):
"""A greedy library was required, but not available."""
def __init__(self, revision):
self.revision = revision
message = "No greedy libraries found adding revision.\nrevision: %s" %\
revision
Exception.__init__(self, message)
class TreeRootNone(pybaz.errors.TreeRootError):
"""None was supplied instead of a valid tree root"""
def __init__(self):
message = "No tree root supplied"
Exception.__init__(self, message)
class IsAutoAlias(CommandFailed):
"""User attempted to redefine an auto alias"""
def __init__(self, alias, message=None):
self.revision = alias
if message is None:
message = "\"%s\" is an auto alias." % alias
Exception.__init__(self, message)
class TarError(Exception):
"""An error occurred using tar"""
def __init__(self, msg):
Exception.__init__(self, msg)
class UnknownCompressionMethod(TarError):
"""User specified an unknown compression method"""
def __init__(self, method):
self.method = method
msg = "Compression method \"%s\" is unknown." % self.method
TarError.__init__(self, msg)
class NoUnambiguousParent(TarError):
"""This tarfile doesn't follow the convention of a single root dir"""
def __init__(self, file, dir):
self.file = file
self.dir = dir
msg = "The file \"%s\" does not have \"%s\" as a parent" % (self.file,
self.dir)
TarError.__init__(self, msg)
class UnsupportedScheme(Exception):
def __init__(self, location):
msg = "Unsupported scheme: %s" % location
self.location = location
Exception.__init__(self, msg)
# arch-tag: fd8812b0-2d93-4b7c-a669-24a915d86ec1
|