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

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
can be extremely useful in testing for instance.
21
21
"""
22
22
 
 
23
from __future__ import absolute_import
 
24
 
23
25
from . import errors
24
26
 
25
27
 
26
 
class AlreadyBuilding(errors.BzrError):
27
 
 
28
 
    _fmt = "The tree builder is already building a tree."
29
 
 
30
 
 
31
 
class NotBuilding(errors.BzrError):
32
 
 
33
 
    _fmt = "Not currently building a tree."
34
 
 
35
 
 
36
28
class TreeBuilder(object):
37
29
    """A TreeBuilder allows the creation of specific content in one tree at a
38
30
    time.
52
44
        """
53
45
        self._ensure_building()
54
46
        if not self._root_done:
55
 
            self._tree.add('', b'root-id', 'directory')
 
47
            self._tree.add('', 'root-id', 'directory')
56
48
            self._root_done = True
57
49
        for name in recipe:
58
 
            if name.endswith('/'):
 
50
            if name[-1] == '/':
59
51
                self._tree.mkdir(name[:-1])
60
52
            else:
61
 
                end = b'\n'
62
 
                content = b"contents of %s%s" % (name.encode('utf-8'), end)
 
53
                end = '\n'
 
54
                content = "contents of %s%s" % (name.encode('utf-8'), end)
63
55
                self._tree.add(name, None, 'file')
64
 
                self._tree.put_file_bytes_non_atomic(name, content)
 
56
                file_id = self._tree.path2id(name)
 
57
                self._tree.put_file_bytes_non_atomic(file_id, content)
65
58
 
66
59
    def _ensure_building(self):
67
60
        """Raise NotBuilding if there is no current tree being built."""
68
61
        if self._tree is None:
69
 
            raise NotBuilding
 
62
            raise errors.NotBuilding
70
63
 
71
64
    def finish_tree(self):
72
65
        """Finish building the current tree."""
82
75
            MutableTree interface.
83
76
        """
84
77
        if self._tree is not None:
85
 
            raise AlreadyBuilding
 
78
            raise errors.AlreadyBuilding
86
79
        self._tree = tree
87
80
        self._tree.lock_tree_write()