[Pythonmac-SIG] xattr question

Christian Tismer tismer at stackless.com
Sun Oct 3 01:32:46 CEST 2010


  Hi Bob, hi mackies

while writing some tool for Time Machine, I encountered quite some
different implementations of xattr. Actually, for a tool written
in python, the internal API is sufficient, but when trying the xattr
command, I was quite confused which way to go.

At the moment, I see three different implementations of xattr.

- one implementation completely in C

- one from you (Bob)

- the built-in version from Mac Os.

The problem is that they are not compatible or subsets of each other,
but that they diverge in the one or other aspect. I think this is
not a good thing for system tools. They should have different names,
or they should be aware of their differences and clearly state this.
At the moment, I see the different versions pretty much ignoring
that they are not the only implementations, but whatever you install,
you think you have "the" tool.

I would like to change this, and to find out about an agreed standard
for the xattr command that is guaranteed to be supported by every
implementations. Is there some definition like this somewhere?

Essentially, the basic commands are the same for all versions, but they
heavily differ by their options.

What is the opinion, especially yours, Bob, hot that should be?


Here are the different versions listed.
---------------------------------------

(1) http://xattr.sourceforge.net/
     See this page which is the man page with links to other implementations
     and download. Especially misleading is the reference to Bob's version,
     that suggests it is an enhanced version, instead it is missing most
     of the features, silently. Options:

     -s    Do not follow symbolic links.
     -l    Display results in extended format.
     -R    Expect to edit existing extended attributes; fail rather than 
create a new one.
     -C    Expect to create new extended attributes; fail rather than 
edit an existing one.

(2) http://pypi.python.org/pypi/xattr
     This is Bob's implementation. Options:

     -l: print long format (attr_name: attr_value)
     -z: compress or decompress (if compressed) attribute value in zip

(3) /usr/bin/xattr-2.6
     supplied by Apple. I did not find another source than on Os X.
     Options:

     -r: act recursively
     -l: print long format (attr_name: attr_value and hex output has 
offsets and
         ascii representation)
     -v: also print filename (automatic with -r and with multiple files)
     -x: attr_value is represented as a hex string for input and output


My commentary:
--------------

(1) is a simple C implementation. Not bad, but nothing that looks
     like a good reason to prefer it over Python, except one feature:

     The options -R and -C ensure your expectations, which helps to
     prevent typos: If you specify -R for instance, the attribute has
     to be replaced, i.e. you get an error if it did not exist before.

     No hex, no zip, no recursion.

(2) is a nice Python implementation. It has the extra feature of actimg
     on zip compressed archives. Non-standard imports

     import zlib        for zip entries

(3) is also a nice Python implementation, and pretty similar to (2).
     No idea who is the hen and who the egg. Non-standard imports:

     import binascii    for hex operation
     import string      white space elimination for hex (maketrans)

The hex feature of (3) is a real advantage if you want to clone
certain xattr entries which are binary. You can really use a hex dump,
remove formatting of the listing, and apply it to another file.

The zip feature of (2) is useful if you need to modify archives.

The recursion feature of (3) looks handy at first sight, but actually
its use is limited, because you have limited control of the traversal
of huge Time Machine archives, which tend to have millions of files.
It would make sense if you could filter the many xattr entries of
little relevance, of filter files which have xattributes at all.

It would probably make more sense to add recursion features concerning
xattr to the find command, or invent a new one.


So here come(s) my question(s):
-------------------------------

Does it make sense to further develop a C version? Assuming "no".

Is there a reason why Bob-xattr and Apple-xattr do not agree on
a common API?

Is there any discussion somewhere that leads these decisions?

What is you intention, how should xattr functionality be in future?
Also in the light of compatibility with other OSses?

Where can the Apple version be downloaded, when you try to re-install
your system python?

I think it would be good to clarify this a bit, and maybe to collect
some information for (mostly) newbies like me.
Would the python mac wiki be a good place?

cheers -- chris

-- 
Christian Tismer             :^)<mailto:tismer at stackless.com>
tismerysoft GmbH             :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key ->  http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
       whom do you want to sponsor today?   http://www.stackless.com/



More information about the Pythonmac-SIG mailing list