pysvn - Programmer's reference

This programmer's reference gives complete and detailed infomation on the pysvn API.

The pysvn Programmer's Guide gives an tutorial introduction to the pysvn module.

pysvn features and feature testing

This document covers pysvn version 1.6. Features offered by pysvn depend on the version of SVN that is being used. Full functionality is only available with SVN 1.6.0 or later.

Click one of the buttons below to show the pysvn API as supported by a particular version of the SVN.

Sorry you browser does not support the show API buttons. Try viewing this page in FireFox.

Showing the PySVN API supported by SVN 1.6.0. Unsupported parts of the API are show like: This.

The recommended way to test for a feature is to use the python hasattr() builtin. Working out what is and is not support from the version number information is quite complex and unnessesary. For example to test for lock and unlock support:

client = pysvn.Client()
if hasattr( client, 'lock' ):
    # use lock

pysvn module

The pysvn module has the following variables:

The pysvn module has six classes:

The following enumerations are provided:

Use python builtin dir() to list all available values in an enumeration:

    print dir( pysvn.wc_notify_action )

pysvn.Client - Subversion client interface

Interface summary:

client = pysvn.Client()
client = pysvn.Client( config_dir )

The default subversion configuration directory is used if the config_dir is omitted or set to ''.

The configuration directory is automatically created if it is missing.

A Client object can only be used on one thread at a time. If two threads attempt to call methods of Client at the same time one of the threads will get a pysvn.ClientError exception with the value 'client in use on another thread'.

Variables Callbacks Methods

Client variables

exception_style allows you to control the style of exception raised by pysvn.

commit_info_style allows you to control the style of commit_info returned by pysvn.

pysvn.Client.exception_style

exception_style is used to control how pysvn raises ClientError exceptions.

The default value, 0, makes pysvn raise exceptions as it did prior to pysvn 1.1.2.

exception_style can be set to 0 or 1, see ClientError for details of effect of the style on the exception raised.

pysvn.Client.commit_info_style

commit_info_style is used to control how pysvn return commit information.

commit_info_style can be set to 0 or 1. The default value, 0, makes pysvn return only the commit revision.

When set to 1 pysvn returns a dictionary of commit information including date, author, revision and post_commit_err.

Client callbacks

pysvn uses callback functions to allow for realtime feedback and credential handling.

callback_cancel allows you to cancel a long running subversion command.

callback_notify gives feedback as commands runs.

callback_get_log_message is called when a log message is required.

callback_get_login is called to get a username and password to access a repository.

callback_ssl_server_trust_prompt is called when using HTTPS to a server whoes certificate needs is trust verifing.

It is possible to use the Client object without setting up any calls backs. Make sure that all nessesary usernames, passwords and SSL certificate information are stored in the subversion configuration directory.

pysvn.Client.callback_cancel

import pysvn

cancel_command = False
def cancel():
    return cancel_command

client = pysvn.Client()
client.callback_cancel = cancel

The callback_cancel function is called frequently during long running commands. Return True to cause the command to cancel, return False to allow the command to continue.

pysvn.Client.callback_get_log_message

import pysvn

log_message = "reason for change"
def get_log_message():
    return rc, log_message

client = pysvn.Client()
client.callback_get_log_message = get_log_message

The callback_get_log_message is called when a log message is required to complete the current command. Return the True in rc and a log message as a string. Returning False in rc will cause the command to be cancelled. An empty log_message is not allowed and may cause the command to be cancelled.

Unicode strings cannot be handled. If you have a unicode string, convert it to UTF-8.

pysvn.Client.callback_get_login

import pysvn

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

client = pysvn.Client()
client.callback_get_login = get_login

callback_get_login is called each time subversion needs a username and password in the realm to access a repository and has no cached credentials.

The may_save parameter is true if subversion is willing to save the answers returned by the callback_get_login function.

pysvn expect the callback_get_login to return a tuple of four values (retcode, username, password, save).

pysvn.Client.callback_notify

import pysvn

def notify( event_dict ):
    return

client = pysvn.Client()
client.callback_notify = notify

The callback_notify is called as a command runs each time an interesting event occurs. The details of the event are passed to the callback_notify function as a dictionary.

The dictionary contains the following values:

pysvn.Client.callback_ssl_client_cert_password_prompt

import pysvn

def ssl_client_cert_password_prompt( realm, may_save ):
    return retcode, password, save

client = pysvn.Client()
client.callback_ssl_client_cert_password_prompt = ssl_client_cert_password_prompt

callback_ssl_client_cert_password_prompt is called each time subversion needs a password in the realm to use a client certificate and has no cached credentials.

The may_save parameter is true if subversion is willing to save the answers returned by the callback_ssl_client_cert_password_prompt function.

pysvn expect the callback_ssl_client_cert_password_prompt to return a tuple of three values (retcode, password, save).

pysvn.Client.callback_ssl_client_cert_prompt

import pysvn

def ssl_client_cert_prompt( realm, may_save ):
    return retcode, certfile, may_save

client = pysvn.Client()
client.callback_ssl_client_cert_prompt = ssl_client_cert_prompt

callback_ssl_client_cert_prompt is called each time subversion needs a client certificate.

pysvn expect the callback_ssl_client_cert_prompt to return a tuple of three values (retcode, certfile, may_save).

pysvn.Client.callback_ssl_server_prompt

import pysvn

def ssl_server_prompt( ):
    return 

client = pysvn.Client()
client.callback_ssl_server_prompt = ssl_server_prompt

NOT IMPLEMENTED - what it used for?

pysvn.Client.callback_ssl_server_trust_prompt

import pysvn

def ssl_server_trust_prompt( trust_dict ):
    return retcode, accepted_failures, save

client = pysvn.Client()
client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt

The callback_ssl_server_trust_prompt is called each time an HTTPS server presents a certificate and subversion is not sure if it should be trusted. callback_ssl_server_trust_prompt is called with information about the certificate in trust dict.

pysvn expect the callback_ssl_server_trust_prompt to return a tuple of three values (retcode, accepted_failures, save).

Client methods

add add_to_changelist annotate cat checkin checkout
cleanup copy copy2 diff diff_peg diff_summarize
diff_summarize_peg export get_adm_dir get_auth_cache get_auto_props get_changelist
get_default_password get_default_username get_interactive get_store_passwords import_ info
info2 is_adm_dir is_url list log lock
ls merge merge_peg merge_peg2 merge_peg2 mkdir
move copy2 propdel propget proplist propset
relocate remove remove_from_changelists resolved revert revpropdel
revpropget revproplist revpropset root_url_from_path set_adm_dir set_auth_cache
set_auto_props set_default_password set_default_username set_interactive set_store_passwords status
switch unlock update      

pysvn.Client.add_to_changelist

add_to_changelist( path,
                   changelist,
                   depth=QQQ,
                   changelists=[] )

TBD

depth is one of the pysvn.depth enums.

pysvn.Client.add

add( path,
     recurse=True,
     force=False,
     ignore=False,
     depth=None )
add( [path,path],
     recurse=True,
     force=False,
     ignore=True,
     depth=None )

Schedules all the files or directories specfied in the paths for addition to the repository. Set recurse to True to recursively add a directory's children. Set force to True to force operation to run. Set ignore to False to disregard default and svn:ignore property ignores. Files are added at the next checkin.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.annotate

file_annotation = \
annotate( url_or_path,
          revision_start=pysvn.Revision( opt_revision_kind.number, 0 ),
          revision_end=pysvn.Revision( opt_revision_kind.head ),
          peg_revision=pysvn.Revision( opt_revision_kind.unspecified ) )
 )

Return the annotation for each line in the url_or_path from revision_start to revision_end.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The file_annotation is a list of dictionaries. Each dictionary contains:

pysvn.Client.cat

file_text = \
cat( url_or_path,
     revision=pysvn.Revision( opt_revision_kind.head ),
     peg_revision=pysvn.Revision( opt_revision_kind.unspecified ) )

Return the contents of url_or_path for the specified revision as a string, file_text.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

pysvn.Client.checkin

revision = \
checkin( path,
        log_message,
        recurse=True,
        keep_locks=False,
        depth,
        keep_changelist,
        changelists,
        revprops )
revision = \
checkin( [path,path],
        log_message,
        recurse=True,
        keep_locks=False,
        depth,
        keep_changelist,
        changelists,
        revprops )

checkin the files in the path_list to the repository with the specifed log_message. Set recurse to True to recursively checkin a directory's children with the same log message. Set keep_locks to True to prevent locks in the path being unlocked.

checkin returns a pysvn.Revision containing the number of the checked in revision.

depth, keep_changelist, changelists, revprops TBD

pysvn.Client.checkout

revision = \
checkout( url,
          path,
          recurse=True,
          revision=pysvn.Revision( opt_revision_kind.head ),
          peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
          ignore_externals=False )

checkout the repository at url into the location specified by path. Set recurse to True to recursively check out a directory's children. Specify a revision to check out a particular version of the source tree. Set ignore_externals to True to ignore externals definitions.

peg_revision indicates in which revision url is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

checkout returns a pysvn.Revision containing the number of the checked out revision.

Note: Subversion seems to return 0 rather then the actual revision. Use a notify callback and record the revision reported for the pysvn.wc_notify_action.update_completed event. This is what the svn command does.

pysvn.Client.cleanup

cleanup( path )

Clean up any locks in the working copy at path. Usually such locks are the result of a failed or interrupted operation.

pysvn.Client.copy

copy( src_url_or_path,
      dest_url_or_path,
      src_revision=pysvn.Revision( opt_revision_kind.head ))

Duplicate something in working copy or repos, remembering history. The src_revision defaults to pysvn.Revision( opt_revision_kind.head ) if the src_path is a URL otherwise to pysvn.Revision( opt_revision_kind.working ).

src_url_or_path and dest_url_or_path can each be either a working copy (WC) path or URL:

If the destination is a URL the client_get_log_message callback must be implemented to return a log message.

pysvn.Client.copy2

copy2( sources,
       dest_url_or_path,
       copy_as_child=False,
       make_parents=False,
       revprops,
       ignore_externals=False )

Duplicate something in working copy or repos, remembering history. The src_revision defaults to pysvn.Revision( opt_revision_kind.head ) if the src_path is a URL otherwise to pysvn.Revision( opt_revision_kind.working ).

sources is a list of tuples of (url_or_path, rev), you can ommit rev by passing (url_or_path,). TBD better docs here.

revprops TBD

set ignore_externals to True to ignore externals.

src_url_or_path and dest_url_or_path can each be either a working copy (WC) path or URL:

If the destination is a URL the client_get_log_message callback must be implemented to return a log message.

pysvn.Client.diff

diff_text = \
diff( tmp_path,
      url_or_path,
      revision1=pysvn.Revision( opt_revision_kind.base ),
      url_or_path2=url_or_path,
      revision2=pysvn.Revision( opt_revision_kind.working ),
      recurse=True,
      ignore_ancestry=False,
      diff_deleted=True,
      ignore_content_type=False,
      header_encoding="",
      diff_options=[],
      depth=depth,,
      relative_to_dir=None,
      changelists=None )

Return the differences between revision1 of url_or_path and revision2 of url_or_path2. diff_text is a string containing the diff output.

diff uses tmp_path to form the filename when creating any temporary files needed. The names are formed using tmp_path + unique_string + ".tmp". For example tmp_path=/tmp/diff_prefix will create files like /tmp/diff_prefix.tmp and /tmp/diff_prefix1.tmp.

Diff output will not be generated for binary files, unless ignore_content_type is true, in which case diffs will be shown regardless of the content types.

Generated headers are encoded using header_encoding.

The list of diff_options strings are passed to the external diff program that subversion uses. Typical options are -b (ignore space changes) and -w (ignore all white space). The exact options that work depend on the version of subversion used and its configuration.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

If relative_to_dir is not None, the original_path and modified_path will have the relative_to_dir stripped from the front of the respective paths.

If relative_to_dir is not None but relative_to_dir is not a parent path of the target, an error is returned.

pysvn.Client.diff_peg

diff_text = \
diff_peg( tmp_path,
          url_or_path,
          peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
          revision_start=pysvn.Revision( opt_revision_kind.base ),
          revision_end=pysvn.Revision( opt_revision_kind.working ),
          recurse=True,
          ignore_ancestry=False,
          diff_deleted=True,
          ignore_content_type=False,
          header_encoding="",
          diff_options=[],
          depth=depth )

return the differences between two revisions of the url_or_path. diff_text is a string containing the diff output.

diff uses tmp_path to form the filename when creating any temporary files needed. The names are formed using tmp_path + unique_string + ".tmp". For example tmp_path=/tmp/diff_prefix will create files like /tmp/diff_prefix.tmp and /tmp/diff_prefix1.tmp.

Set recurse to True to recursively diff a directory's children. diff_text is a string containing the diff.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

Diff output will not be generated for binary files, unless ignore_content_type is true, in which case diffs will be shown regardless of the content types.

Generated headers are encoded using header_encoding.

The list of diff_options strings are passed to the external diff program that subversion uses. Typical options are -b (ignore space changes) and -w (ignore all white space). The exact options that work depend on the version of subversion used and its configuration.

pysvn.Client.diff_summarize

summary = \
diff_summarize( url_or_path1,
                revision1=pysvn.Revision( opt_revision_kind.base ),
                url_or_path2=url_or_path,
                revision2=pysvn.Revision( opt_revision_kind.working ),
                recurse=True,
                ignore_ancestry=False,
                depth=depth )

Produce a diff summary which lists the changed items between url_or_path1 revision1 and url_or_path2 revision2 without creating text deltas. url_or_path1 and url_or_path2 can be either working-copy paths or URLs.

The function may report false positives if ignore_ancestry is False, since a file might have been modified between two revisions, but still have the same contents.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.diff_summarize_peg

diff_text = \
diff_summarize_peg( url_or_path,
                    peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
                    revision_start=pysvn.Revision( opt_revision_kind.base ),
                    revision_end=pysvn.Revision( opt_revision_kind.working ),
                    recurse=True,
                    ignore_ancestry=False,
                    depth=depth )

Produce a diff summary which lists the changed items between the filesystem object url_or_path in peg revision peg_revision, as it changed between revision_start and revision_end. url_or_path can be either a working-copy path or URL.

If peg_revision is opt_revision_unspecified, behave identically to svn_client_diff_summarize(), using path for both of that function's url_or_path1 and url_or_path2 argments.

The function may report false positives if ignore_ancestry is False, as described in the documentation for diff_summarize().

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.export

revision = \
export( src_url_or_path,
        dest_path,
        force=False,
        revision=pysvn.Revision(),
        native_eol=None,
        ignore_externals=False,
        recurse=True,
        peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
        depth=depth )

Create an unversioned copy of the src_path at revision in dest_path. Set recurse to False to export a single file. Set ignore_externals to True to ignore externals definitions.

peg_revision indicates in which revision src_url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

  1. Exports a clean directory tree from the repository specified by URL src_url_or_path, at revision if it is given, otherwise at HEAD, into dest_path.
  2. Exports a clean directory tree from the working copy specified by src_path into dest_path. All local changes will be preserved, but files not under revision control will not be copied.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

native_eol parameter allows the line ending of files with svn:eol-style propery set to native to be overriden. Use None to use the eol-style of the Operating System, use "LF" to use "\n", "CR" to use "\r" and "CRLF" to use "\r\n".

export returns a pysvn.Revision containing the number of the checked in revision.

Note: The native_eol parameter is only available for svn 1.1.0 or later.

pysvn.Client.get_auth_cache

enabled = get_auth_cache()

return true if credential caching is enabled, otherwise return false.

pysvn.Client.get_adm_dir

name = get_adm_dir()

Returns the name of the subverion admin directory.

pysvn.Client.get_auto_props

enabled = get_auto_props()

Returns true if svn will automatically set properties when adding files, otherwise returns false.

pysvn.Client.get_changelist

changelist_list = \
get_changelist( path,
                changelist,
                depth=depth,
                changelists=[] )

TBD

The depth is one of the pysvn.depth enums.

pysvn.Client.get_default_password

password = get_default_password()

Returns None if no default is set otherwise returns the password as a string.

pysvn.Client.get_default_username

username = get_default_username()

Returns None if no default is set otherwise returns the username as a string.

pysvn.Client.get_interactive

enabled = get_interactive()

Returns true if svn will prompt for missing credential information, otherwise returns false.

pysvn.Client.get_store_passwords

enabled = get_store_passwords()

Returns true if svn will store passwords after prompting for them, otherwise returns false.

pysvn.Client.import_

revision = \
import_( path,
         url,
         log_message,
         recurse=True,
         ignore=False,
         revprops )

Commit an unversioned file or tree into the repository.

Recursively commit a copy of PATH to URL. Parent directories are created as necessary in the repository. Set ignore to False to disregard default and svn:ignore property ignores.

revprops TBD

import_ returns a pysvn.Revision containing the number of the checked in revision.

pysvn.Client.info

entry = info( path )

return information on path as a Entry object.

pysvn.Client.info2

entry_list = \
info2( url_or_path,
       revision=pysvn.Revision( opt_revision_kind.unspecified ),
       peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
       recurse=True,
       depth=depth )

return information on url_or_path as a list of (path, info_dict) tuples. To return information about a URL revision must be opt_revision_kind.head or opt_revision_kind.number.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

The info_dict contains:

Note: The info2 command is only available with svn 1.2.0 or later.

pysvn.Client.is_adm_dir

rc = \
is_adm_dir( name )

Return True is the name is an subversion admin directory.

pysvn.Client.root_url_from_path

root_url = \
    root_url_from_path( url_or_path )

Return the root URL of the repository given the url_or_path.

pysvn.Client.is_url

rc = \
is_url( url )

return True if the url is a known subversion url.

pysvn.Client.list

entries_list = \
list( url_or_path,
      peg_revision=pysvn.Revision( opt_revision_kind.unspecified ) )
      revision=pysvn.Revision( opt_revision_kind.head ),
      recurse=True,
      dirent_fields=pysvn.SVN_DIRENT_ALL,
      fetch_locks=False,
      depth=depth )

Returns a list with a tuple of information for each file in the given path at the provided revision.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

dirent_fields controls which dirent fields will return. Use pysvn.SVN_DIRENT_ALL to return all fields. Bit-wise or one of these values to return only the selected fields:

The tuple contains:

The PysvnList object contains the requested dirent fields:

The PysvnList object obtains the lock information:

pysvn.Client.lock

lock( url_or_path,
      lock_comment, 
      force=False )

lock the url_or_path with lock_comment. Set force to True to override any lock held by another user.

pysvn.Client.log

log_messages = \
log( url_or_path,
     revision_start=pysvn.Revision( opt_revision_kind.head ),
     revision_end=pysvn.Revision( opt_revision_kind.number, 0 ),
     discover_changed_paths=False,
     strict_node_history=True,
     limit=0,
     peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
     include_merged_revisions=False,
     revprops=list_of_revprop_names )

Return the log messages for the specified url_or_path between revisions start and end. Set limit to the maximum number of log messages to be returned, 0 means return all messages.

If discover_changed_paths is set, the changed_paths dictionary entry is filled with a list of changed paths. If strict_node_history is set, log entries will not cross copies.

If url_or_path no longer exists in the repos of WC then pass in a peg_revision of a revision where it did exist.

include_merged_revisions TBD

revprops is a list of strings that name the revprops to be returned.

log returns a list of log entries; each log entry is a dictionary. The dictionary contains:

pysvn.Client.ls

entries_list = \
ls( url_or_path,
    revision=pysvn.Revision( opt_revision_kind.head ),
    recurse=True,
    peg_revision=pysvn.Revision( opt_revision_kind.unspecified ) )

Use the list method in new code as it fixes performance and ambiguity problems with the ls method.

Returns a list of dictionaries for each file the given path at the provided revision.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The dictionary contains:

pysvn.Client.merge

merge( url_or_path1,
       revision1,
       url_or_path2,
       revision2,
       local_path,
       force=False,
       recurse=True,
       notice_ancestry=False,
       dry_run=False,,
       depth=depth,
       record_only=False,
       merge_options=[] )

Apply the differences between two sources to a working copy path.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

merge_options (a list of strings), is used to pass additional command line arguments to the merge processes (internal or external).

The internal subversion diff supports the following options:

pysvn.Client.merge_peg

merge_peg( url_or_path,
           revision1,
           revision2,
           peg_revision,
           local_path,
           recurse=True,
           notice_ancestry,
           force=False,
           dry_run=False,
           depth=depth,
           record_only=False,
           merge_options=[] )

Apply the differences between two sources to a working copy path.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

merge_options (a list of strings), is used to pass additional command line arguments to the merge processes (internal or external).

The internal subversion diff supports the following options:

pysvn.Client.merge_peg2

merge_peg2( sources,
            ranges_to_merge,
            peg_revision,
            tareget_wcpath,
            depth=depth,
            notice_ancestry=False,
            force=False,
            dry_run=False,
            record_only=True,
            merge_options=[] )

Apply the differences between the ranges_to_merge in sources to a working copy path, target_wcpath. ranges_to_merge is a list of tuples with the start and end revisions to be merged.

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The depth is one of the pysvn.depth enums.

merge_options (a list of strings), is used to pass additional command line arguments to the merge processes (internal or external).

The internal subversion diff supports the following options:

pysvn.Client.merge_reintegrate

merge_reintegrate( url_or_path,
                   revision,
                   local_path,
                   dry_run=False,
                   merge_options=[] )

Lump-merge all of url_or_path unmerged changes into local_path.

merge_options (a list of strings), is used to pass additional command line arguments to the merge processes (internal or external).

The internal subversion diff supports the following options:

pysvn.Client.mkdir

mkdir( url_or_path,
       log_message,
       make_parents,
       revprops )
mkdir( [url_or_path,url_or_path],
       log_message,
       make_parents,
       revprops )

Create a new directory under revision control.

url_or_path can be a list of URLs and paths

make_parents and revprops TBD

If url_or_path is a path, each directory is scheduled for addition upon the next commit.

If url_or_path is a URL, the directories are created in the repository via an immediate commit.

In both cases, all the intermediate directories must already exist.

pysvn.Client.move

move( src_url_or_path,
      dest_url_or_path,
      force=False )

Move (rename) something in working copy or HEAD revision of repository.

NOTE: this command is equivalent to a 'copy' and 'delete'.

src_path and dest_path can both be working copy (WC) paths or URLs:

If src_url_or_path is a path, each item is scheduled for deletion upon the next commit. Files, and directories that have not been committed, are immediately removed from the working copy. The command will not remove PATHs that are, or contain, unversioned or modified items; set force=True to override this behaviour.

If src_url_or_path is a URL, the items are deleted from the repository via an immediate commit.

pysvn.Client.move2

move2( sources,
       dest_url_or_path,
       move_as_child=False,
       make_parents=False,
       revprops )

Duplicate something in working copy or repos, remembering history. The src_revision defaults to pysvn.Revision( opt_revision_kind.head ) if the src_path is a URL otherwise to pysvn.Revision( opt_revision_kind.working ).

revprops TBD

src_url_or_path and dest_url_or_path can each be either a working copy (WC) path or URL:

If the destination is a URL the client_get_log_message callback must be implemented to return a log message.

pysvn.Client.propdel

rev = \
propdel( prop_name,
         url_or_path,
         revision=pysvn.Revision(),
         recurse=False,
         skip_checks=False,
         depth=depth,
         base_revision_for_url=[0 for URL, -1 for path],
         revprops )

Delete the property prop_name from url_or_path.

If skip_checks is true, do no validity checking. But if skip_checks is false, and propname is not a valid property for target, return an error, either SVN_ERR_ILLEGAL_TARGET (if the property is not appropriate for target), or SVN_ERR_BAD_MIME_TYPE (if propname is "svn:mime-type", but propval is not a valid mime-type).

The url_or_path may only be an URL if base_revision_for_url is not -1; in this case, the property will only be set if it has not changed since revision base_revision_for_url. base_revision_for_url must be -1 if url_or_path is not an URL.

The src_revision defaults to pysvn.Revision( opt_revision_kind.head ) if the src_path is a URL otherwise to pysvn.Revision( opt_revision_kind.working ).

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

revprops TBD

pysvn.Client.propget

prop_list = \
propget( prop_name,
         url_or_path,
         revision=pysvn.Revision(),
         recurse=False,
         peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
         depth=depth )

Returns a dictionary with keys of url_or_path and values of the prop_name.

The src_revision defaults to pysvn.Revision( opt_revision_kind.head ) if the url_or_path is a URL otherwise to pysvn.Revision( opt_revision_kind.working ).

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.proplist

prop_list = \
proplist( url_or_path,
          revision=pysvn.Revision(),
          recurse=False,
          peg_revision=pysvn.Revision( opt_revision_kind.unspecified ),
          depth=depth )

Returns a list of tuples (path, prop_dict). The prop_dict contains the prop_names and their values if set on the path.

The src_revision defaults to pysvn.Revision( opt_revision_kind.head ) if the url_or_path is a URL otherwise to pysvn.Revision( opt_revision_kind.working ).

peg_revision indicates in which revision url_or_path is valid. If peg_revision.kind is opt_revision_kind.unspecified, then it defaults to opt_revision_kind.head for URLs or opt_revision_kind.working for WC targets.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.propset

commit_info = \
propset( prop_name,
         prop_value,
         url_or_path,
         revision=pysvn.Revision(),
         recurse=False,
         skip_checks=False,
         depth=depth,
         base_revision_for_url=[0 for URL, -1 for path],
         allow_unver_obstructions=False,
         revprops )

Set the property prop_name to prop_value in url_or_path.

If skip_checks is true, do no validity checking. But if skip_checks is false, and propname is not a valid property for target, return an error, either SVN_ERR_ILLEGAL_TARGET (if the property is not appropriate for target), or SVN_ERR_BAD_MIME_TYPE (if propname is "svn:mime-type", but propval is not a valid mime-type).

The revision defaults to pysvn.Revision( opt_revision_kind.head ) if the url_or_path is a URL otherwise to pysvn.Revision( opt_revision_kind.working ).

The url_or_path may only be an URL if base_revision_for_url is not -1; in this case, the property will only be set if it has not changed since revision base_revision_for_url. base_revision_for_url must be -1 if url_or_path is not an URL.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

If allow_unver_obstructions is False then the update will abort if there are any unversioned obstructing items.

revprops TBD

pysvn.Client.relocate

relocate( from_url,
          to_url,
          path,
          recurse=True,
          depth=depth )

Relocate the working copy from from_url to to_url of path.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.remove

remove( url_or_path_list,
        force=False,
        keep_local=False,
        revprops )

If url_or_path is a path, each item is scheduled for deletion upon the next commit. Files, and directories that have not been committed, are immediately removed from the working copy. The command will not remove paths that are, or contain, unversioned or modified items; set force=True to override this behaviour.

Set keep_local to True to prevent the local file from being delete.

revprops TBD

If url_or_path is a URL, the items are deleted from the repository via an immediate commit.

pysvn.Client.remove_from_changelists

remove_from_changelists( path,
                         changelist,
                         depth=pysvn.depth.infinite,
                         changelists=[] )

TBD

pysvn.Client.resolved

resolved( path,
          recurse=True,
          depth=depth )

Mark the conflicted file at path as resolved.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.revert

revert( path,
        recurse=False,
        depth=depth )
revert( [path,path],
        recurse=False,
        depth=depth )

Discard any changes in the working copy at path. Set recurse to True to recursively revert a directory's children.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

pysvn.Client.revpropdel

rev = \
revpropdel( prop_name,
            url,
            revision=pysvn.Revision( opt_revision_kind.head ),
            force=False )

Delete the revision property prop_name from url.

pysvn.Client.revpropget

rev_prop = \
revpropget( prop_name,
            url,
            revision=pysvn.Revision( opt_revision_kind.head ) )

Returns a tuple (rev, prop_val) where the prop_val contains the revision property value.

pysvn.Client.revproplist

rev_prop_dict = \
revproplist( url,
             revision=pysvn.Revision( opt_revision_kind.head ) )

Returns a tuple (revision, prop_dict) where the prop_dict contains the revision properies and their values.

pysvn.Client.revpropset

rev = \
revpropset( prop_name,
            prop_value,
            url,
            revision=pysvn.Revision( opt_revision_kind.head ),
            force=False )

set the revision property prop_name to prop_value in path. The revision updated is returned.

pysvn.Client.set_adm_dir

set_adm_dir( name )

Set the name of the subverion admin directory. ".svn" is the normal admin dir use and "_svn" is used on Windows to work around problems with .NET.

pysvn.Client.set_auth_cache

set_auth_cache( enable )

When enable is True subversion will remember authentication credentials in the configuration directory.

pysvn.Client.set_auto_props

set_auto_props( enable )

When enabled, subversion will automatically set properties when adding files; otherwise when disabled it will not.

pysvn.Client.set_default_password

set_default_password( password )

Set the default password to be used if there is no stored password.

pysvn.Client.set_default_username

set_default_username( username )

Set the default username to be used if there is no stored username.

pysvn.Client.set_interactive

set_interactive( enable )

When enable is True subversion will prompt for authentication credentials when there are no valid store credentials.

pysvn.Client.set_store_passwords

set_store_passwords( enable )

When enable is True subversion will store any passwords that subversion prompted for.

pysvn.Client.status

status_list = \
status( path,
        recurse=True,
        get_all=True,
        update=False,
        ignore=False,
        ignore_externals=False,
        depth=depth )

If path is a directory status is returned for all files in the directory in status_list. If path is a single file status is returned for that single file in status_list. Set ignore_externals to True to ignore externals definitions.

The status_list is a list of PysvnStatus objects.

Options:

pysvn.Client.switch

switch( path,
        url,
        recurse=True,
        revision=pysvn.Revision( opt_revision_kind.head ),
        depth=depth,
        peg_revision=revision,
        depth_is_sticky=False,
        ignore_externals=False,
        allow_unver_obstructions=False )

Update the working copy to a different URL.

The depth can be used as in place of recurse. depth is one of the pysvn.depth enums.

If depth_is_sticky is set and depth is not svn_depth_unknown, then in addition to switching PATH, also set its sticky ambient depth value to @a depth.

If ignore_externals is set, do not process externals definitions as part of this operation.

If allow_unver_obstructions is True then the switch tolerates existing unversioned items that obstruct added paths. Only obstructions of the same type (file or dir) as the added item are tolerated. The text of obstructing files is left as-is, effectively treating it as a user modification after the switch. Working properties of obstructing items are set equal to the base properties.

If allow_unver_obstructions is False then the switch will abort if there are any unversioned obstructing items.

  1. Update the working copy to mirror a new URL. This behaviour is a superset of "svn update". Note: this is the way to move a working copy to a new branch.
  2. Reconnect the working copy when the repository URL has changed.

pysvn.Client.unlock

unlock( url_or_path,
        force=False )

Unlock the url_or_path. Set force to True to unlock any lock held by another user.

pysvn.Client.update

revision = \
update( path,
        recurse=True,
        revision=pysvn.Revision( opt_revision_kind.head ),
        ignore_externals=False,
        depth=depth )

Update the file in the working copy at path to the specified revision. Set recurse to True to recursively update a directory's children. Set ignore_externals to True to ignore externals definitions.

path can be a single path string or a list of path strings.

The depth can be used in place of recurse. depth is one of the pysvn.depth enums. Use pysvn.depth.unknown to update all files and folders in the working copy honoring the current depths. Use pysvn.depth.infinity to upadate all files and folders adding any that are missing ignoring the current depths.

update returns a pysvn.Revision containing the number of the revision the working copy was updated to.

This command is typically used to get the latest changes from the repository.

Note: updating to an older revision does not change the current revision. To make the current version identical to an older revision, use a merge followed by a commit.

pysvn.Transaction - Subversion transaction interface

Interface summary:

transaction = pysvn.Transaction()
transaction = pysvn.Transaction( repos_path, transaction_name )

The Transaction object allows you to implement hook code for the SVN repository. The pre-commit and pre-revprop-change hooks are the only hooks that are currently appropriate in SVN. See the SVN documentation for details on hook scripts.

A Transaction object can only be used on one thread at a time. If two threads attempt to call methods of Transaction at the same time one of the threads will get a pysvn.TransactionError exception with the value 'transaction in use on another thread'.

Transaction methods

cat changed    
propdel propget proplist propset
revpropdel revpropget revproplist revpropset

pysvn.Transaction.cat

file_text = \
cat( path )

Return the contents of path as a string, file_text.

pysvn.Transaction.changed

file_text = \
changed( [copy_info=False] )

Return a dict of all changes in the transaction. The keys in the dict are the path names and the values are tuples contraining action, kind, text_mod, prop_mod.

The optional copy_info parameter when True will return the copy from revision and copy from path information.

pysvn.Transaction.propdel

propdel( prop_name,
         path )

Delete the property prop_name from path in the transaction.

pysvn.Transaction.propget

prop_value = \
propget( prop_name,
         path )

Returns the prop_value as a string or None if the prop_name is not in the transaction.

pysvn.Transaction.proplist

prop_dict = \
proplist( path )

Returns a prop_dict. The prop_dict contains the prop_names and their values if set on the path in the transaction.

pysvn.Transaction.propset

propset( prop_name,
         prop_value,
         path )

Set the property prop_name to prop_value in path in the transaction.

pysvn.Transaction.revpropdel

revpropdel( prop_name )

Delete the revision property prop_name in the transaction.

pysvn.Transaction.revpropget

prop_val = \
revpropget( prop_name )

Returns the prop_val with the revision property value or None if not set in the transaction.

pysvn.Transaction.revproplist

prop_dict = \
revproplist()

Returns a prop_dict where the prop_dict contains the revision properies and their values in the transaction.

pysvn.Transaction.revpropset

rev = \
revpropset( prop_name,
            prop_value )

set the revision property prop_name to prop_value in path in the transaction. The revision updated is returned.

pysvn.Revision - subversion revision

The Revision object has three member variables:

Interface summary:

import pysvn
import time

revhead = pysvn.Revision( pysvn.opt_revision_kind.head )
revdate = pysvn.Revision( pysvn.opt_revision_kind.date, time.time() )
revnum = pysvn.Revision( pysvn.opt_revision_kind.number, 4721 )

pysvn.ClientError - Exception class raised by client commands on error

ClientError exception is raised when any of the subversion functions called by pysvn return an error.

The Client.exception_style variable controls the information stored in the ClientError object.

exception_style = 0

The args property is set to a single string parameter containing the whole error message. '\n' is used to seperate message parts.

Use str() to get the string description of the exception raised by pysvn.

import pysvn

client = pysvn.Client()
client.exception_style = 0
try:

    client.update( '.' )
except pysvn.ClientError, e:
    # convert to a string
    print str(e)
    # or access the string in args directly
    print e.args

exception_style = 1

The arg property is set to a tuple contain two values.

arg[0] is set to a string parameter containing the whole error message. '\n' is used to seperate message parts.

arg[1] is set to a list of tuples containing the message string and the error code. The error code values are defined by SVN and APR.

import pysvn

client = pysvn.Client()
client.exception_style = 1
try:

    client.update( '' )
except pysvn.ClientError, e:
    # print the whole message
    print e.args[0]
    # or process the error list
    for message, code in e.args[1]:
        print 'Code:',code,'Message:',message

pysvn.PysvnStatus - subversion status object

Each status object has the following fields:

pysvn.PysvnEntry - subversion entry object

pysvn.opt_revision_kind - subversion revision number kind enumeration

pysvn.wc_notify_action - subversion notification callback action enumeration

pysvn.wc_status_kind - subversion status kind enumeration

pysvn.wc_merge_outcome - subversion merge outcome enumeration

pysvn.wc_notify_state - subversion notify callback state enumeration

pysvn.wc_schedule - subversion status schedule enumeration

pysvn.node_kind - subversion node kind enumeration

pysvn.depth - subversion depth enumeration

Copyright © 2004-2009 Barry A. Scott. All rigths reserved.