~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fai/arch/errors.py

  • Committer: Robert Collins
  • Date: 2005-09-08 11:21:38 UTC
  • mto: (147.2.6) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20050908112138-033369d3cacacb55
test and deliver basic pending-merges into bzr so that merging is recorded

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 TreeRootError(Exception):
 
52
 
 
53
    """Could not find the Arch tree-root of a directory."""
 
54
 
 
55
    def __init__(self, dirname):
 
56
        message = "directory is not inside a project tree: %r" % (dirname,)
 
57
        Exception.__init__(self, message)
 
58
        self.dirname = str(dirname)
 
59
 
 
60
 
 
61
class TreeVersionError(Exception):
 
62
 
 
63
    """Arch source tree does not have a valid default version."""
 
64
 
 
65
    def __init__(self, tree, bad_version=None):
 
66
        if bad_version is None:
 
67
            message = "tree has no default version set: %r" % (tree,)
 
68
        else:
 
69
            message = "invalid default version for tree: tree=%r, version=%r" \
 
70
                      % (tree, bad_version)
 
71
        Exception.__init__(self, message)
 
72
        self.tree = tree
 
73
        self.bad_version = bad_version
 
74
 
 
75
 
 
76
class NamespaceError(Exception):
 
77
 
 
78
    """Invalid Arch namespace name, or incorrect kind of name.
 
79
 
 
80
    A value that does not make sense in the Arch namespace was
 
81
    provided, or the wrong kind of name was used, for example a
 
82
    revision where a patchlevel is expected.
 
83
    """
 
84
 
 
85
    def __init__(self, name, expected=None):
 
86
        if expected is None:
 
87
            message = "invalid name: %s" % (name,)
 
88
        else:
 
89
            message = "invalid %s: %s" % (expected, name)
 
90
        Exception.__init__(self, message)
 
91
        self.name = name
 
92
        self.expected = expected
 
93
 
 
94
 
 
95
class ArchiveNotRegistered(Exception):
 
96
 
 
97
    """Tried to access an unregistered archive.
 
98
 
 
99
    Namespace existence predicates, implementing `NamespaceObject.exists`,
 
100
    return a boolean value for the existence of a name in the Arch namespace.
 
101
    When the archive a name belongs to is not registered, existence cannot be
 
102
    decided, so this exception is raised.
 
103
    """
 
104
 
 
105
    def __init__(self, name):
 
106
        message = "archive not registered: %s" % (name,)
 
107
        Exception.__init__(self, message)
 
108
        self.name = name
 
109
 
 
110
 
 
111
class UntaggedFileError(Exception):
 
112
 
 
113
    """Tried to get the id-tag of file which has none.
 
114
 
 
115
    The id-tag of a file is an id which is set by an explicit id or a
 
116
    tagline. Implicit-style taglines ("tag:") and name-based ids do
 
117
    not count.
 
118
    """
 
119
 
 
120
    def __init__(self, name):
 
121
        message = "file has not explicit id nor tagline: %s" % (name,)
 
122
        Exception.__init__(self, message)
 
123
        self.name = name
 
124
 
 
125
class IllegalEscapeSequence(Exception):
 
126
 
 
127
    """Illegal syntax in a pika-escaped string.
 
128
 
 
129
    Pika-escaping is the syntax used to represent spaces, control
 
130
    characters and non-ASCII characters in file names with Arch.
 
131
    """
 
132
 
 
133
    def __init__(self, text):
 
134
        message = "illegal escape sequence in %r" % text
 
135
        Exception.__init__(self, message)
 
136
        self.text = text
 
137
 
 
138
 
 
139
class NoPristineFoundError(Exception):
 
140
 
 
141
    """Failed to find a pristine for the given revision.
 
142
 
 
143
    `WorkingTree.find_pristine` raises this exception if no pristine
 
144
    tree can be found for the given revision.
 
145
    """
 
146
 
 
147
    def __init__(self, tree, revision):
 
148
        message = "no pristine found for revision %s in tree %r" \
 
149
                  % (revision.fullname, str(tree))
 
150
        Exception.__init__(self, message)
 
151
        self.revision, self.tree = revision, tree
 
152
 
 
153
 
 
154
class MissingFileError(Exception):
 
155
 
 
156
    """A request file is not present in the given revision.
 
157
 
 
158
    `ArchSourceTree.file_find` raises this exception if the requested
 
159
    does not exist in the specified revision.
 
160
    """
 
161
 
 
162
    def __init__(self, tree, name, revision):
 
163
        message = "file %r from the tree %r is not present in revision %s" \
 
164
                  % (str(name), str(tree), revision)
 
165
        Exception.__init__(self, message)
 
166
        self.tree, self.name, self.revision = tree, name, revision