2009-09-19 58 views

回答

1

这看起来像一个非常完整的文档:

http://pysvn.tigris.org/docs/pysvn_prog_ref.html

而且这里有几个例子:

http://svn.apache.org/repos/asf/subversion/trunk/tools/examples/

+6

pysvn是一组不同的python绑定比我想要使用的那些。但这些例子可能有用。 – retracile 2009-09-19 16:42:20

+0

+1 svnshell.py将会非常有用。但是我没有看到与结账和合并有很大关系,所以我仍然在寻找更多。 – retracile 2009-09-19 16:56:06

1

如果你从源代码编译的Subversion Subversion的Python绑定不自动包含。你必须专门构建并包含它们。幸运的是,您可以在安装Subversion之后执行此操作。绑定的来源包含在Subversion源代码中。

这些指令适用于红帽企业Linux上的Subversion 1.5.9和Python 2.4.3,但它们应该很容易被破解,用于最新版本的Subversion和Python以及通用的unix安装。从http://downloads.sourceforge.net/swig

tar -xvf swig-<version>.tar.gz 
cd swig-<version> 

首先,下载痛饮在这一点上,你必须做出决定。您可以为所有支持的语言安装swig,或者您可以根据需要进行安装。 “检查”可能需要长达一个小时才能运行,并且可能由于您不关心的语言错误而失败。

如果你想使用所有支持的语言运行:

./configure 

如果你想将范围缩小到只蟒蛇,运行:

./configure --with-python=/usr/local/bin/python2.4 --without-perl --without-ruby --without-php4 

接下来,运行:

make 

如果您选择完全安装,请运行:

make -k check 

如果作用域下降到只有Python中,你只需要运行蟒蛇测试:

make check-python-examples 
make check-python-test-suite 

如果一切正常,你就可以安装痛饮:

使安装

从这里开始,安装Subversion python绑定应该相当简单:

tar -xvf subversion-1.5.9.tar.gz --gzip 
cd subversion-1.5.9 
make swig-py 
make install-swig-py 
touch /usr/lib64/python2.4/site-packages/svn-python.pth 
echo /usr/local/lib/svn-python > /usr/lib64/python2.4/site-packages/svn-python.pth 

一如既往,您的里程可能会有所不同,具体取决于您的具体版本和体系结构。祝你好运。

+5

虽然这可能对那些正在查找有关如何安装绑定的信息有帮助,但这并不能解决有关使用绑定的问题。我正在寻找API和编程文档,而不是安装帮助。 – retracile 2011-09-09 14:11:30

5

只是想在这里添加一点澄清。

感谢上述两个答案(@BenjaminWohlwend@Logan),我意识到Subversion有不止一套Python绑定/接口;我这样做对我的Ubuntu 11.04中:

$ apt-cache search '[Ss]vn|[Ss]ubversion' | grep -i python 
python-svn - A(nother) Python interface to Subversion 
python-svn-dbg - A(nother) Python interface to Subversion (debug extension) 
python-subversion - Python bindings for Subversion 
python-subversion-dbg - Python bindings for Subversion (debug extension) 
python-opster - a python command line parsing speedster 
python-py - Advanced Python testing tool and networking lib 
python-rope - Python refactoring library 
python-subvertpy - Alternative Python bindings for Subversion 

我们可以看一下Debian软件包文件列表,以确定哪些库,这些参考;因此,我们有:

...我还发现了另一个存储库中的:

链接http://svn.apache.org/repos/asf/subversion(这是我从@BenjaminWohlwend了)显然是Apache软件基金会(ASF?)Subversion的源代码本身Subversion库。

OP对文档的追求似乎与python-subversion(或SWIG绑定(或libsvn);其源代码构建指令位于@Logan的帖子中有关。除了bindings/swig/python/README之外,我找不到OP中已经提到的svn.developer: Using the APIs更好的文档来源;它解释了如何SWIG由C产生的Python接口:

翻译参数列表

的SWIG绑定的东西的参数,减少法律去像
这样:

- The module prefix can be omitted. o: 

    void *some_C_function = svn_client_foo; 

    becomes: 

    import svn.client 
    func = svn.client.foo 

[... ]

然后,可以查找,例如,svn/core.py,并找到函数(和“明确定义的符号”),如svn_mergeinfo_merge;注意core.py进口libsvn.core - 其中libsvn可能是指从C文件libsvn_swig_py/swigutil_py.c构建的共享对象(.so)文件。

然后,我们可以查找svn_mergeinfo_merge,并找到一个提交消息,如SVNSearch: Subversion (commit 23570 05.03.2007),它指的是那个函数,和一个svn_mergeinfo.h;查找该文件进一步,我们发现它在ASF库:svn_mergeinfo.h,这的确包含:

/** Like svn_mergeinfo_merge2, but uses only one pool. 
* 
* @deprecated Provided for backward compatibility with the 1.5 API. 
*/ 
SVN_DEPRECATED 
svn_error_t * 
svn_mergeinfo_merge(svn_mergeinfo_t mergeinfo, 
        svn_mergeinfo_t changes, 
        apr_pool_t *pool); 

看到DEPRECATED那里,它在这里可能是很好的参考svn commit: r1175903 (Mon Sep 26 2011)

  • 颠覆/libsvn_subr/mergeinfo.c

    (svn_mergeinfo_merge2):新的。

    (svn_mergeinfo_merge):转移到deprecated.c。

    (svn_mergeinfo_catalog_merge):使用新的API。

那就是 - 特定功能已被弃用,在2011年 - 因此希望,一个人的Python的SVN绑定和SVN安装应符合......

0

希望它与另一篇文章重新确定:python-subversion :我想试试Example 8.3. A Python status crawler - Using the APIs (svnbook)。在Ubuntu 11.04上,Python 2.7,svn_client_status2在具有UTF-8字符的文件名上崩溃,出现“错误(22):将目录'路径'中的条目转换为UTF-8” - 解决方法是在任何之前调用setlocale调用这个函数。

我也意识到在Python API中有svn_client_status3svn_client_status4; svn_client_status3有一个稍微不同的呼叫,也需要setlocale。但是,svn_client_status4不应该使用 - 它segfaults,因为它需要一个Python无法提供的结构参数;欲了解更多信息,请参阅#16027750 Debugging: stepping through Python script using gdb?

把它包起来,这里是例8。3与使用svn_client_status3区域设置 - 并且不会崩溃我的系统上(甚至在使用UTF-8字符的文件名):

#!/usr/bin/env python 

# modified from: 
# http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html 
# does the same as `svn status`, and is marked: 
"""Crawl a working copy directory, printing status information.""" 

# tested on Python 2.7, Ubuntu Natty 11.04; needs: 
# sudo apt-get install python-subversion 

import locale 
print locale.getlocale() # (None, None) - in C: ANSI_X3.4-1968 
locale.setlocale(locale.LC_ALL, '') # would print en_US.UTF-8 
print locale.getlocale() # NOW it is ('en_US', 'UTF-8') 

import sys 
import os.path 

import getopt 
import svn.core, svn.client, svn.wc 


def generate_status_code(status): 
    """Translate a status value into a single-character status code, 
    using the same logic as the Subversion command-line client.""" 
    code_map = { svn.wc.svn_wc_status_none  : ' ', 
       svn.wc.svn_wc_status_normal  : ' ', 
       svn.wc.svn_wc_status_added  : 'A', 
       svn.wc.svn_wc_status_missing  : '!', 
       svn.wc.svn_wc_status_incomplete : '!', 
       svn.wc.svn_wc_status_deleted  : 'D', 
       svn.wc.svn_wc_status_replaced : 'R', 
       svn.wc.svn_wc_status_modified : 'M', 
       svn.wc.svn_wc_status_merged  : 'G', 
       svn.wc.svn_wc_status_conflicted : 'C', 
       svn.wc.svn_wc_status_obstructed : '~', 
       svn.wc.svn_wc_status_ignored  : 'I', 
       svn.wc.svn_wc_status_external : 'X', 
       svn.wc.svn_wc_status_unversioned : '?', 
      } 
    return code_map.get(status, '?') 


def do_status(wc_path, verbose): 
    # Build a client context baton. 
    ctx = svn.client.svn_client_ctx_t() 

    def _status_callback(path, status): 
     """A callback function for svn_client_status.""" 

     # Print the path, minus the bit that overlaps with the root of 
     # the status crawl 
     text_status = generate_status_code(status.text_status) 
     prop_status = generate_status_code(status.prop_status) 
     print '%s%s %s' % (text_status, prop_status, path) 

    # Do the status crawl, using _status_callback() as our callback function. 
    revision = svn.core.svn_opt_revision_t() 
    revision.type = svn.core.svn_opt_revision_head 
    #~ svn.client.svn_client_status2(wc_path, revision, _status_callback, 
           #~ svn.core.svn_depth_infinity, verbose, 
           #~ 0, 0, 1, ctx) 
    svn.client.svn_client_status3(wc_path, revision, _status_callback, 
           svn.core.svn_depth_infinity, verbose, 
           0, 0, 1,(), ctx) 
    # DO NOT USE svn_client_status4! (needs a C struct argument) 


def usage_and_exit(errorcode): 
    """Print usage message, and exit with ERRORCODE.""" 
    stream = errorcode and sys.stderr or sys.stdout 
    stream.write("""Usage: %s OPTIONS WC-PATH 
Options: 
    --help, -h : Show this usage message 
    --verbose, -v : Show all statuses, even uninteresting ones 
""" % (os.path.basename(sys.argv[0]))) 
    sys.exit(errorcode) 

if __name__ == '__main__': 
    # Parse command-line options. 
    try: 
    opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose"]) 
    except getopt.GetoptError: 
    usage_and_exit(1) 
    verbose = 0 
    for opt, arg in opts: 
    if opt in ("-h", "--help"): 
     usage_and_exit(0) 
    if opt in ("-v", "--verbose"): 
     verbose = 1 
    if len(args) != 1: 
    usage_and_exit(2) 

    # Canonicalize the repository path. 
    wc_path = svn.core.svn_path_canonicalize(args[0]) 

    # Do the real work. 
    try: 
    do_status(wc_path, verbose) 
    except svn.core.SubversionException, e: 
    sys.stderr.write("Error (%d): %s\n" % (e.apr_err, e.message)) 
    sys.exit(1)