【问题标题】:subversion python bindings documentation? [closed]颠覆 python 绑定文档? [关闭]
【发布时间】:2009-09-19 16:32:18
【问题描述】:

在哪里可以找到使用 subversion python 绑定的好介绍?

我发现one section in the svnbook 正在谈论它;还有一些basic examples from 1.3

有没有更彻底和最新的东西?

【问题讨论】:

    标签: python svn documentation


    【解决方案1】:

    只是想在这里添加一点说明。

    感谢以上两个答案(@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 获得)显然是用于Subversion 源代码本身的Apache Software Foundation (asf?) Subversion 存储库。

    OP 对文档的追求似乎与 python-subversion(或 SWIG 绑定(或 libsvn)有关;其从源代码构建的说明在 @Logan 的帖子中。我找不到更好的文档源来自 OP 中已经提到的svn.developer: Using the APIs,除了bindings/swig/python/README;它解释了 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)可能还不错:

    • subversion/libsvn_subr/mergeinfo.c

      (svn_mergeinfo_merge2):新的。

      (svn_mergeinfo_merge):移至 deprecated.c。

      (svn_mergeinfo_catalog_merge):使用新的 API。

    也就是说 - 该特定功能已在 2011 年被弃用 - 所以希望一个人的 Python SVN 绑定和 SVN 安装应该匹配......

    【讨论】:

      【解决方案2】:

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

      这些说明适用于 Red Hat Enterprise Linux 上的 Subversion 1.5.9 和 Python 2.4.3,但对于最新版本的 Subversion 和 Python 以及通用 unix 安装,它们应该很容易破解。

      首先,从http://downloads.sourceforge.net/swig下载swig

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

      此时您必须做出决定。您可以为所有受支持的语言安装 swig,也可以根据需要安装。 'make check' 可能需要一个小时才能运行,并且可能由于您不关心的语言的错误而失败。

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

      ./configure 
      

      如果您想将范围缩小到 python,请运行:

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

      接下来,运行:

      make
      

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

      make -k check
      

      如果您只限于 python,您只需要运行 python 测试:

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

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

      进行安装

      从这里开始,安装 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
      

      与往常一样,您的里程可能会因您的特定版本和架构而异。祝你好运。

      【讨论】:

      • 虽然这可能对那些正在寻找有关如何安装绑定的信息的人有所帮助,但这并不能解决我关于使用绑定的问题。我正在寻找 API 和编程文档,而不是安装帮助。
      【解决方案3】:

      【讨论】:

      • pysvn 是一组与我想要使用的不同的 python 绑定。但这些例子可能有用。
      • +1 svnshell.py 将非常有用。但我没有看到太多与结帐和合并相关的内容,所以我仍在寻找更多。
      【解决方案4】:

      希望另一个帖子没问题回复:python-subversion:我想试试Example 8.3. A Python status crawler - Using the APIs (svnbook)。在 Ubuntu 11.04、Python 2.7 上,svn_client_status2 在带有 UTF-8 字符的文件名上崩溃,并显示“Error (22): Error convert entry in directory 'path' to UTF-8” - 解决方案这是在调用此函数之前调用setlocale

      我还意识到 Python API 中有 svn_client_status3svn_client_status4svn_client_status3 调用稍有不同,同样需要setlocale。然而,svn_client_status4 不应该被使用——它是段错误的,因为它需要一个 Python 无法提供的 struct 参数;有关更多信息,请参阅#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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-10-08
        • 1970-01-01
        • 2013-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-22
        相关资源
        最近更新 更多