2009-09-19 59 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)