~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Export a bzrlib.tree.Tree to a new or empty directory."""
 
17
"""Export a Tree to a non-versioned directory.
 
18
"""
18
19
 
19
20
import errno
20
21
import os
21
 
import time
 
22
import StringIO
22
23
 
23
24
from bzrlib import errors, osutils
24
25
from bzrlib.export import _export_iter_entries
29
30
from bzrlib.trace import mutter
30
31
 
31
32
 
32
 
def dir_exporter(tree, dest, root, subdir, filtered=False,
33
 
                 per_file_timestamps=False):
 
33
def dir_exporter(tree, dest, root, subdir, filtered=False):
34
34
    """Export this tree to a new directory.
35
35
 
36
 
    `dest` should either not exist or should be empty. If it does not exist it
37
 
    will be created holding the contents of this tree.
 
36
    `dest` should not exist, and will be created holding the
 
37
    contents of this tree.
 
38
 
 
39
    TODO: To handle subdirectories we need to create the
 
40
           directories first.
38
41
 
39
42
    :note: If the export fails, the destination directory will be
40
 
           left in an incompletely exported state: export is not transactional.
 
43
           left in a half-assed state.
41
44
    """
42
45
    mutter('export version %r', tree)
43
46
    try:
76
79
    # The data returned here can be in any order, but we've already created all
77
80
    # the directories
78
81
    flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
79
 
    now = time.time()
80
82
    for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
81
83
        if filtered:
82
84
            filters = tree._content_filter_stack(relpath)
92
94
            out.writelines(chunks)
93
95
        finally:
94
96
            out.close()
95
 
        if per_file_timestamps:
96
 
            mtime = tree.get_file_mtime(tree.path2id(relpath), relpath)
97
 
        else:
98
 
            mtime = now
99
 
        os.utime(fullpath, (mtime, mtime))