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

  • Committer: Martin
  • Date: 2017-08-28 14:17:16 UTC
  • mto: This revision was merged to the branch mainline in revision 6779.
  • Revision ID: gzlist@googlemail.com-20170828141716-kncy9mgeszq9x963
Add test_cleanup to passing Python 3 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  tree.views.lookup_view()
23
23
"""
24
24
 
 
25
from __future__ import absolute_import
25
26
 
26
27
import re
27
28
 
28
 
from bzrlib import (
 
29
from . import (
29
30
    errors,
30
31
    osutils,
31
32
    )
35
36
_VIEWS_FORMAT1_MARKER = "Bazaar views format 1\n"
36
37
 
37
38
 
 
39
class NoSuchView(errors.BzrError):
 
40
    """A view does not exist.
 
41
    """
 
42
 
 
43
    _fmt = u"No such view: %(view_name)s."
 
44
 
 
45
    def __init__(self, view_name):
 
46
        self.view_name = view_name
 
47
 
 
48
 
 
49
class ViewsNotSupported(errors.BzrError):
 
50
    """Views are not supported by a tree format.
 
51
    """
 
52
 
 
53
    _fmt = ("Views are not supported by %(tree)s;"
 
54
            " use 'brz upgrade' to change your tree to a later format.")
 
55
 
 
56
    def __init__(self, tree):
 
57
        self.tree = tree
 
58
 
 
59
 
 
60
class FileOutsideView(errors.BzrError):
 
61
 
 
62
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
63
            '%(view_str)s')
 
64
 
 
65
    def __init__(self, file_name, view_files):
 
66
        self.file_name = file_name
 
67
        self.view_str = ", ".join(view_files)
 
68
 
 
69
 
38
70
class _Views(object):
39
71
    """Base class for View managers."""
40
72
 
94
126
        :param views: a map from view name to list of files/directories
95
127
        """
96
128
        if current is not None and current not in views:
97
 
            raise errors.NoSuchView(current)
 
129
            raise NoSuchView(current)
98
130
        self.tree.lock_write()
99
131
        try:
100
132
            self._current = current
118
150
                    return []
119
151
            return self._views[view_name]
120
152
        except KeyError:
121
 
            raise errors.NoSuchView(view_name)
 
153
            raise NoSuchView(view_name)
122
154
 
123
155
    def set_view(self, view_name, view_files, make_current=True):
124
156
        """Add or update a view definition.
148
180
            try:
149
181
                del self._views[view_name]
150
182
            except KeyError:
151
 
                raise errors.NoSuchView(view_name)
 
183
                raise NoSuchView(view_name)
152
184
            if view_name == self._current:
153
185
                self._current = None
154
186
            self._save_view_info()
179
211
            try:
180
212
                try:
181
213
                    view_content = self.tree._transport.get_bytes('views')
182
 
                except errors.NoSuchFile, e:
 
214
                except errors.NoSuchFile as e:
183
215
                    self._current, self._views = None, {}
184
216
                else:
185
217
                    keywords, self._views = \
237
269
                    raise ValueError("failed to deserialize views line %s",
238
270
                        text)
239
271
            return keywords, views
240
 
        except ValueError, e:
 
272
        except ValueError as e:
241
273
            raise ValueError("failed to deserialize views content %r: %s"
242
274
                % (view_content, e))
243
275
 
255
287
        return False
256
288
 
257
289
    def _not_supported(self, *a, **k):
258
 
        raise errors.ViewsNotSupported(self.tree)
 
290
        raise ViewsNotSupported(self.tree)
259
291
 
260
292
    get_view_info = _not_supported
261
293
    set_view_info = _not_supported
281
313
    if tree.supports_views():
282
314
        view_files = tree.views.lookup_view()
283
315
        if  view_files and not osutils.is_inside_any(view_files, relpath):
284
 
            raise errors.FileOutsideView(relpath, view_files)
 
316
            raise FileOutsideView(relpath, view_files)