rwallace
rwallace

Reputation: 33405

Distributing a Python script to unpack .tar.xz

Is there a way to distribute a Python script that can unpack a .tar.xz file?

Specifically:

So that seems to amount to asking whether out-of-the-box Python 2.7 has such a feature, and as far as I can tell the answer is no, but is there anything I'm missing?

Upvotes: 2

Views: 2032

Answers (1)

Cyrbil
Cyrbil

Reputation: 6478

First decompress the xz file into tar data and then extract the tar data:

import lzma
import tarfile

with lzma.open("file.tar.xz") as fd:
    with tarfile.open(fileobj=fd) as tar:
        content = tar.extractall('/path/to/extract/to')

For python2.7 you need to install pip27.pylzma

Upvotes: 3

Related Questions