Python Checkout Subversion repo via PySVN

Python Checkout Subversion repo via PySVN

Working with Subversion (SVN) on Python can be easy with the use of PySVN.

PySVN is an extension for Python which can be installed as a module/extension.

Install PySVN

PySVN is a neat extension which makes the interaction of Python with Subversion (SVN) very easy. You can find more details about PySVN here

On Fedora based systems you can install PySVN using yum.

[[email protected] ~]# yum install pysvn

You can also download the source code for PySVN and compile it on your system. The source code can be found here

Python Checkout Subversion repo via PySVN

Once you have PySVN you can have a small function in Python which will checkout the repository from Subversion (SVN).

Here’s a small script which will perform this task:

import pysvn

def checkOut(svn_url,dest_dir):
    client = pysvn.Client()

The above function should work if there are credentials stored locally in the ~/.subversion directory. However, if there aren’t then you need to add callback_get_login to this code.

Here’s the example of it.

import pysvn

def getLogin(realm, username, may_save):
    svn_user = 'USER'
    svn_pass = 'Password'
    return True, svn_user, svn_pass, False

def checkOut(svn_url,dest_dir):
    client = pysvn.Client()
    client.callback_get_login = getLogin


Python Checkout Subversion repo via PySVN

1 Comment

  • Pavel

    September 25, 2015 at 5:18 pm Reply

    what about https connection ?
    could you show me example 🙂
    i had tried do next:

    def get_login(username, save, password,retcode):
    return retcode, username, password, save

    def ssl_server_trust_prompt(trust_dict):
    return True, 0, True

    client = pysvn.Client()
    client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt
    client.callback_get_login = get_login(username=’USER’,save=False,retcode=True,password=’passwd’)

    but i got error : AttributeError: expecting None or a callable object

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.