/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
"""Import command classes."""
18
19
20
# Lists of command names
21
COMMAND_NAMES = ['blob', 'checkpoint', 'commit', 'progress', 'reset', 'tag']
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
22
FILE_COMMAND_NAMES = ['filemodify', 'filedelete', 'filecopy', 'filerename',
23
    'filedeleteall']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
24
0.64.2 by Ian Clatworthy
use Bazaar file kinds
25
# Bazaar file kinds
26
FILE_KIND = 'file'
27
SYMLINK_KIND = 'symlink'
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
28
29
30
class ImportCommand(object):
31
    """Base class for import commands."""
32
33
    def __init__(self, name):
34
        self.name = name
0.64.9 by Ian Clatworthy
dump parameter for info processor
35
        # List of field names not to display
36
        self._binary = []
37
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
38
    def dump_str(self, names=None, child_lists=None, verbose=False):
39
        """Dump fields as a string.
40
41
        :param names: the list of fields to include or
42
            None for all public fields
43
        :param child_lists: dictionary of child command names to
44
            fields for that child command to include
45
        :param verbose: if True, prefix each line with the command class and
46
            display fields as a dictionary; if False, dump just the field
47
            values with tabs between them
48
        """
0.64.9 by Ian Clatworthy
dump parameter for info processor
49
        interesting = {}
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
50
        if names is None:
51
            fields = [k for k in self.__dict__.keys() if not k.startswith('_')]
52
        else:
53
            fields = names
54
        for field in fields:
55
            value = self.__dict__.get(field)
56
            if field in self._binary and value is not None:
57
                value = '(...)'
0.64.9 by Ian Clatworthy
dump parameter for info processor
58
            interesting[field] = value
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
59
        if verbose:
60
            return "%s: %s" % (self.__class__.__name__, interesting)
61
        else:
0.64.20 by Ian Clatworthy
clean-up fixes after filtering enhancements
62
            return "\t".join([str(interesting[k]) for k in fields])
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
63
64
65
class BlobCommand(ImportCommand):
66
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
67
    def __init__(self, mark, data, lineno=0):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
68
        ImportCommand.__init__(self, 'blob')
69
        self.mark = mark
70
        self.data = data
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
71
        self.lineno = lineno
72
        # Provide a unique id in case the mark is missing
73
        if mark is None:
74
            self.id = '@%d' % lineno
75
        else:
76
            self.id = ':' + mark
0.64.9 by Ian Clatworthy
dump parameter for info processor
77
        self._binary = ['data']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
78
79
80
class CheckpointCommand(ImportCommand):
81
82
    def __init__(self):
83
        ImportCommand.__init__(self, 'checkpoint')
84
85
86
class CommitCommand(ImportCommand):
87
88
    def __init__(self, ref, mark, author, committer, message, parents,
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
89
        file_iter, lineno=0):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
90
        ImportCommand.__init__(self, 'commit')
91
        self.ref = ref
92
        self.mark = mark
93
        self.author = author
94
        self.committer = committer
95
        self.message = message
96
        self.parents = parents
97
        self.file_iter = file_iter
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
98
        self.lineno = lineno
0.64.9 by Ian Clatworthy
dump parameter for info processor
99
        self._binary = ['file_iter']
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
100
        # Provide a unique id in case the mark is missing
101
        if mark is None:
102
            self.id = '@%d' % lineno
103
        else:
104
            self.id = ':' + mark
0.64.9 by Ian Clatworthy
dump parameter for info processor
105
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
106
    def dump_str(self, names=None, child_lists=None, verbose=False):
107
        result = [ImportCommand.dump_str(self, names, verbose=verbose)]
0.64.9 by Ian Clatworthy
dump parameter for info processor
108
        for f in self.file_iter():
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
109
            if child_lists is None:
110
                continue
111
            try:
112
                child_names = child_lists[f.name]
113
            except KeyError:
114
                continue
115
            result.append("\t%s" % f.dump_str(child_names, verbose=verbose))
0.64.9 by Ian Clatworthy
dump parameter for info processor
116
        return '\n'.join(result)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
117
118
119
class ProgressCommand(ImportCommand):
120
121
    def __init__(self, message):
122
        ImportCommand.__init__(self, 'progress')
123
        self.message = message
124
125
126
class ResetCommand(ImportCommand):
127
128
    def __init__(self, ref, from_):
129
        ImportCommand.__init__(self, 'reset')
130
        self.ref = ref
131
        self.from_ = from_
132
133
134
class TagCommand(ImportCommand):
135
136
    def __init__(self, id, from_, tagger, message):
137
        ImportCommand.__init__(self, 'tag')
138
        self.id = id
139
        self.from_ = from_
140
        self.tagger = tagger
141
        self.message = message
142
143
144
class FileCommand(ImportCommand):
145
    """Base class for file commands."""
146
    pass
147
148
149
class FileModifyCommand(FileCommand):
150
151
    def __init__(self, path, kind, is_executable, dataref, data):
152
        # Either dataref or data should be null
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
153
        FileCommand.__init__(self, 'filemodify')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
154
        self.path = path
155
        self.kind = kind
156
        self.is_executable = is_executable
157
        self.dataref = dataref
158
        self.data = data
0.64.9 by Ian Clatworthy
dump parameter for info processor
159
        self._binary = ['data']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
160
161
162
class FileDeleteCommand(FileCommand):
163
164
    def __init__(self, path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
165
        FileCommand.__init__(self, 'filedelete')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
166
        self.path = path
167
168
169
class FileCopyCommand(FileCommand):
170
171
    def __init__(self, src_path, dest_path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
172
        FileCommand.__init__(self, 'filecopy')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
173
        self.src_path = src_path
174
        self.dest_path = dest_path
175
176
177
class FileRenameCommand(FileCommand):
178
0.64.2 by Ian Clatworthy
use Bazaar file kinds
179
    def __init__(self, old_path, new_path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
180
        FileCommand.__init__(self, 'filerename')
0.64.2 by Ian Clatworthy
use Bazaar file kinds
181
        self.old_path = old_path
182
        self.new_path = new_path
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
183
184
185
class FileDeleteAllCommand(FileCommand):
186
0.64.2 by Ian Clatworthy
use Bazaar file kinds
187
    def __init__(self):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
188
        FileCommand.__init__(self, 'filedeleteall')