/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2008, 2009, 2010 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
16
16
 
17
17
"""TreeBuilder helper class.
18
18
 
19
 
TreeBuilders are used to build trees of various shapres or properties. This
 
19
TreeBuilders are used to build trees of various shapes or properties. This
20
20
can be extremely useful in testing for instance.
21
21
"""
22
22
 
23
 
from bzrlib import errors
 
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."
24
34
 
25
35
 
26
36
class TreeBuilder(object):
42
52
        """
43
53
        self._ensure_building()
44
54
        if not self._root_done:
45
 
            self._tree.add('', 'root-id', 'directory')
 
55
            self._tree.add('', b'root-id', 'directory')
46
56
            self._root_done = True
47
57
        for name in recipe:
48
 
            if name[-1] == '/':
 
58
            if name.endswith('/'):
49
59
                self._tree.mkdir(name[:-1])
50
60
            else:
51
 
                end = '\n'
52
 
                content = "contents of %s%s" % (name.encode('utf-8'), end)
 
61
                end = b'\n'
 
62
                content = b"contents of %s%s" % (name.encode('utf-8'), end)
53
63
                self._tree.add(name, None, 'file')
54
 
                file_id = self._tree.path2id(name)
55
 
                self._tree.put_file_bytes_non_atomic(file_id, content)
 
64
                self._tree.put_file_bytes_non_atomic(name, content)
56
65
 
57
66
    def _ensure_building(self):
58
67
        """Raise NotBuilding if there is no current tree being built."""
59
68
        if self._tree is None:
60
 
            raise errors.NotBuilding
 
69
            raise NotBuilding
61
70
 
62
71
    def finish_tree(self):
63
72
        """Finish building the current tree."""
73
82
            MutableTree interface.
74
83
        """
75
84
        if self._tree is not None:
76
 
            raise errors.AlreadyBuilding
 
85
            raise AlreadyBuilding
77
86
        self._tree = tree
78
87
        self._tree.lock_tree_write()