1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# Module: Subversion utilities
19
# Author: William Grant
26
def create_auth_svn_client(username, password):
27
"""Create a new pysvn client which is set up to automatically authenticate
28
with the supplied credentials.
30
username = str(username)
31
password = str(password)
32
def get_login(_realm, existing_login, _may_save):
33
"""Callback function used by pysvn for authentication.
34
realm, existing_login, _may_save: The 3 arguments passed by pysvn to
36
The following has been determined empirically, not from docs:
37
existing_login will be the name of the user who owns the process on
38
the first attempt, "" on subsequent attempts. We use this fact.
40
# Only provide credentials on the _first_ attempt.
41
# If we're being asked again, then it means the credentials failed for
42
# some reason and we should just fail. (This is not desirable, but it's
43
# better than being asked an infinite number of times).
44
return (existing_login != "", username, password, True)
46
svnclient = pysvn.Client()
47
svnclient.callback_get_login = get_login
50
def revision_from_string(r_str):
54
return pysvn.Revision( pysvn.opt_revision_kind.head )
55
elif r_str == "WORKING":
56
return pysvn.Revision( pysvn.opt_revision_kind.working )
58
return pysvn.Revision( pysvn.opt_revision_kind.base )
63
return pysvn.Revision( pysvn.opt_revision_kind.number, r)
68
def revision_exists(client, path, revision):
70
client.list(path, revision=revision)
72
except pysvn.ClientError:
75
def revision_is_dir(client, path, revision):
76
"""Returns True if the given path+revision is a directory.
77
@raises a pysvn.ClientError if it does not exist.
79
# XXX I *think* the first element of the list is the requested object, and
80
# subsequent items are its possible children (so ignore them).
81
list_object, _ = client.list(path, revision=revision)[0]
82
# list_object is a PySvnList object
83
return list_object.kind == pysvn.node_kind.dir
85
class PysvnListStatWrapper:
86
'''Wrap a pysvn listing object to look somewhat like a result of
89
def __init__(self, pysvn_list):
90
self.pysvn_list = pysvn_list
92
def __getattr__(self, name):
95
# Special magic needed.
96
if self.pysvn_list.kind == pysvn.node_kind.dir:
101
return getattr(self.pysvn_list,
105
except AttributeError, KeyError:
106
raise AttributeError, name