Eduardo Robles Elvira added the comment:

I guess I got it wrong, it's not part of the POSIX standard, just part of the 
GNU tar documentation. About the getmembers and getnames not reflecting the 
entirety of the archive, it's an optimization I needed and I think ccan be 
quite handy. It's also consistent with how the tar command works afaik, just 
listing the contents of the current volume. But it's true that could be done.

Regarding the TarVolumeSet idea, it could work but it's not as easy as that. 
You don't want to directly do a plain open in there, because you want to be 
able to deal with read/write modes, with gzip/bzip/Stream class. You also want 
to give the user maximum flexibility. That's why in my implementation 
new_volume_handler and open_volume functions are separated. Similarly, we could 
do something like this:

class MyTarVolumeSet(tarfile.TarVolumeSet):

    def __init__(self, template, max_vol_size):
        self.template = template
        self.max_vol_size = max_vol_size

    def new_volume_handler(self, tarfile, volume_number):
        self.open_volume(self.template % volume_number, tarfile)

volumes = MyTarVolumesSet("test.tar.%03d")
with tarfile.open(fileobj=volumes, mode="w:") as tar:
    for t in tar:
        print(t.name)

Note that the new_volume_handler in this example receives more or less the same 
params as in my patch (not the base name, because it's already stored in the 
template), and that the open_volume really abstracts which way it will be 
opened. It could also have, as in my patch, an optional fileobj parameter, for 
a new indirection/abstraction.

In any case, this kind of abstraction would still really need some kind of 
hooking with tarfile, because a multivol tarfile is not exactly the same as a 
normal tarfile chopped up. This might be doable unilateraly by a smart 
TarVolumeSet getting the information from the tarfile and modifying/patching 
anything needed. This is one of the reasons why one would probably would still 
need access to the tarfile inside the open_volume function.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18321>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to