/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
0.64.60 by Ian Clatworthy
support merges when from clause implicit
88
    def __init__(self, ref, mark, author, committer, message, from_,
89
        merges, 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
0.64.60 by Ian Clatworthy
support merges when from clause implicit
96
        self.from_ = from_
97
        self.merges = merges
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
98
        self.file_iter = file_iter
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
99
        self.lineno = lineno
0.64.9 by Ian Clatworthy
dump parameter for info processor
100
        self._binary = ['file_iter']
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
101
        # Provide a unique id in case the mark is missing
102
        if mark is None:
103
            self.id = '@%d' % lineno
104
        else:
105
            self.id = ':' + mark
0.64.9 by Ian Clatworthy
dump parameter for info processor
106
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
107
    def dump_str(self, names=None, child_lists=None, verbose=False):
108
        result = [ImportCommand.dump_str(self, names, verbose=verbose)]
0.64.9 by Ian Clatworthy
dump parameter for info processor
109
        for f in self.file_iter():
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
110
            if child_lists is None:
111
                continue
112
            try:
113
                child_names = child_lists[f.name]
114
            except KeyError:
115
                continue
116
            result.append("\t%s" % f.dump_str(child_names, verbose=verbose))
0.64.9 by Ian Clatworthy
dump parameter for info processor
117
        return '\n'.join(result)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
118
119
120
class ProgressCommand(ImportCommand):
121
122
    def __init__(self, message):
123
        ImportCommand.__init__(self, 'progress')
124
        self.message = message
125
126
127
class ResetCommand(ImportCommand):
128
129
    def __init__(self, ref, from_):
130
        ImportCommand.__init__(self, 'reset')
131
        self.ref = ref
132
        self.from_ = from_
133
134
135
class TagCommand(ImportCommand):
136
137
    def __init__(self, id, from_, tagger, message):
138
        ImportCommand.__init__(self, 'tag')
139
        self.id = id
140
        self.from_ = from_
141
        self.tagger = tagger
142
        self.message = message
143
144
145
class FileCommand(ImportCommand):
146
    """Base class for file commands."""
147
    pass
148
149
150
class FileModifyCommand(FileCommand):
151
152
    def __init__(self, path, kind, is_executable, dataref, data):
153
        # Either dataref or data should be null
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
154
        FileCommand.__init__(self, 'filemodify')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
155
        self.path = path
156
        self.kind = kind
157
        self.is_executable = is_executable
158
        self.dataref = dataref
159
        self.data = data
0.64.9 by Ian Clatworthy
dump parameter for info processor
160
        self._binary = ['data']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
161
162
163
class FileDeleteCommand(FileCommand):
164
165
    def __init__(self, path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
166
        FileCommand.__init__(self, 'filedelete')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
167
        self.path = path
168
169
170
class FileCopyCommand(FileCommand):
171
172
    def __init__(self, src_path, dest_path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
173
        FileCommand.__init__(self, 'filecopy')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
174
        self.src_path = src_path
175
        self.dest_path = dest_path
176
177
178
class FileRenameCommand(FileCommand):
179
0.64.2 by Ian Clatworthy
use Bazaar file kinds
180
    def __init__(self, old_path, new_path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
181
        FileCommand.__init__(self, 'filerename')
0.64.2 by Ian Clatworthy
use Bazaar file kinds
182
        self.old_path = old_path
183
        self.new_path = new_path
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
184
185
186
class FileDeleteAllCommand(FileCommand):
187
0.64.2 by Ian Clatworthy
use Bazaar file kinds
188
    def __init__(self):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
189
        FileCommand.__init__(self, 'filedeleteall')