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 martin.panter
Recipients lars.gustaebel, markgrandi, martin.panter, pitrou, r.david.murray
Date 2015-03-24.03:36:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427168189.35.0.848097805056.issue22208@psf.upfronthosting.co.za>
In-reply-to
Content
If you read the documentation it is clear that gettarfile() requires an OS file, so won’t work with an internal Python-only file object. Maybe the documentation could be tweaked, but I don’t think the gettarfile() implementation should be changed. To me the whole point of it is to call fstat() on the file and fill in the TarInfo attributes appropriately.

Instead, perhaps an enhancement could be made that allowed something like this:

metadata = TarInfo.make_file('helloworld.txt', len(b))
tarFileObj.addfile(metadata, io.BytesIO(b))

The corresponding TarInfo class could grow new presets looking something like:

class TarInfo:
    @classmethod
    def make_file(cls, name, size):  # Name and size are mandatory
        self = cls(name)
        self.type = REGTYPE
        self.size = size
        self.mtime = None  # Force addfile() to set it to some default time.time() value
        self.mode = 0o644
        return self
    
    @classmethod
    def make_executable(cls, name, size):
        ...
        self.mode = 0o755
        ...
    
    @classmethod
    def make_directory(cls, name):
        ...
        self.type = DIRTYPE
        ...
    
    def make_hard_link(cls, name, target)
    def make_symlink(cls, name, target)
    def make_block_device(cls, name, major, minor)  # Set undocumented attributes
    def make_char_device(cls, name, major, minor)
History
Date User Action Args
2015-03-24 03:36:29martin.pantersetrecipients: + martin.panter, lars.gustaebel, pitrou, r.david.murray, markgrandi
2015-03-24 03:36:29martin.pantersetmessageid: <1427168189.35.0.848097805056.issue22208@psf.upfronthosting.co.za>
2015-03-24 03:36:29martin.panterlinkissue22208 messages
2015-03-24 03:36:28martin.pantercreate