/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Processor of import commands.
18
19
This module provides core processing functionality including an abstract class
20
for basing real processors on. See the processors package for examples.
21
"""
22
23
24
import errors
25
26
27
class ImportProcessor(object):
28
    """Base class for import processors.
29
    
30
    Subclasses should override the pre_*, post_* and *_handler
31
    methods as appropriate.
32
    """
33
34
    def __init__(self, target, verbose=False):
35
        self.target = target
36
        self.verbose = verbose
37
38
    def process(self, command_iter):
39
        """Import data into Bazaar by processing a stream of commands.
40
41
        :param command_iter: an iterator providing commands
42
        """
43
        self.pre_process()
44
        for cmd in command_iter():
45
            try:
46
                handler = self.__class__.__dict__[cmd.name + "_handler"]
47
            except KeyError:
48
                raise errors.MissingHandler(cmd.name)
49
            else:
50
                # TODO: put hooks around processing each command?
51
                handler(self, cmd)
52
        self.post_process()
53
54
    def pre_process(self):
55
        """Hook for logic at start of processing."""
56
        pass
57
58
    def post_process(self):
59
        """Hook for logic at end of processing."""
60
        pass
61
62
    def progress_handler(self, cmd):
63
        """Process a ProgressCommand."""
64
        raise NotImplementedError(self.progress_handler)
65
66
    def blob_handler(self, cmd):
67
        """Process a BlobCommand."""
68
        raise NotImplementedError(self.blob_handler)
69
70
    def checkpoint_handler(self, cmd):
71
        """Process a CheckpointCommand."""
72
        raise NotImplementedError(self.checkpoint_handler)
73
74
    def commit_handler(self, cmd):
75
        """Process a CommitCommand."""
76
        raise NotImplementedError(self.commit_handler)
77
78
    def reset_handler(self, cmd):
79
        """Process a ResetCommand."""
80
        raise NotImplementedError(self.reset_handler)
81
82
    def tag_handler(self, cmd):
83
        """Process a TagCommand."""
84
        raise NotImplementedError(self.tag_handler)