Add revision specifier support.
[jelmer/subvertpy.git] / errors.py
1 # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
2
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.
7
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.
12
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
16 """Subversion-specific errors and conversion of Subversion-specific errors."""
17
18 from bzrlib.errors import (BzrError, ConnectionError, ConnectionReset, 
19                            LockError, NotBranchError, PermissionDenied, 
20                            DependencyNotPresent, NoRepositoryPresent,
21                            TransportError, UnexpectedEndOfContainerError)
22
23 import svn.core
24
25 # APR define, not in svn.core
26 SVN_ERR_UNKNOWN_HOSTNAME = 670002
27
28 class NotSvnBranchPath(NotBranchError):
29     """Error raised when a path was specified that did not exist."""
30     _fmt = """%(path)s is not a valid Subversion branch path. 
31 See 'bzr help svn-branching-schemes' for details."""
32
33     def __init__(self, branch_path, scheme=None):
34         NotBranchError.__init__(self, branch_path)
35         self.scheme = scheme
36
37
38 class NoSvnRepositoryPresent(NoRepositoryPresent):
39
40     def __init__(self, url):
41         BzrError.__init__(self)
42         self.path = url
43
44
45 class ChangesRootLHSHistory(BzrError):
46     _fmt = """changing lhs branch history not possible on repository root"""
47
48
49 class MissingPrefix(BzrError):
50     _fmt = """Prefix missing for %(path)s; please create it before pushing. """
51
52     def __init__(self, path):
53         BzrError.__init__(self)
54         self.path = path
55
56
57 class RevpropChangeFailed(BzrError):
58     _fmt = """Unable to set revision property %(name)s."""
59
60     def __init__(self, name):
61         BzrError.__init__(self)
62         self.name = name
63
64
65 def convert_error(err):
66     """Convert a Subversion exception to the matching BzrError.
67
68     :param err: SubversionException.
69     :return: BzrError instance if it could be converted, err otherwise
70     """
71     (msg, num) = err.args
72
73     if num == svn.core.SVN_ERR_RA_SVN_CONNECTION_CLOSED:
74         return ConnectionReset(msg=msg)
75     elif num == svn.core.SVN_ERR_WC_LOCKED:
76         return LockError(message=msg)
77     elif num == svn.core.SVN_ERR_RA_NOT_AUTHORIZED:
78         return PermissionDenied('.', msg)
79     elif num == svn.core.SVN_ERR_INCOMPLETE_DATA:
80         return UnexpectedEndOfContainerError()
81     elif num == svn.core.SVN_ERR_RA_SVN_MALFORMED_DATA:
82         return TransportError("Malformed data", msg)
83     elif num == SVN_ERR_UNKNOWN_HOSTNAME:
84         return ConnectionError(msg=msg)
85     elif num > 0 and num < 1000:
86         return OSError(num, msg)
87     else:
88         return err
89
90
91 def convert_svn_error(unbound):
92     """Decorator that catches particular Subversion exceptions and 
93     converts them to Bazaar exceptions.
94     """
95     def convert(*args, **kwargs):
96         try:
97             return unbound(*args, **kwargs)
98         except svn.core.SubversionException, e:
99             raise convert_error(e)
100
101     convert.__doc__ = unbound.__doc__
102     convert.__name__ = unbound.__name__
103     return convert
104
105
106 class NoCheckoutSupport(BzrError):
107
108     _fmt = 'Subversion version too old for working tree support.'
109
110
111 class LocalCommitsUnsupported(BzrError):
112
113     _fmt = 'Local commits are not supported for lightweight Subversion checkouts.'
114
115
116 class InvalidPropertyValue(BzrError):
117     _fmt = 'Invalid property value for Subversion property %(property)s: %(msg)s'
118
119     def __init__(self, property, msg):
120         BzrError.__init__(self)
121         self.property = property
122         self.msg = msg
123
124 class RebaseNotPresent(DependencyNotPresent):
125     _fmt = "Unable to import bzr-rebase (required for svn-upgrade support): %(error)s"
126
127     def __init__(self, error):
128         DependencyNotPresent.__init__(self, 'bzr-rebase', error)