Subversion Command-Line Wrapper (svn)

1.0.1 · active · verified Thu Apr 16

The `svn` library by dsoprea is an intuitive Python wrapper for the Subversion (SVN) command-line client, compatible with Python 2.7 and 3.3+. It provides a lightweight interface for common SVN operations such as listing, getting info, logging, checking out, exporting, adding, committing, updating, and diffing. The library itself wraps the `svn` command-line executable, which must be installed separately on the system. The current version is 1.0.1, with its last release in February 2020.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `svn.remote.RemoteClient` to check out a remote Subversion repository. It then uses `svn.local.LocalClient` to retrieve information about the newly created working copy. Remember to replace placeholder URLs and paths, and handle credentials as needed.

import svn.remote
import os

# Example: Checkout a remote repository
# Replace with your actual repository URL and desired local path
repo_url = os.environ.get('SVN_REPO_URL', 'https://example.com/svn/myproject/trunk')
local_path = os.environ.get('SVN_LOCAL_PATH', '/tmp/myproject_working_copy')

if not os.path.exists(local_path):
    print(f"Checking out '{repo_url}' to '{local_path}'...")
    try:
        r = svn.remote.RemoteClient(repo_url)
        # For repositories requiring credentials:
        # r = svn.remote.RemoteClient(repo_url, username='myuser', password='mypassword')
        r.checkout(local_path)
        print("Checkout successful.")

        # Example: Get info about the checked out working copy
        local_client = svn.local.LocalClient(local_path)
        info = local_client.info()
        print("\nWorking copy info:")
        for key, value in info.items():
            print(f"  {key}: {value}")

    except svn.exception.SvnException as e:
        print(f"SVN Error: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
else:
    print(f"'{local_path}' already exists. Skipping checkout.")
    print("You can use svn.local.LocalClient to interact with it.")

view raw JSON →