Python distutils - 带过滤器的copy_tree

发布于 2024-08-06 17:35:35 字数 195 浏览 4 评论 0原文

我想将数据目录复制到我的分发目录中。 copy_tree 做得很好。但是,该项目也是一个 svn 存储库,我不希望发行版拥有数据目录拥有的所有 .svn 文件。有没有简单的方法来执行不包括 .svn 文件的 copy_tree ,或者我应该编写自己的递归目录副本?我觉得以前肯定有人遇到过这个问题。

I want to copy a data directory into my distribution dir. copy_tree does this just fine. However, the project is also an svn repository, and I don't want the distribution to have all the .svn files that the data dir has. Is there any easy way to do a copy_tree excluding the .svn files, or should I just write my own recursive dir copy? I feel someone must have had this issue before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转身泪倾城 2024-08-13 17:35:35

我刚刚使用了 shutdownttree.copytree,它需要一个ignore kwd arg。

I just used shutil.copytree, which takes an ignore kwd arg.

风流物 2024-08-13 17:35:35

试试这个代码片段:

from distutils import file_util, dir_util

orig_copy_file = file_util.copy_file
orig_copy_tree = dir_util.copy_tree

def my_copy_file(src, *args, **kwargs):
    if src.endswith('.ext'):
        return
    orig_copy_file(src, *args, **kwargs)

def my_copy_tree(src, *args, **kwargs):
    if src.endswith('foldername'):
        return []
    return orig_copy_tree(src, *args, **kwargs)

file_util.copy_file = my_copy_file
dir_util.copy_tree = my_copy_tree

Try this code snippet:

from distutils import file_util, dir_util

orig_copy_file = file_util.copy_file
orig_copy_tree = dir_util.copy_tree

def my_copy_file(src, *args, **kwargs):
    if src.endswith('.ext'):
        return
    orig_copy_file(src, *args, **kwargs)

def my_copy_tree(src, *args, **kwargs):
    if src.endswith('foldername'):
        return []
    return orig_copy_tree(src, *args, **kwargs)

file_util.copy_file = my_copy_file
dir_util.copy_tree = my_copy_tree
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文