Show More
@@ -1,129 +1,128 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2007 Daniel Holth <dholth@fastmail.fm> |
|
3 | # Copyright (C) 2007 Daniel Holth <dholth@fastmail.fm> | |
4 | # This is a stripped-down version of the original bzr-svn transport.py, |
|
4 | # This is a stripped-down version of the original bzr-svn transport.py, | |
5 | # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org> |
|
5 | # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org> | |
6 |
|
6 | |||
7 | # This program is free software; you can redistribute it and/or modify |
|
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by |
|
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or |
|
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. |
|
10 | # (at your option) any later version. | |
11 |
|
11 | |||
12 | # This program is distributed in the hope that it will be useful, |
|
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. |
|
15 | # GNU General Public License for more details. | |
16 |
|
16 | |||
17 | # You should have received a copy of the GNU General Public License |
|
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program; if not, write to the Free Software |
|
18 | # along with this program; if not, write to the Free Software | |
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 |
|
20 | |||
21 | from svn.core import SubversionException, Pool |
|
21 | from svn.core import SubversionException, Pool | |
22 | import svn.ra |
|
22 | import svn.ra | |
23 | import svn.client |
|
23 | import svn.client | |
24 | import svn.core |
|
24 | import svn.core | |
25 |
|
25 | |||
26 | # Some older versions of the Python bindings need to be |
|
26 | # Some older versions of the Python bindings need to be | |
27 | # explicitly initialized. But what we want to do probably |
|
27 | # explicitly initialized. But what we want to do probably | |
28 | # won't work worth a darn against those libraries anyway! |
|
28 | # won't work worth a darn against those libraries anyway! | |
29 | svn.ra.initialize() |
|
29 | svn.ra.initialize() | |
30 |
|
30 | |||
31 | svn_config = svn.core.svn_config_get_config(None) |
|
31 | svn_config = svn.core.svn_config_get_config(None) | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | def _create_auth_baton(pool): |
|
34 | def _create_auth_baton(pool): | |
35 | """Create a Subversion authentication baton. """ |
|
35 | """Create a Subversion authentication baton. """ | |
36 | import svn.client |
|
36 | import svn.client | |
37 | # Give the client context baton a suite of authentication |
|
37 | # Give the client context baton a suite of authentication | |
38 | # providers.h |
|
38 | # providers.h | |
39 | providers = [ |
|
39 | providers = [ | |
40 | svn.client.get_simple_provider(pool), |
|
40 | svn.client.get_simple_provider(pool), | |
41 | svn.client.get_username_provider(pool), |
|
41 | svn.client.get_username_provider(pool), | |
42 | svn.client.get_ssl_client_cert_file_provider(pool), |
|
42 | svn.client.get_ssl_client_cert_file_provider(pool), | |
43 | svn.client.get_ssl_client_cert_pw_file_provider(pool), |
|
43 | svn.client.get_ssl_client_cert_pw_file_provider(pool), | |
44 | svn.client.get_ssl_server_trust_file_provider(pool), |
|
44 | svn.client.get_ssl_server_trust_file_provider(pool), | |
45 | ] |
|
45 | ] | |
46 | # Platform-dependant authentication methods |
|
46 | # Platform-dependant authentication methods | |
47 | getprovider = getattr(svn.core, 'svn_auth_get_platform_specific_provider', |
|
47 | getprovider = getattr(svn.core, 'svn_auth_get_platform_specific_provider', | |
48 | None) |
|
48 | None) | |
49 | if getprovider: |
|
49 | if getprovider: | |
50 | # Available in svn >= 1.6 |
|
50 | # Available in svn >= 1.6 | |
51 | for name in ('gnome_keyring', 'keychain', 'kwallet', 'windows'): |
|
51 | for name in ('gnome_keyring', 'keychain', 'kwallet', 'windows'): | |
52 | for type in ('simple', 'ssl_client_cert_pw', 'ssl_server_trust'): |
|
52 | for type in ('simple', 'ssl_client_cert_pw', 'ssl_server_trust'): | |
53 | p = getprovider(name, type, pool) |
|
53 | p = getprovider(name, type, pool) | |
54 | if p: |
|
54 | if p: | |
55 | providers.append(p) |
|
55 | providers.append(p) | |
56 | else: |
|
56 | else: | |
57 | if hasattr(svn.client, 'get_windows_simple_provider'): |
|
57 | if hasattr(svn.client, 'get_windows_simple_provider'): | |
58 | providers.append(svn.client.get_windows_simple_provider(pool)) |
|
58 | providers.append(svn.client.get_windows_simple_provider(pool)) | |
59 |
|
59 | |||
60 | return svn.core.svn_auth_open(providers, pool) |
|
60 | return svn.core.svn_auth_open(providers, pool) | |
61 |
|
61 | |||
62 | class NotBranchError(SubversionException): |
|
62 | class NotBranchError(SubversionException): | |
63 | pass |
|
63 | pass | |
64 |
|
64 | |||
65 | class SvnRaTransport(object): |
|
65 | class SvnRaTransport(object): | |
66 | """ |
|
66 | """ | |
67 | Open an ra connection to a Subversion repository. |
|
67 | Open an ra connection to a Subversion repository. | |
68 | """ |
|
68 | """ | |
69 | def __init__(self, url="", ra=None): |
|
69 | def __init__(self, url="", ra=None): | |
70 | self.pool = Pool() |
|
70 | self.pool = Pool() | |
71 | self.svn_url = url |
|
71 | self.svn_url = url | |
72 | self.username = '' |
|
72 | self.username = '' | |
73 | self.password = '' |
|
73 | self.password = '' | |
74 |
|
74 | |||
75 | # Only Subversion 1.4 has reparent() |
|
75 | # Only Subversion 1.4 has reparent() | |
76 | if ra is None or not hasattr(svn.ra, 'reparent'): |
|
76 | if ra is None or not hasattr(svn.ra, 'reparent'): | |
77 | self.client = svn.client.create_context(self.pool) |
|
77 | self.client = svn.client.create_context(self.pool) | |
78 | ab = _create_auth_baton(self.pool) |
|
78 | ab = _create_auth_baton(self.pool) | |
79 | if False: |
|
79 | if False: | |
80 | svn.core.svn_auth_set_parameter( |
|
80 | svn.core.svn_auth_set_parameter( | |
81 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) |
|
81 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) | |
82 | svn.core.svn_auth_set_parameter( |
|
82 | svn.core.svn_auth_set_parameter( | |
83 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) |
|
83 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) | |
84 | self.client.auth_baton = ab |
|
84 | self.client.auth_baton = ab | |
85 | self.client.config = svn_config |
|
85 | self.client.config = svn_config | |
86 | try: |
|
86 | try: | |
87 | self.ra = svn.client.open_ra_session( |
|
87 | self.ra = svn.client.open_ra_session( | |
88 | self.svn_url.encode('utf8'), |
|
88 | self.svn_url.encode('utf8'), | |
89 | self.client, self.pool) |
|
89 | self.client, self.pool) | |
90 | except SubversionException, (inst, num): |
|
90 | except SubversionException, (inst, num): | |
91 | if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, |
|
91 | if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, | |
92 | svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, |
|
92 | svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, | |
93 | svn.core.SVN_ERR_BAD_URL): |
|
93 | svn.core.SVN_ERR_BAD_URL): | |
94 | raise NotBranchError(url) |
|
94 | raise NotBranchError(url) | |
95 | raise |
|
95 | raise | |
96 | else: |
|
96 | else: | |
97 | self.ra = ra |
|
97 | self.ra = ra | |
98 | svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) |
|
98 | svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) | |
99 |
|
99 | |||
100 | class Reporter(object): |
|
100 | class Reporter(object): | |
101 |
def __init__(self, |
|
101 | def __init__(self, reporter_data): | |
102 | self._reporter = reporter |
|
102 | self._reporter, self._baton = reporter_data | |
103 | self._baton = report_baton |
|
|||
104 |
|
103 | |||
105 | def set_path(self, path, revnum, start_empty, lock_token, pool=None): |
|
104 | def set_path(self, path, revnum, start_empty, lock_token, pool=None): | |
106 | svn.ra.reporter2_invoke_set_path(self._reporter, self._baton, |
|
105 | svn.ra.reporter2_invoke_set_path(self._reporter, self._baton, | |
107 | path, revnum, start_empty, lock_token, pool) |
|
106 | path, revnum, start_empty, lock_token, pool) | |
108 |
|
107 | |||
109 | def delete_path(self, path, pool=None): |
|
108 | def delete_path(self, path, pool=None): | |
110 | svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton, |
|
109 | svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton, | |
111 | path, pool) |
|
110 | path, pool) | |
112 |
|
111 | |||
113 | def link_path(self, path, url, revision, start_empty, lock_token, |
|
112 | def link_path(self, path, url, revision, start_empty, lock_token, | |
114 | pool=None): |
|
113 | pool=None): | |
115 | svn.ra.reporter2_invoke_link_path(self._reporter, self._baton, |
|
114 | svn.ra.reporter2_invoke_link_path(self._reporter, self._baton, | |
116 | path, url, revision, start_empty, lock_token, |
|
115 | path, url, revision, start_empty, lock_token, | |
117 | pool) |
|
116 | pool) | |
118 |
|
117 | |||
119 | def finish_report(self, pool=None): |
|
118 | def finish_report(self, pool=None): | |
120 | svn.ra.reporter2_invoke_finish_report(self._reporter, |
|
119 | svn.ra.reporter2_invoke_finish_report(self._reporter, | |
121 | self._baton, pool) |
|
120 | self._baton, pool) | |
122 |
|
121 | |||
123 | def abort_report(self, pool=None): |
|
122 | def abort_report(self, pool=None): | |
124 | svn.ra.reporter2_invoke_abort_report(self._reporter, |
|
123 | svn.ra.reporter2_invoke_abort_report(self._reporter, | |
125 | self._baton, pool) |
|
124 | self._baton, pool) | |
126 |
|
125 | |||
127 | def do_update(self, revnum, path, *args, **kwargs): |
|
126 | def do_update(self, revnum, path, *args, **kwargs): | |
128 | return self.Reporter(svn.ra.do_update(self.ra, revnum, path, |
|
127 | return self.Reporter(svn.ra.do_update(self.ra, revnum, path, | |
129 | *args, **kwargs)) |
|
128 | *args, **kwargs)) |
General Comments 0
You need to be logged in to leave comments.
Login now