~bzr/bzr-fastimport/0.6

« back to all changes in this revision

Viewing changes to commands.py

  • Committer: Ian Clatworthy
  • Date: 2008-02-14 06:28:42 UTC
  • Revision ID: ian.clatworthy@internode.on.net-20080214062842-x2yy4rk70ny1ounp
1st cut: gfi parser + --info processing method

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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']
 
22
FILE_COMMAND_NAMES = ['modify', 'delete', 'copy', 'rename', 'deleteall']
 
23
 
 
24
# File kinds
 
25
FILE_KIND = 'f'
 
26
SYMLINK_KIND = 's'
 
27
 
 
28
 
 
29
class ImportCommand(object):
 
30
    """Base class for import commands."""
 
31
 
 
32
    def __init__(self, name):
 
33
        self.name = name
 
34
 
 
35
 
 
36
class BlobCommand(ImportCommand):
 
37
 
 
38
    def __init__(self, mark, data):
 
39
        ImportCommand.__init__(self, 'blob')
 
40
        self.mark = mark
 
41
        self.data = data
 
42
 
 
43
 
 
44
class CheckpointCommand(ImportCommand):
 
45
 
 
46
    def __init__(self):
 
47
        ImportCommand.__init__(self, 'checkpoint')
 
48
 
 
49
 
 
50
class CommitCommand(ImportCommand):
 
51
 
 
52
    def __init__(self, ref, mark, author, committer, message, parents,
 
53
        file_iter):
 
54
        ImportCommand.__init__(self, 'commit')
 
55
        self.ref = ref
 
56
        self.mark = mark
 
57
        self.author = author
 
58
        self.committer = committer
 
59
        self.message = message
 
60
        self.parents = parents
 
61
        self.file_iter = file_iter
 
62
 
 
63
 
 
64
class ProgressCommand(ImportCommand):
 
65
 
 
66
    def __init__(self, message):
 
67
        ImportCommand.__init__(self, 'progress')
 
68
        self.message = message
 
69
 
 
70
 
 
71
class ResetCommand(ImportCommand):
 
72
 
 
73
    def __init__(self, ref, from_):
 
74
        ImportCommand.__init__(self, 'reset')
 
75
        self.ref = ref
 
76
        self.from_ = from_
 
77
 
 
78
 
 
79
class TagCommand(ImportCommand):
 
80
 
 
81
    def __init__(self, id, from_, tagger, message):
 
82
        ImportCommand.__init__(self, 'tag')
 
83
        self.id = id
 
84
        self.from_ = from_
 
85
        self.tagger = tagger
 
86
        self.message = message
 
87
 
 
88
 
 
89
class FileCommand(ImportCommand):
 
90
    """Base class for file commands."""
 
91
    pass
 
92
 
 
93
 
 
94
class FileModifyCommand(FileCommand):
 
95
 
 
96
    def __init__(self, path, kind, is_executable, dataref, data):
 
97
        # Either dataref or data should be null
 
98
        FileCommand.__init__(self, 'modify')
 
99
        self.path = path
 
100
        self.kind = kind
 
101
        self.is_executable = is_executable
 
102
        self.dataref = dataref
 
103
        self.data = data
 
104
 
 
105
 
 
106
class FileDeleteCommand(FileCommand):
 
107
 
 
108
    def __init__(self, path):
 
109
        FileCommand.__init__(self, 'delete')
 
110
        self.path = path
 
111
 
 
112
 
 
113
class FileCopyCommand(FileCommand):
 
114
 
 
115
    def __init__(self, src_path, dest_path):
 
116
        FileCommand.__init__(self, 'copy')
 
117
        self.src_path = src_path
 
118
        self.dest_path = dest_path
 
119
 
 
120
 
 
121
class FileRenameCommand(FileCommand):
 
122
 
 
123
    def __init__(self, src_path, dest_path):
 
124
        FileCommand.__init__(self, 'rename')
 
125
        self.src_path = src_path
 
126
        self.dest_path = dest_path
 
127
 
 
128
 
 
129
class FileDeleteAllCommand(FileCommand):
 
130
 
 
131
    def __init__(self, path):
 
132
        FileCommand.__init__(self, 'deleteall')