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

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""TreeBuilder helper class.
18
18
 
19
 
TreeBuilders are used to build trees of various shapes or properties. This
 
19
TreeBuilders are used to build trees of various shapres or properties. This 
20
20
can be extremely useful in testing for instance.
21
21
"""
22
22
 
23
 
from . import errors
24
 
 
25
 
 
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."
 
23
from bzrlib import errors
34
24
 
35
25
 
36
26
class TreeBuilder(object):
52
42
        """
53
43
        self._ensure_building()
54
44
        if not self._root_done:
55
 
            self._tree.add('', b'root-id', 'directory')
 
45
            self._tree.add('', 'root-id', 'directory')
56
46
            self._root_done = True
57
47
        for name in recipe:
58
 
            if name.endswith('/'):
 
48
            assert isinstance(name, basestring)
 
49
            if name[-1] == '/':
59
50
                self._tree.mkdir(name[:-1])
60
51
            else:
61
 
                end = b'\n'
62
 
                content = b"contents of %s%s" % (name.encode('utf-8'), end)
 
52
                end = '\n'
 
53
                content = "contents of %s%s" % (name.encode('utf-8'), end)
63
54
                self._tree.add(name, None, 'file')
64
 
                self._tree.put_file_bytes_non_atomic(name, content)
 
55
                file_id = self._tree.path2id(name)
 
56
                self._tree.put_file_bytes_non_atomic(file_id, content)
65
57
 
66
58
    def _ensure_building(self):
67
59
        """Raise NotBuilding if there is no current tree being built."""
68
60
        if self._tree is None:
69
 
            raise NotBuilding
70
 
 
 
61
            raise errors.NotBuilding
 
62
            
71
63
    def finish_tree(self):
72
64
        """Finish building the current tree."""
73
65
        self._ensure_building()
77
69
 
78
70
    def start_tree(self, tree):
79
71
        """Start building on tree.
80
 
 
81
 
        :param tree: A tree to start building on. It must provide the
 
72
        
 
73
        :param tree: A tree to start building on. It must provide the 
82
74
            MutableTree interface.
83
75
        """
84
76
        if self._tree is not None:
85
 
            raise AlreadyBuilding
 
77
            raise errors.AlreadyBuilding
86
78
        self._tree = tree
87
79
        self._tree.lock_tree_write()