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 |
||
|
0.64.6
by Ian Clatworthy
generic processing method working for one revision in one branch |
34 |
def __init__(self, bzrdir, verbose=False): |
35 |
self.bzrdir = bzrdir |
|
36 |
if bzrdir is None: |
|
37 |
# Some 'importers' don't need a repository to write to
|
|
38 |
self.branch = None |
|
39 |
self.repo = None |
|
40 |
self.working_tree = None |
|
41 |
else: |
|
42 |
(self.working_tree, self.branch) = bzrdir._get_tree_branch() |
|
43 |
self.repo = self.branch.repository |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
44 |
self.verbose = verbose |
45 |
||
46 |
def process(self, command_iter): |
|
47 |
"""Import data into Bazaar by processing a stream of commands. |
|
48 |
||
49 |
:param command_iter: an iterator providing commands
|
|
50 |
"""
|
|
|
0.64.6
by Ian Clatworthy
generic processing method working for one revision in one branch |
51 |
if self.working_tree is not None: |
52 |
self.working_tree.lock_write() |
|
53 |
elif self.branch is not None: |
|
54 |
self.branch.lock_write() |
|
55 |
try: |
|
56 |
self._process(command_iter) |
|
57 |
finally: |
|
58 |
if self.working_tree is not None: |
|
59 |
self.working_tree.unlock() |
|
60 |
elif self.branch is not None: |
|
61 |
self.branch.unlock() |
|
62 |
||
63 |
def _process(self, command_iter): |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
64 |
self.pre_process() |
65 |
for cmd in command_iter(): |
|
66 |
try: |
|
67 |
handler = self.__class__.__dict__[cmd.name + "_handler"] |
|
68 |
except KeyError: |
|
69 |
raise errors.MissingHandler(cmd.name) |
|
70 |
else: |
|
71 |
# TODO: put hooks around processing each command?
|
|
72 |
handler(self, cmd) |
|
73 |
self.post_process() |
|
74 |
||
75 |
def pre_process(self): |
|
76 |
"""Hook for logic at start of processing.""" |
|
77 |
pass
|
|
78 |
||
79 |
def post_process(self): |
|
80 |
"""Hook for logic at end of processing.""" |
|
81 |
pass
|
|
82 |
||
83 |
def progress_handler(self, cmd): |
|
84 |
"""Process a ProgressCommand.""" |
|
85 |
raise NotImplementedError(self.progress_handler) |
|
86 |
||
87 |
def blob_handler(self, cmd): |
|
88 |
"""Process a BlobCommand.""" |
|
89 |
raise NotImplementedError(self.blob_handler) |
|
90 |
||
91 |
def checkpoint_handler(self, cmd): |
|
92 |
"""Process a CheckpointCommand.""" |
|
93 |
raise NotImplementedError(self.checkpoint_handler) |
|
94 |
||
95 |
def commit_handler(self, cmd): |
|
96 |
"""Process a CommitCommand.""" |
|
97 |
raise NotImplementedError(self.commit_handler) |
|
98 |
||
99 |
def reset_handler(self, cmd): |
|
100 |
"""Process a ResetCommand.""" |
|
101 |
raise NotImplementedError(self.reset_handler) |
|
102 |
||
103 |
def tag_handler(self, cmd): |
|
104 |
"""Process a TagCommand.""" |
|
105 |
raise NotImplementedError(self.tag_handler) |
|
|
0.64.4
by Ian Clatworthy
abstract CommitHandler |
106 |
|
107 |
||
108 |
class CommitHandler(object): |
|
109 |
"""Base class for commit handling. |
|
110 |
|
|
111 |
Subclasses should override the pre_*, post_* and *_handler
|
|
112 |
methods as appropriate.
|
|
113 |
"""
|
|
114 |
||
115 |
def __init__(self, command): |
|
116 |
self.command = command |
|
117 |
||
118 |
def process(self): |
|
119 |
self.pre_process_files() |
|
120 |
for fc in self.command.file_iter(): |
|
121 |
try: |
|
122 |
handler = self.__class__.__dict__[fc.name + "_handler"] |
|
123 |
except KeyError: |
|
124 |
raise errors.MissingHandler(fc.name) |
|
125 |
else: |
|
126 |
handler(self, fc) |
|
127 |
self.post_process_files() |
|
128 |
||
129 |
def pre_process_files(self): |
|
130 |
"""Prepare for committing.""" |
|
131 |
pass
|
|
132 |
||
133 |
def post_process_files(self): |
|
134 |
"""Save the revision.""" |
|
135 |
pass
|
|
136 |
||
137 |
def modify_handler(self, filecmd): |
|
138 |
"""Handle a filemodify command.""" |
|
139 |
raise NotImplementedError(self.modify_handler) |
|
140 |
||
141 |
def delete_handler(self, filecmd): |
|
142 |
"""Handle a filedelete command.""" |
|
143 |
raise NotImplementedError(self.delete_handler) |
|
144 |
||
145 |
def copy_handler(self, filecmd): |
|
146 |
"""Handle a filecopy command.""" |
|
147 |
raise NotImplementedError(self.copy_handler) |
|
148 |
||
149 |
def rename_handler(self, filecmd): |
|
150 |
"""Handle a filerename command.""" |
|
151 |
raise NotImplementedError(self.rename_handler) |
|
152 |
||
153 |
def deleteall_handler(self, filecmd): |
|
154 |
"""Handle a filedeleteall command.""" |
|
155 |
raise NotImplementedError(self.deleteall_handler) |