在Python3.4中,如何使用tar+gzip压缩和“follow symbolic link”特性?问题是:
代码:
...
mode = ""
if bckentry['method'] == "tar":
mode = "w"
elif bckentry['method'] == "targz":
mode = "w:gz"
archive = tarfile.TarFile(name=filepath, mode=mode)
archive.dereference = True if bckentry['followsym'] == "yes" else False
# archive = tarfile.open(filepath, mode=mode)
if bckentry['withpath'] == 'yes':
for entry in bckentry['include_dirs']:
archive.add(entry, filter=self.filter_tar)
elif bckentry['withpath'] == 'no':
for entry in bckentry['include_dirs']:
archive.add(entry, arcname=os.path.basename(entry), filter=self.filter_tar)
...
^{} 是^{} 类方法的快捷方式,该方法反过来调用^{} 构造函数。文档有点含糊,但从代码中可以明显看出,前两个将把
dereference
关键字参数和所有其他未使用的kwarg传递给TarFile
构造函数。在因此,您可以将
dereference
与它们中的任何一个一起使用,如果您只是将其作为关键字参数传递:相关问题 更多 >
编程相关推荐