/breezy-loom/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy-loom/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Loom, a plugin for bzr to assist in developing focused patches.
# Copyright (C) 2010 Canonical Limited.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

"""Format information about formats for Loom.

This is split out from the implementation of the formats to permit lazy
loading without requiring the implementation code to be cryptic.
"""

from __future__ import absolute_import

__all__ = [
    'NotALoom',
    'register_formats',
    'require_loom_branch',
    ]

from bzrlib.lazy_import import lazy_import
import bzrlib.errors

lazy_import(globals(), """
from bzrlib import branch as _mod_branch
""")


_LOOM_FORMATS = {
    "Bazaar-NG Loom branch format 1\n": "BzrBranchLoomFormat1",
    "Bazaar-NG Loom branch format 6\n": "BzrBranchLoomFormat6",
    "Bazaar-NG Loom branch format 7\n": "BzrBranchLoomFormat7",
    }

def register_formats():
    branch_formats = [_mod_branch.MetaDirBranchFormatFactory(format_string,
        "bzrlib.plugins.loom.branch", format_class) for 
        (format_string, format_class) in _LOOM_FORMATS.iteritems()]
    format_registry = getattr(_mod_branch, 'format_registry')
    map(format_registry.register, branch_formats)


def require_loom_branch(branch):
    """Return None if branch is already loomified, or raise NotALoom."""
    if branch._format.network_name() not in _LOOM_FORMATS:
        raise NotALoom(branch)


# TODO: define errors without importing all errors.
class NotALoom(bzrlib.errors.BzrError):

    _fmt = ("The branch %(branch)s is not a loom. "
        "You can use 'bzr loomify' to make it into a loom.")

    def __init__(self, branch):
        bzrlib.errors.BzrError.__init__(self)
        self.branch = branch