def _init_client(self): self.client_ctx = client.Client() self.client_ctx.auth = Auth([ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider()]) self.client_ctx.log_msg_func = self.log_message_func
def test_commit_start(self): self.build_tree({"dc/foo": None}) self.client = client.Client(auth=ra.Auth([ra.get_username_provider()]), log_msg_func=lambda c: "Bmessage") self.client.add("dc/foo") self.client.commit(["dc"]) r = ra.RemoteAccess(self.repos_url) revprops = r.rev_proplist(1) self.assertEqual("Bmessage", revprops["svn:log"])
def __init__( self, remote_url: str, origin_url: str, local_dirname: str, max_content_length: int, from_dump: bool = False, ): self.remote_url = remote_url.rstrip("/") self.origin_url = origin_url self.from_dump = from_dump auth = Auth([get_username_provider()]) # one client for update operation self.client = client.Client(auth=auth) if not self.remote_url.startswith("file://"): # use redirection URL if any for remote operations self.remote_url = self.info(self.remote_url).url # one connection for log iteration self.conn_log = self.remote_access(auth) # another for replay self.conn = self.remote_access(auth) self.local_dirname = local_dirname local_name = os.path.basename(self.remote_url) self.local_url = os.path.join(self.local_dirname, local_name).encode("utf-8") self.uuid = self.conn.get_uuid().encode("utf-8") self.swhreplay = replay.Replay( conn=self.conn, rootpath=self.local_url, svnrepo=self, temp_dir=local_dirname, ) self.max_content_length = max_content_length self.has_relative_externals = False self.has_recursive_externals = False self.replay_started = False # compute root directory path from the remote repository URL, required to # properly load the sub-tree of a repository mounted from a dump file repos_root_url = self.info(origin_url).repos_root_url self.root_directory = origin_url.rstrip("/").replace( repos_root_url, "", 1)
def init_ra_and_client(self): """ Initializes the RA and client layers. With the SWIG bindings, getting unified diffs runs the remote server sometimes runs out of open files. It is not known whether the Subvertpy is affected by this. """ def getclientstring(): return 'hgsubversion' # TODO: handle certificate authentication, Mercurial style def getpass(realm, username, may_save): return self.username or username, self.password or '', False def getuser(realm, may_save): return self.username or '', False providers = ra.get_platform_specific_client_providers() providers += [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_username_prompt_provider(getuser, 0), ra.get_simple_prompt_provider(getpass, 0), ] auth = ra.Auth(providers) if self.username: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, self.password) self.remote = ra.RemoteAccess(url=self.svn_url, client_string_func=getclientstring, auth=auth) self.client = client.Client() self.client.auth = auth
def setUp(self): super(TestClient, self).setUp() self.repos_url = self.make_client("d", "dc") self.client = client.Client(auth=ra.Auth([ra.get_username_provider()]))
#!/usr/bin/python # Demonstrates how to do access the working tree using subvertpy import os from subvertpy import client, repos, wc from subvertpy.ra import Auth, get_username_provider # Create a repository repos.create("tmprepo") c = client.Client(auth=Auth([get_username_provider()])) c.checkout("file://" + os.getcwd() + "/tmprepo", "tmpco", "HEAD") w = wc.WorkingCopy(None, "tmpco") print(w) entry = w.entry("tmpco") print(entry.revision) print(entry.url)
class SubversionRepo(object): """Wrapper for a Subversion repository. This wrapper uses Subvertpy, an alternate set of bindings for Subversion that's more pythonic and sucks less. See earlier in this file for version requirements. Note that password stores do not work, the parameter is only here to ensure that the API is the same as for the SWIG wrapper. """ def __init__(self, url='', username='', password='', head=None, password_stores=None): parsed = common.parse_url(url, username, password) # --username and --password override URL credentials self.username = parsed[0] self.password = parsed[1] self.svn_url = parsed[2] self.init_ra_and_client() self.svn_url = self.remote.get_url() self.uuid = self.remote.get_uuid() self.root = self.remote.get_repos_root() assert self.svn_url.startswith(self.root) # *will* have a leading '/', would not if we used get_repos_root2 self.subdir = self.svn_url[len(self.root):] if not self.subdir or self.subdir[-1] != '/': self.subdir += '/' # the RA interface always yields quoted paths, but the editor interface # expects unquoted paths self.subdir = urllib.unquote(self.subdir) self.hasdiff3 = True self.autoprops_config = common.AutoPropsConfig() def init_ra_and_client(self): """ Initializes the RA and client layers. With the SWIG bindings, getting unified diffs runs the remote server sometimes runs out of open files. It is not known whether the Subvertpy is affected by this. """ def getclientstring(): return 'hgsubversion' def simple(realm, username, may_save): return _prompt.simple(realm, username, may_save) def username(realm, may_save): return _prompt.username(realm, may_save) def ssl_client_cert(realm, may_save): return _prompt.ssl_client_cert(realm, may_save) def ssl_client_cert_pw(realm, may_save): return _prompt.ssl_client_cert_pw(realm, may_save) def ssl_server_trust(realm, failures, cert_info, may_save): creds = _prompt.ssl_server_trust(realm, failures, cert_info, may_save) if creds is None: # We need to reject the certificate, but subvertpy doesn't # handle None as a return value here, and requires # we instead return a tuple of (int, bool). Because of that, # we return (0, False) instead. creds = (0, False) return creds providers = ra.get_platform_specific_client_providers() providers += [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ] if _prompt: providers += [ ra.get_simple_prompt_provider(simple, 2), ra.get_username_prompt_provider(username, 2), ra.get_ssl_client_cert_prompt_provider(ssl_client_cert, 2), ra.get_ssl_client_cert_pw_prompt_provider(ssl_client_cert_pw, 2), ra.get_ssl_server_trust_prompt_provider(ssl_server_trust), ] auth = ra.Auth(providers) if self.username: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, self.password) try: self.remote = ra.RemoteAccess(url=self.svn_url, client_string_func=getclientstring, auth=auth) except SubversionException, e: # e.child contains a detailed error messages msglist = [] svn_exc = e while svn_exc: if svn_exc.args[0]: msglist.append(svn_exc.args[0]) svn_exc = svn_exc.child msg = '\n'.join(msglist) raise common.SubversionConnectionException(msg) self.client = client.Client() self.client.auth = auth