~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2011-06-27 22:03:53 UTC
  • mfrom: (770.1.1 trunk)
  • Revision ID: aaron@aaronbentley.com-20110627220353-c7ikthkaap2amfzm
Support importing .tar.xz and .tar.lzma files.  (Jelmer)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import errno
4
4
import os
5
 
import sys
6
5
from StringIO import StringIO
7
6
import stat
8
7
import tarfile
280
279
            raise BzrCommandError("Working tree has uncommitted changes.")
281
280
 
282
281
        if (source.endswith('.tar') or source.endswith('.tar.gz') or
283
 
            source.endswith('.tar.bz2')) or source.endswith('.tgz'):
 
282
            source.endswith('.tar.bz2') or source.endswith('.tgz') or
 
283
            source.endswith('.tar.lzma') or source.endswith('.tar.xz')):
284
284
            try:
285
285
                tar_input = open_from_url(source)
286
286
                if source.endswith('.bz2'):
287
 
                    tar_input = StringIO(tar_input.read().decode('bz2'))
 
287
                    import bz2
 
288
                    tar_input = StringIO(bz2.decompress(tar_input.read()))
 
289
                elif source.endswith('.xz') or source.endswith('.lzma'):
 
290
                    import lzma
 
291
                    tar_input = StringIO(lzma.decompress(tar_input.read()))
288
292
            except IOError, e:
289
293
                if e.errno == errno.ENOENT:
290
294
                    raise NoSuchFile(source)