/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/export/tar_exporter.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from __future__ import absolute_import
20
20
 
21
21
import os
22
 
import StringIO
23
22
import sys
24
23
import tarfile
25
24
 
26
 
from breezy import (
 
25
from .. import (
27
26
    errors,
28
27
    osutils,
29
28
    )
30
 
from breezy.export import _export_iter_entries
 
29
from ..export import _export_iter_entries
 
30
from ..sixish import (
 
31
    BytesIO,
 
32
    )
31
33
 
32
34
 
33
35
def prepare_tarball_item(tree, root, final_path, tree_path, entry, force_mtime=None):
51
53
    if entry.kind == "file":
52
54
        item.type = tarfile.REGTYPE
53
55
        if tree.is_executable(entry.file_id, tree_path):
54
 
            item.mode = 0755
 
56
            item.mode = 0o755
55
57
        else:
56
 
            item.mode = 0644
 
58
            item.mode = 0o644
57
59
        # This brings the whole file into memory, but that's almost needed for
58
60
        # the tarfile contract, which wants the size of the file up front.  We
59
61
        # want to make sure it doesn't change, and we need to read it in one
60
62
        # go for content filtering.
61
63
        content = tree.get_file_text(entry.file_id, tree_path)
62
64
        item.size = len(content)
63
 
        fileobj = StringIO.StringIO(content)
 
65
        fileobj = BytesIO(content)
64
66
    elif entry.kind == "directory":
65
67
        item.type = tarfile.DIRTYPE
66
68
        item.name += '/'
67
69
        item.size = 0
68
 
        item.mode = 0755
 
70
        item.mode = 0o755
69
71
        fileobj = None
70
72
    elif entry.kind == "symlink":
71
73
        item.type = tarfile.SYMTYPE
72
74
        item.size = 0
73
 
        item.mode = 0755
 
75
        item.mode = 0o755
74
76
        item.linkname = tree.get_symlink_target(entry.file_id, tree_path)
75
77
        fileobj = None
76
78
    else:
218
220
            "Writing to fileobject not supported for .tar.lzma")
219
221
    try:
220
222
        import lzma
221
 
    except ImportError, e:
 
223
    except ImportError as e:
222
224
        raise errors.DependencyNotPresent('lzma', e)
223
225
 
224
226
    stream = lzma.LZMAFile(dest.encode(osutils._fs_enc), 'w',