如何将 PySVN 检出限制为特定文件类型?

How do I limit PySVN checkout to a specific filetype?

假设 SVN 服务器上的目录结构与此类似:

/ mainfolder 
../ subfolder1
   -big-file1.xlm
   -small-file1.txt
../ subfolder2
   -big-file2.xlm
   -small-file2.txt

在 Python 脚本中使用结账功能,如下所示:

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

try:
    client.checkout(svnurl()+"/mainfolder",
    './examples/pysvntest')
    print("done")   

except pysvn.ClientError as e:
    print("SVN Error occured: ", e)

如何将功能限制为仅结帐 small-file? 可以按文件类型、文件大小(或其他智能方式)

您可以使用client.ls()(或client.list())找到您需要获取的文件路径,然后过滤结果。 注意您不能签出单个文件,因此您需要使用client.export()client.cat()

下面的代码应该给你一个起点:

import pysvn

url = '...'
checkout_path = '...'
file_ext = '.txt'

client = pysvn.Client()
client.checkout(path=checkout_path, url=url, depth=pysvn.depth.empty)

files_and_dirs = client.ls(url_or_path=url)

for file_or_dir in files_and_dirs:
    if file_or_dir.kind == pysvn.node_kind.file and file_or_dir.name.endswith(file_ext):
        client.export(dest_path=checkout_path, src_url_or_path=file_or_dir.name)  # TODO: Export to the correct location. Can also use client.cat() here, to get the file content into a string