我编写了一个脚本,将所有日志文件收集到一个tar文件中。问题是它不包含软链路的数据。我尝试使用取消引用标志,但在python 2.4.3中不能识别。
我不能使用命令行,因为有长度限制,并且我想支持许多日志文件。
user ~/Desktop]$python
Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
>>> import tarfile
>>> tarfile.TarFile('test.tar.gz', mode='w', dereference=True)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: __init__() got an unexpected keyword argument 'dereference'
>>>发布于 2011-08-09 20:43:19
根据Python 2.4 docs,支持dereference = True。自从tarfile在Python2.3中添加以来,它似乎已经得到了支持。
除非您在非Posix系统(Windows)上,否则您一定是做错了。发布你的代码和你在dereference = True中得到的错误,这样我们就可以告诉你那是什么。
另外,软链接我假设你指的是符号链接?因为这就是dereference = True所允许的。
编辑:我刚刚看了一下code for tarfile on Python 2.4。It 不支持将dereference参数到构造函数,但it 似乎有所需的代码来实际取消引用(根据source for Python 2.6检查)。所以,
import tarfile
tf = tarfile.TarFile('test.tar.gz', mode='w')
tf.dereference = True应该行得通。请更新您的结果。
发布于 2011-08-09 20:39:58
您不能只在tar上使用-T或--files-from选项吗
https://stackoverflow.com/questions/6996224
复制相似问题