/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 bzrlib/tests/treeshape.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2010 Canonical Ltd
 
1
# Copyright (C) 2005 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
30
30
import os
31
31
import stat
32
32
 
33
 
from ..trace import warning
34
 
from ..osutils import pathjoin
35
 
 
 
33
from bzrlib.trace import warning
 
34
from bzrlib.osutils import pathjoin
36
35
 
37
36
def build_tree_contents(template):
38
37
    """Reconstitute some files from a text description.
42
41
 
43
42
    The template is built relative to the Python process's current
44
43
    working directory.
45
 
 
46
 
    ('foo/',) will build a directory.
47
 
    ('foo', 'bar') will write 'bar' to 'foo'
48
 
    ('foo@', 'linktarget') will raise an error
49
44
    """
50
45
    for tt in template:
51
46
        name = tt[0]
52
47
        if name[-1] == '/':
53
48
            os.mkdir(name)
54
49
        elif name[-1] == '@':
55
 
            os.symlink(tt[1], tt[0][:-1])
 
50
            raise NotImplementedError('symlinks not handled yet')
56
51
        else:
57
 
            with open(name, 'w' + ('b' if isinstance(tt[1], bytes) else '')) as f:
 
52
            f = file(name, 'wb')
 
53
            try:
58
54
                f.write(tt[1])
 
55
            finally:
 
56
                f.close()
59
57
 
60
58
 
61
59
def capture_tree_contents(top):
73
71
            if stat.S_ISLNK(info.st_mode):
74
72
                yield (fullpath + '@', os.readlink(fullpath))
75
73
            elif stat.S_ISREG(info.st_mode):
76
 
                with open(fullpath, 'rb') as f:
77
 
                    file_bytes = f.read()
78
 
                yield (fullpath, file_bytes)
 
74
                yield (fullpath, file(fullpath, 'rb').read())
79
75
            else:
80
76
                warning("can't capture file %s with mode %#o",
81
77
                        fullpath, info.st_mode)