Index: csvn/client.py =================================================================== --- csvn/client.py (revision 25219) +++ csvn/client.py (working copy) @@ -2,171 +2,9 @@ from csvn.core import * from csvn.ext.callback_receiver import CallbackReceiver from txn import Txn +from client_helpers import * import os -class SvnDate(str): - - def as_apr_time_t(self): - """Return this date to an apr_time_t object""" - pool = Pool() - when = apr_time_t() - svn_time_from_cstring(byref(when), self, pool) - return when - - def as_human_string(self): - """Return this date to a human-readable date""" - pool = Pool() - return str(svn_time_to_human_cstring(self.as_apr_time_t(), pool)) - -class LogEntry(object): - """REVISION, AUTHOR, DATE, and MESSAGE are straightforward, and - contain what you expect. DATE is an SvnDate object. - - If no information about the paths changed in this revision is - available, CHANGED_PATHS will be None. Otherwise, CHANGED_PATHS - will contain a dictionary which maps every path committed - in REVISION to svn_log_changed_path_t pointers.""" - - __slots__ = ['changed_paths', 'revision', - 'author', 'date', 'message'] - - -class _LogMessageReceiver(CallbackReceiver): - - def collect(self, session, start_rev, end_rev, paths, limit, verbose, - stop_on_copy): - self.verbose = verbose - pool = Pool() - baton = c_void_p(id(self)) - receiver = svn_log_message_receiver_t(self.receive) - svn_ra_get_log(session, paths, start_rev, end_rev, - limit, verbose, stop_on_copy, receiver, - baton, pool) - - def receive(baton, changed_paths, revision, author, date, message, pool): - self = cast(baton, py_object).value - - entry = LogEntry() - - # Save information about the log entry - entry.revision = revision - entry.author = str(author) - entry.date = SvnDate(date) - entry.message = str(message) - - if self.verbose: - entry.changed_paths = Hash(POINTER(svn_log_changed_path_t), - changed_paths, dup = svn_log_changed_path_dup) - else: - entry.changed_paths = None - - self.send(entry) - receive = staticmethod(receive) - -class User(object): - - def __init__(self, username=None, password=None): - """Create a user object which represents a user - with the specified username and password.""" - - self._username = username - self._password = password - self.pool = Pool() - - def username(self): - """Return the current username. - - By default, this function just returns the username - which was supplied in the constructor, but subclasses - may behave differently.""" - return self._username - - def password(self): - """Return the current password. - - By default, this function just returns the password - which was supplied in the constructor, but subclasses - may behave differently.""" - return self._password - - def allow_access(self, requested_access, path): - """Check whether the current user has the REQUESTED_ACCESS - to PATH. - - If PATH is None, this function should check if the - REQUESTED_ACCESS is granted for at least one path - in the repository. - - REQUESTED_ACCESS is an integer which may consist of - any combination of the following fields: - svn_authz_read: The path can be read - svn_authz_write: The path can be altered - svn_authz_recursive: The other access credentials - are recursive. - - By default, this function always returns True, but - subclasses may behave differently. - - This function is used by the "Repository" class to check - permissions (see repos.py). - - FIXME: This function isn't currently used, because we - haven't implemented higher-level authz yet. - """ - - return True - - def setup_auth_baton(self, auth_baton): - - # Setup the auth baton using the default options from the - # command-line client - svn_cmdline_setup_auth_baton(auth_baton, TRUE, - self._username, self._password, NULL, TRUE, NULL, - svn_cancel_func_t(), NULL, self.pool) - - -class RepositoryURI(object): - """A URI to an object in a Subversion repository, stored internally in - encoded format. - - When you supply URIs to a RemoteClient, or a transaction""" - - def __init__(self, uri, encoded=True): - """Create a RepositoryURI object from a URI. If encoded=True, the - input string may be URI-encoded.""" - pool = Pool() - if not encoded: - uri = svn_path_uri_encode(uri, pool) - self._as_parameter_ = str(svn_path_canonicalize(uri, pool)) - - def join(self, uri): - """Join this URI and the specified relative URI, - adding a slash if necessary.""" - pool = Pool() - return RepositoryURI(svn_path_join(self, uri, pool)) - - def dirname(self): - """Get the parent directory of this URI""" - pool = Pool() - return RepositoryURI(svn_path_dirname(self, pool)) - - def relative_path(self, uri, encoded=True): - """Convert the supplied URI to a decoded path, relative to me.""" - pool = Pool() - if not encoded: - uri = svn_path_uri_encode(uri, pool) - child_path = svn_path_is_child(self, uri, pool) or uri - return str(svn_path_uri_decode(child_path, pool)) - - def longest_ancestor(self, uri): - """Get the longest ancestor of this URI and another URI""" - pool = Pool() - return RepositoryURI(svn_path_get_longest_ancestor(self, uri, pool)) - - def __str__(self): - """Return the URI as a string""" - return self._as_parameter_ - class RemoteRepository(object): def __init__(self, url, user=None): Index: csvn/client_helpers.py =================================================================== --- csvn/client_helpers.py (revision 0) +++ csvn/client_helpers.py (revision 0) @@ -0,0 +1,167 @@ +import csvn.core as svn +from csvn.core import * +from csvn.ext.callback_receiver import CallbackReceiver + +class SvnDate(str): + + def as_apr_time_t(self): + """Return this date to an apr_time_t object""" + pool = Pool() + when = apr_time_t() + svn_time_from_cstring(byref(when), self, pool) + return when + + def as_human_string(self): + """Return this date to a human-readable date""" + pool = Pool() + return str(svn_time_to_human_cstring(self.as_apr_time_t(), pool)) + +class LogEntry(object): + """REVISION, AUTHOR, DATE, and MESSAGE are straightforward, and + contain what you expect. DATE is an SvnDate object. + + If no information about the paths changed in this revision is + available, CHANGED_PATHS will be None. Otherwise, CHANGED_PATHS + will contain a dictionary which maps every path committed + in REVISION to svn_log_changed_path_t pointers.""" + + __slots__ = ['changed_paths', 'revision', + 'author', 'date', 'message'] + + +class _LogMessageReceiver(CallbackReceiver): + + def collect(self, session, start_rev, end_rev, paths, limit, verbose, + stop_on_copy): + self.verbose = verbose + pool = Pool() + baton = c_void_p(id(self)) + receiver = svn_log_message_receiver_t(self.receive) + svn_ra_get_log(session, paths, start_rev, end_rev, + limit, verbose, stop_on_copy, receiver, + baton, pool) + + def receive(baton, changed_paths, revision, author, date, message, pool): + self = cast(baton, py_object).value + + entry = LogEntry() + + # Save information about the log entry + entry.revision = revision + entry.author = str(author) + entry.date = SvnDate(date) + entry.message = str(message) + + if self.verbose: + entry.changed_paths = Hash(POINTER(svn_log_changed_path_t), + changed_paths, dup = svn_log_changed_path_dup) + else: + entry.changed_paths = None + + self.send(entry) + receive = staticmethod(receive) + +class User(object): + + def __init__(self, username=None, password=None): + """Create a user object which represents a user + with the specified username and password.""" + + self._username = username + self._password = password + self.pool = Pool() + + def username(self): + """Return the current username. + + By default, this function just returns the username + which was supplied in the constructor, but subclasses + may behave differently.""" + return self._username + + def password(self): + """Return the current password. + + By default, this function just returns the password + which was supplied in the constructor, but subclasses + may behave differently.""" + return self._password + + def allow_access(self, requested_access, path): + """Check whether the current user has the REQUESTED_ACCESS + to PATH. + + If PATH is None, this function should check if the + REQUESTED_ACCESS is granted for at least one path + in the repository. + + REQUESTED_ACCESS is an integer which may consist of + any combination of the following fields: + svn_authz_read: The path can be read + svn_authz_write: The path can be altered + svn_authz_recursive: The other access credentials + are recursive. + + By default, this function always returns True, but + subclasses may behave differently. + + This function is used by the "Repository" class to check + permissions (see repos.py). + + FIXME: This function isn't currently used, because we + haven't implemented higher-level authz yet. + """ + + return True + + def setup_auth_baton(self, auth_baton): + + # Setup the auth baton using the default options from the + # command-line client + svn_cmdline_setup_auth_baton(auth_baton, TRUE, + self._username, self._password, NULL, TRUE, NULL, + svn_cancel_func_t(), NULL, self.pool) + + +class RepositoryURI(object): + """A URI to an object in a Subversion repository, stored internally in + encoded format. + + When you supply URIs to a RemoteClient, or a transaction""" + + def __init__(self, uri, encoded=True): + """Create a RepositoryURI object from a URI. If encoded=True, the + input string may be URI-encoded.""" + pool = Pool() + if not encoded: + uri = svn_path_uri_encode(uri, pool) + self._as_parameter_ = str(svn_path_canonicalize(uri, pool)) + + def join(self, uri): + """Join this URI and the specified relative URI, + adding a slash if necessary.""" + pool = Pool() + return RepositoryURI(svn_path_join(self, uri, pool)) + + def dirname(self): + """Get the parent directory of this URI""" + pool = Pool() + return RepositoryURI(svn_path_dirname(self, pool)) + + def relative_path(self, uri, encoded=True): + """Convert the supplied URI to a decoded path, relative to me.""" + pool = Pool() + if not encoded: + uri = svn_path_uri_encode(uri, pool) + child_path = svn_path_is_child(self, uri, pool) or uri + return str(svn_path_uri_decode(child_path, pool)) + + def longest_ancestor(self, uri): + """Get the longest ancestor of this URI and another URI""" + pool = Pool() + return RepositoryURI(svn_path_get_longest_ancestor(self, uri, pool)) + + def __str__(self): + """Return the URI as a string""" + return self._as_parameter_ +