/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)
0.64.4 by Ian Clatworthy
abstract CommitHandler
85
86
87
class CommitHandler(object):
88
    """Base class for commit handling.
89
    
90
    Subclasses should override the pre_*, post_* and *_handler
91
    methods as appropriate.
92
    """
93
94
    def __init__(self, command):
95
        self.command = command
96
97
    def process(self):
98
        self.pre_process_files()
99
        for fc in self.command.file_iter():
100
            try:
101
                handler = self.__class__.__dict__[fc.name + "_handler"]
102
            except KeyError:
103
                raise errors.MissingHandler(fc.name)
104
            else:
105
                handler(self, fc)
106
        self.post_process_files()
107
108
    def pre_process_files(self):
109
        """Prepare for committing."""
110
        pass
111
112
    def post_process_files(self):
113
        """Save the revision."""
114
        pass
115
116
    def modify_handler(self, filecmd):
117
        """Handle a filemodify command."""
118
        raise NotImplementedError(self.modify_handler)
119
120
    def delete_handler(self, filecmd):
121
        """Handle a filedelete command."""
122
        raise NotImplementedError(self.delete_handler)
123
124
    def copy_handler(self, filecmd):
125
        """Handle a filecopy command."""
126
        raise NotImplementedError(self.copy_handler)
127
128
    def rename_handler(self, filecmd):
129
        """Handle a filerename command."""
130
        raise NotImplementedError(self.rename_handler)
131
132
    def deleteall_handler(self, filecmd):
133
        """Handle a filedeleteall command."""
134
        raise NotImplementedError(self.deleteall_handler)