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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import re
28
28
 
29
 
from . import (
 
29
from bzrlib import (
30
30
    errors,
31
31
    osutils,
32
32
    )
36
36
_VIEWS_FORMAT1_MARKER = "Bazaar views format 1\n"
37
37
 
38
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
 
 
70
39
class _Views(object):
71
40
    """Base class for View managers."""
72
41
 
126
95
        :param views: a map from view name to list of files/directories
127
96
        """
128
97
        if current is not None and current not in views:
129
 
            raise NoSuchView(current)
 
98
            raise errors.NoSuchView(current)
130
99
        self.tree.lock_write()
131
100
        try:
132
101
            self._current = current
150
119
                    return []
151
120
            return self._views[view_name]
152
121
        except KeyError:
153
 
            raise NoSuchView(view_name)
 
122
            raise errors.NoSuchView(view_name)
154
123
 
155
124
    def set_view(self, view_name, view_files, make_current=True):
156
125
        """Add or update a view definition.
180
149
            try:
181
150
                del self._views[view_name]
182
151
            except KeyError:
183
 
                raise NoSuchView(view_name)
 
152
                raise errors.NoSuchView(view_name)
184
153
            if view_name == self._current:
185
154
                self._current = None
186
155
            self._save_view_info()
207
176
    def _load_view_info(self):
208
177
        """Load the current view and dictionary of view definitions."""
209
178
        if not self._loaded:
210
 
            with self.tree.lock_read():
 
179
            self.tree.lock_read()
 
180
            try:
211
181
                try:
212
182
                    view_content = self.tree._transport.get_bytes('views')
213
 
                except errors.NoSuchFile as e:
 
183
                except errors.NoSuchFile, e:
214
184
                    self._current, self._views = None, {}
215
185
                else:
216
186
                    keywords, self._views = \
217
187
                        self._deserialize_view_content(view_content)
218
188
                    self._current = keywords.get('current')
 
189
            finally:
 
190
                self.tree.unlock()
219
191
            self._loaded = True
220
192
 
221
193
    def _serialize_view_content(self, keywords, view_dict):
222
194
        """Convert view keywords and a view dictionary into a stream."""
223
195
        lines = [_VIEWS_FORMAT1_MARKER]
224
196
        for key in keywords:
225
 
            line = "%s=%s\n" % (key, keywords[key])
 
197
            line = "%s=%s\n" % (key,keywords[key])
226
198
            lines.append(line.encode('utf-8'))
227
199
        if view_dict:
228
200
            lines.append("views:\n".encode('utf-8'))
266
238
                    raise ValueError("failed to deserialize views line %s",
267
239
                        text)
268
240
            return keywords, views
269
 
        except ValueError as e:
 
241
        except ValueError, e:
270
242
            raise ValueError("failed to deserialize views content %r: %s"
271
243
                % (view_content, e))
272
244
 
284
256
        return False
285
257
 
286
258
    def _not_supported(self, *a, **k):
287
 
        raise ViewsNotSupported(self.tree)
 
259
        raise errors.ViewsNotSupported(self.tree)
288
260
 
289
261
    get_view_info = _not_supported
290
262
    set_view_info = _not_supported
310
282
    if tree.supports_views():
311
283
        view_files = tree.views.lookup_view()
312
284
        if  view_files and not osutils.is_inside_any(view_files, relpath):
313
 
            raise FileOutsideView(relpath, view_files)
 
285
            raise errors.FileOutsideView(relpath, view_files)