/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.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Export trees to tarballs, non-controlled directories, zipfiles, etc.
18
18
"""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import errno
21
23
import os
22
24
import sys
23
25
import time
 
26
import warnings
24
27
 
25
28
from . import (
26
29
    archive,
63
66
 
64
67
    if not per_file_timestamps:
65
68
        force_mtime = time.time()
66
 
        if getattr(tree, '_repository', None):
67
 
            try:
68
 
                force_mtime = tree._repository.get_revision(
69
 
                    tree.get_revision_id()).timestamp
70
 
            except errors.NoSuchRevision:
71
 
                pass
72
69
    else:
73
70
        force_mtime = None
74
71
 
79
76
        # then we should stream a tar file and unpack that on the fly.
80
77
        with tree.lock_read():
81
78
            for unused in dir_exporter_generator(tree, dest, root, subdir,
82
 
                                                 force_mtime):
 
79
                    force_mtime):
83
80
                pass
84
81
        return
85
82
 
86
83
    with tree.lock_read():
87
 
        chunks = tree.archive(format, dest, root=root,
88
 
                              subdir=subdir, force_mtime=force_mtime)
 
84
        chunks = tree.archive(format, dest, root=root, subdir=subdir, force_mtime=force_mtime)
89
85
        if dest == '-':
90
86
            for chunk in chunks:
91
 
                getattr(sys.stdout, 'buffer', sys.stdout).write(chunk)
 
87
                 sys.stdout.write(chunk)
92
88
        elif fileobj is not None:
93
89
            for chunk in chunks:
94
90
                fileobj.write(chunk)
95
91
        else:
96
92
            with open(dest, 'wb') as f:
97
93
                for chunk in chunks:
98
 
                    f.write(chunk)
 
94
                    f.writelines(chunk)
99
95
 
100
96
 
101
97
def guess_format(filename, default='dir'):
201
197
            os.mkdir(fullpath)
202
198
        elif ie.kind == "symlink":
203
199
            try:
204
 
                symlink_target = tree.get_symlink_target(tp)
 
200
                symlink_target = tree.get_symlink_target(tp, file_id)
205
201
                os.symlink(symlink_target, fullpath)
206
202
            except OSError as e:
207
203
                raise errors.BzrError(
209
205
                    % (fullpath, symlink_target, e))
210
206
        else:
211
207
            raise errors.BzrError("don't know how to export {%s} of kind %r" %
212
 
                                  (tp, ie.kind))
 
208
               (tp, ie.kind))
213
209
 
214
210
        yield
215
211
    # The data returned here can be in any order, but we've already created all
219
215
        fullpath = osutils.pathjoin(dest, relpath)
220
216
        # We set the mode and let the umask sort out the file info
221
217
        mode = 0o666
222
 
        if tree.is_executable(treepath):
 
218
        if tree.is_executable(treepath, file_id):
223
219
            mode = 0o777
224
220
        with os.fdopen(os.open(fullpath, flags, mode), 'wb') as out:
225
221
            out.writelines(chunks)
226
222
        if force_mtime is not None:
227
223
            mtime = force_mtime
228
224
        else:
229
 
            mtime = tree.get_file_mtime(treepath)
 
225
            mtime = tree.get_file_mtime(treepath, file_id)
230
226
        os.utime(fullpath, (mtime, mtime))
231
227
 
232
228
        yield