This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lars.gustaebel
Recipients christian.heimes, edulix, lars.gustaebel, loewis, serhiy.storchaka
Date 2014-02-02.15:53:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1391356384.98.0.935159192528.issue18321@psf.upfronthosting.co.za>
In-reply-to
Content
I had the following idea: What about a separate class, let's call it TarVolumeSet for now, that maps a set of (virtual) volumes onto one big file-like object. This TarVolumeSet will be passed to a TarFile constructor as the fileobj argument. It is subclassable for implementing custom behavior.


class MyTarVolumeSet(tarfile.TarVolumeSet):

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

    def open_volume(self, volume_number):
        return open(self.template % volume_number, "rb")

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


In my opinion, this approach has a number of advantages: Most importantly, it separates the multi-volume code from the TarFile class, which reduces the invasiveness, complexity and maintenance burden of the original approach. The TarFile class would be totally agnostic about the concept of multiple volumes, TarVolumeSet looks just like another file-object to TarFile. Looks like the cleanest solution to me so far.
History
Date User Action Args
2014-02-02 15:53:05lars.gustaebelsetrecipients: + lars.gustaebel, loewis, christian.heimes, serhiy.storchaka, edulix
2014-02-02 15:53:04lars.gustaebelsetmessageid: <1391356384.98.0.935159192528.issue18321@psf.upfronthosting.co.za>
2014-02-02 15:53:04lars.gustaebellinkissue18321 messages
2014-02-02 15:53:04lars.gustaebelcreate