I wrote a script that collects all our log files to one tar file. The problem is that it doesn't contain soft link's data. I tried to use the dereference flag but it is not recognized for python 2.4.3.
I can't use the command line since there's a length limit and I want to support many log files.
开发者_Python百科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'
>>>
According to the Python 2.4 docs dereference = True
is supported. It appears to have been supported since tarfile
was added in Python 2.3.
Unless you're on a non-Posix system (Windows) you must be doing it wrong. Post your code and the error you get with dereference = True
so we can tell you what that is.
Also, by soft links I assume you mean symbolic links? Because that's what dereference = True
allows to work.
Edit: I just looked at the code for tarfile on Python 2.4. It does not support the dereference
parameter to the constructor, but it does seem to have the needed code to actually dereference (Checked against the source for Python 2.6). So,
import tarfile
tf = tarfile.TarFile('test.tar.gz', mode='w')
tf.dereference = True
should work. Please, update with your results.
Couldn't you just use the -T
or --files-from
option on tar
?
精彩评论