[Pythonmac-SIG] Adding resource fork support to tarfile.py

Apple Consultants Network acn at carbontechnologies.com
Tue Jul 18 23:17:17 CEST 2006


Dear List,

I am new to the list and new to python, so please be kind :)  I've  
recently started playing with duplicity (http://duplicity.nongnu.org)  
and really like the feature set that is offered by the project.   
However, I am being stung by the thorn in Apple's side; resource  
forks.  duplicity uses a copy of tarfile.py to build the tar  
archives.  And since this file does not call OS X's tar, nor does it  
have support for resource forks, it will only add data forks to the  
tar archive.

So, I started looking around and found that OS X has a tarfile.py  
(System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/) as part of the standard python install.  This tarfile.py  
is different from the one distributed by duplicity, and at first I  
though I would use it in the distribution.  However, using this  
default install shows that it too does not respect resource forks.   
For example, doing a simple:

#!/usr/bin/python

import tarfile

tar = tarfile.open("sample.tar", "w")
for name in ["Arial"]:
         tar.add(name)
tar.close()

produces a tar file with only the data fork.  The resource fork is  
lost.  In the case of fonts, this is bad.

I am currently running 10.4.7 so I know that resource forks are  
supported in many unix tools such as cp, mv, tar, and others.  For  
example, if I execute a simple tar cf archive.tar Arial, the font is  
intact upon expansion, tar xvf archive.tar.

Also, from searches, there appears to be some level on integration  
between python and resources forks on the Mac through the use of  
"import MacOS > from Carbon import Res".  From searching the archives  
I've found some sample code to allow the reading of the contents of a  
resource fork (thanks to the poster for that).  However, I need to  
make the tarfile library respect the forks as this is how duplicity  
creates the archive files.

Has anyone figured out a way around this limitation in python'  
tarfile.py library.  Admittedly, I generally avoided python so this  
is a bit foreign to me.  Any help or even clarification would be  
appreciated.  I realize that for a person new to the language, this  
is a tall order.

Thanks for your time.

Reid


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonmac-sig/attachments/20060718/323f9159/attachment.html 


More information about the Pythonmac-SIG mailing list