/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
67
    def __init__(self, mark, data):
68
        ImportCommand.__init__(self, 'blob')
69
        self.mark = mark
70
        self.data = data
0.64.9 by Ian Clatworthy
dump parameter for info processor
71
        self._binary = ['data']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
72
73
74
class CheckpointCommand(ImportCommand):
75
76
    def __init__(self):
77
        ImportCommand.__init__(self, 'checkpoint')
78
79
80
class CommitCommand(ImportCommand):
81
82
    def __init__(self, ref, mark, author, committer, message, parents,
83
        file_iter):
84
        ImportCommand.__init__(self, 'commit')
85
        self.ref = ref
86
        self.mark = mark
87
        self.author = author
88
        self.committer = committer
89
        self.message = message
90
        self.parents = parents
91
        self.file_iter = file_iter
0.64.9 by Ian Clatworthy
dump parameter for info processor
92
        self._binary = ['file_iter']
93
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
94
    def dump_str(self, names=None, child_lists=None, verbose=False):
95
        result = [ImportCommand.dump_str(self, names, verbose=verbose)]
0.64.9 by Ian Clatworthy
dump parameter for info processor
96
        for f in self.file_iter():
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
97
            if child_lists is None:
98
                continue
99
            try:
100
                child_names = child_lists[f.name]
101
            except KeyError:
102
                continue
103
            result.append("\t%s" % f.dump_str(child_names, verbose=verbose))
0.64.9 by Ian Clatworthy
dump parameter for info processor
104
        return '\n'.join(result)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
105
106
107
class ProgressCommand(ImportCommand):
108
109
    def __init__(self, message):
110
        ImportCommand.__init__(self, 'progress')
111
        self.message = message
112
113
114
class ResetCommand(ImportCommand):
115
116
    def __init__(self, ref, from_):
117
        ImportCommand.__init__(self, 'reset')
118
        self.ref = ref
119
        self.from_ = from_
120
121
122
class TagCommand(ImportCommand):
123
124
    def __init__(self, id, from_, tagger, message):
125
        ImportCommand.__init__(self, 'tag')
126
        self.id = id
127
        self.from_ = from_
128
        self.tagger = tagger
129
        self.message = message
130
131
132
class FileCommand(ImportCommand):
133
    """Base class for file commands."""
134
    pass
135
136
137
class FileModifyCommand(FileCommand):
138
139
    def __init__(self, path, kind, is_executable, dataref, data):
140
        # Either dataref or data should be null
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
141
        FileCommand.__init__(self, 'filemodify')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
142
        self.path = path
143
        self.kind = kind
144
        self.is_executable = is_executable
145
        self.dataref = dataref
146
        self.data = data
0.64.9 by Ian Clatworthy
dump parameter for info processor
147
        self._binary = ['data']
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
148
149
150
class FileDeleteCommand(FileCommand):
151
152
    def __init__(self, path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
153
        FileCommand.__init__(self, 'filedelete')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
154
        self.path = path
155
156
157
class FileCopyCommand(FileCommand):
158
159
    def __init__(self, src_path, dest_path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
160
        FileCommand.__init__(self, 'filecopy')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
161
        self.src_path = src_path
162
        self.dest_path = dest_path
163
164
165
class FileRenameCommand(FileCommand):
166
0.64.2 by Ian Clatworthy
use Bazaar file kinds
167
    def __init__(self, old_path, new_path):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
168
        FileCommand.__init__(self, 'filerename')
0.64.2 by Ian Clatworthy
use Bazaar file kinds
169
        self.old_path = old_path
170
        self.new_path = new_path
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
171
172
173
class FileDeleteAllCommand(FileCommand):
174
0.64.2 by Ian Clatworthy
use Bazaar file kinds
175
    def __init__(self):
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
176
        FileCommand.__init__(self, 'filedeleteall')