1 # Copyright (C) 2008 Canonical Ltd
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 """Exception classes for fastimport"""
20 class FastImportError(StandardError):
21 """The base exception class for all import processing exceptions."""
23 _fmt = "Unknown Import Error"
26 return self._fmt % self.__dict__
28 class ParsingError(FastImportError):
29 """The base exception class for all import processing exceptions."""
31 _fmt = "Unknown Import Parsing Error"
33 def __init__(self, filename, lineno):
34 FastImportError.__init__(self)
35 self.filename = filename
41 result.append(self.filename)
43 result.append("line ")
44 result.append(str(self.lineno))
46 result.append(FastImportError.__str__(self))
47 return "".join(result)
50 class MissingBytes(ParsingError):
51 """Raised when EOF encountered while expecting to find more bytes."""
53 _fmt = ("Unexpected EOF - expected %(expected)d bytes,"
56 def __init__(self, filename, lineno, expected, found):
57 ParsingError.__init__(self, filename, lineno)
58 self.expected = expected
62 class MissingTerminator(ParsingError):
63 """Raised when EOF encountered while expecting to find a terminator."""
65 _fmt = "Unexpected EOF - expected '%(terminator)s' terminator"
67 def __init__(self, filename, lineno, terminator):
68 ParsingError.__init__(self, filename, lineno)
69 self.terminator = terminator
72 class InvalidCommand(ParsingError):
73 """Raised when an unknown command found."""
75 _fmt = ("Invalid command '%(cmd)s'")
77 def __init__(self, filename, lineno, cmd):
78 ParsingError.__init__(self, filename, lineno)
82 class MissingSection(ParsingError):
83 """Raised when a section is required in a command but not present."""
85 _fmt = ("Command %(cmd)s is missing section %(section)s")
87 def __init__(self, filename, lineno, cmd, section):
88 ParsingError.__init__(self, filename, lineno)
90 self.section = section
93 class BadFormat(ParsingError):
94 """Raised when a section is formatted incorrectly."""
96 _fmt = ("Bad format for section %(section)s in "
97 "command %(cmd)s: found '%(text)s'")
99 def __init__(self, filename, lineno, cmd, section, text):
100 ParsingError.__init__(self, filename, lineno)
102 self.section = section
106 class InvalidTimezone(ParsingError):
107 """Raised when converting a string timezone to a seconds offset."""
109 _fmt = "Timezone %(timezone)r could not be converted.%(reason)s"
111 def __init__(self, filename, lineno, timezone, reason=None):
112 ParsingError.__init__(self, filename, lineno)
113 self.timezone = timezone
115 self.reason = ' ' + reason
120 class UnknownDateFormat(FastImportError):
121 """Raised when an unknown date format is given."""
123 _fmt = ("Unknown date format '%(format)s'")
125 def __init__(self, format):
126 FastImportError.__init__(self)
130 class MissingHandler(FastImportError):
131 """Raised when a processor can't handle a command."""
133 _fmt = ("Missing handler for command %(cmd)s")
135 def __init__(self, cmd):
136 FastImportError.__init__(self)
140 class UnknownParameter(FastImportError):
141 """Raised when an unknown parameter is passed to a processor."""
143 _fmt = ("Unknown parameter - '%(param)s' not in %(knowns)s")
145 def __init__(self, param, knowns):
146 FastImportError.__init__(self)
151 class BadRepositorySize(FastImportError):
152 """Raised when the repository has an incorrect number of revisions."""
154 _fmt = ("Bad repository size - %(found)d revisions found, "
155 "%(expected)d expected")
157 def __init__(self, expected, found):
158 FastImportError.__init__(self)
159 self.expected = expected
163 class BadRestart(FastImportError):
164 """Raised when the import stream and id-map do not match up."""
166 _fmt = ("Bad restart - attempted to skip commit %(commit_id)s "
167 "but matching revision-id is unknown")
169 def __init__(self, commit_id):
170 FastImportError.__init__(self)
171 self.commit_id = commit_id
174 class UnknownFeature(FastImportError):
175 """Raised when an unknown feature is given in the input stream."""
177 _fmt = ("Unknown feature '%(feature)s' - try a later importer or "
178 "an earlier data format")
180 def __init__(self, feature):
181 FastImportError.__init__(self)
182 self.feature = feature