/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.9 by Szilveszter Farkas (Phanatic)
2006-07-08 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
4
#
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
9
#
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
14
#
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
import os
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
20
21
import bzrlib.errors as errors
22
0.8.8 by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
23
from errors import (DirectoryAlreadyExists, MissingArgumentError,
24
                    MultipleMoveError, NoFilesSpecified, NoMatchingFiles,
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
25
                    NonExistingSource, NotBranchError, NotVersionedError)
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
26
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
27
def add(file_list, recursive=False):
0.8.8 by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
28
    """ Add listed files to the branch. 
29
    
30
    :param file_list - list of files to be added (using full paths)
31
    
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
32
    :param recursive - if True, all unknown files will be added
33
    
0.8.8 by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
34
    :return: count of ignored files
35
    """
36
    import bzrlib.add
37
    
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
38
    try:
39
        added, ignored = bzrlib.add.smart_add(file_list, recursive)
40
    except errors.NotBranchError:
41
        raise NotBranchError
42
    except:
43
        raise
0.8.8 by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
44
    
45
    match_len = 0
46
    for glob, paths in ignored.items():
47
        match_len += len(paths)
48
    
49
    return match_len
50
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
51
def mkdir(directory):
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
52
    """ Create new versioned directory.
53
    
54
    :param directory: the full path to the directory to be created
55
    """
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
56
    from bzrlib.workingtree import WorkingTree
57
    
58
    try:
59
        os.mkdir(directory)
60
    except OSError, e:
61
        if e.errno == 17:
62
            raise DirectoryAlreadyExists(directory)
63
    else:
0.8.37 by Szilveszter Farkas (Phanatic)
Implemented Make directory functionality; some cleanups.
64
        try:
65
            wt, dd = WorkingTree.open_containing(directory)
66
        except errors.NotBranchError:
67
            raise NotBranchError
68
        else:
69
            wt.add([dd])
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
70
0.8.8 by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
71
def move(names_list):
72
    """ Move or rename given files.
73
    
74
    :param file_list: if two elements, then rename the first to the second, if more elements then move all of them to the directory specified in the last element
0.8.1 by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added
75
    """
0.8.8 by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
76
    from bzrlib.builtins import tree_files
77
    
78
    if len(names_list) < 2:
79
        raise MissingArgumentError
80
    tree, rel_names = tree_files(names_list)
81
        
82
    if os.path.isdir(names_list[-1]):
83
        # move into existing directory
84
        for pair in tree.move(rel_names[:-1], rel_names[-1]):
85
            pass
86
    else:
87
        if len(names_list) != 2:
88
            raise MultipleMoveError
89
        tree.rename_one(rel_names[0], rel_names[1])
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
90
91
def remove(file_list, new=False):
92
    """ Make selected files unversioned.
93
    
94
    :param file_list: list of files/directories to be removed
95
    
96
    :param new: if True, the 'added' files will be removed
97
    """
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
98
    import bzrlib
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
99
    from bzrlib.builtins import tree_files
100
    
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
101
    try:
102
        tree, file_list = tree_files(file_list)
103
    except errors.NotBranchError:
104
        raise NotBranchError
105
    except:
106
        raise
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
107
    
108
    if new is False:
109
        if file_list is None:
110
            raise NoFilesSpecified
111
    else:
112
        from bzrlib.delta import compare_trees
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
113
        if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9):
114
            added = [compare_trees(tree.basis_tree(), tree,
115
                                   specific_files=file_list).added]
116
        else:
117
            added = [tree.changes_from(tree.basis_tree(),
118
                                       specific_files=file_list).added]
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
119
        file_list = sorted([f[0] for f in added[0]], reverse=True)
120
        if len(file_list) == 0:
121
            raise NoMatchingFiles
122
    
123
    try:
124
        tree.remove(file_list)
125
    except errors.NotVersionedError:
126
        raise NotVersionedError
127
0.8.9 by Szilveszter Farkas (Phanatic)
2006-07-08 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
128
def rename(source, target):
129
    """ Rename a versioned file
130
    
131
    :param source: full path to the original file
132
    
133
    :param target: full path to the new file
134
    """
135
    if os.access(source, os.F_OK) is not True:
136
        raise NonExistingSource(source)
137
    
138
    move([source, target])
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
139
140
def status(filename):
141
    """ Get the status of a file.
142
    
143
    :param filename: the full path to the file
144
    
145
    :return: renamed | added | removed | modified | unchanged | unknown
146
    """
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
147
    import bzrlib
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
148
    from bzrlib.delta import compare_trees
149
    from bzrlib.workingtree import WorkingTree
150
    
151
    try:
152
        tree1 = WorkingTree.open_containing(filename)[0]
153
    except errors.NotBranchError:
154
        return 'unknown'
155
    
156
    branch = tree1.branch
157
    tree2 = tree1.branch.repository.revision_tree(branch.last_revision())
158
    
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
159
    # find the relative path to the given file (needed for proper delta)
160
    wtpath = tree1.basedir
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
161
    #print "DEBUG: wtpath =", wtpath
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
162
    fullpath = filename
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
163
    #print "DEBUG: fullpath =", fullpath
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
164
    i = 0
165
    wtsplit = wtpath.split('/')
166
    fpsplit = fullpath.split('/')
167
    fpcopy = fullpath.split('/')
168
    for item in fpsplit:
169
        if i is not len(wtsplit):
170
            if item == wtsplit[i]:
171
                del fpcopy[0]
172
            i = i + 1
173
    rel = '/'.join(fpcopy)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
174
    #print "DEBUG: rel =", rel
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
175
    
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
176
    if bzrlib.version_info[1] < 9:
177
        delta = compare_trees(old_tree=tree2,
178
                              new_tree=tree1,
179
                              want_unchanged=True,
180
                              specific_files=[rel])
181
    else:
182
        delta = tree1.changes_from(tree2,
183
                                   want_unchanged=True,
184
                                   specific_files=[rel])
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
185
    
186
    """ Debug information (could be usable in the future, so didn't cut out)
187
    print "DEBUG: delta.renamed:"
188
    for path, id, kind, text_modified, meta_modified in delta.renamed:
189
        print path
190
    print
191
    print "DEBUG: delta.added:"
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
192
    for path, id, kind in delta.added:
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
193
        print path
194
    print
195
    print "DEBUG: delta.removed:"
196
    for path, id, kind, text_modified, meta_modified in delta.removed:
197
        print path
198
    print
199
    print "DEBUG: delta.modified:"
200
    for path, id, kind, text_modified, meta_modified in delta.modified:
201
        print path
202
    print
203
    print "DEBUG: delta.unchanged:"
204
    for path, id, kind in delta.unchanged:
205
        print path
206
    """
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
207
    
208
    if len(delta.renamed):
209
        return 'renamed'
210
    elif len(delta.added):
211
        return 'added'
212
    elif len(delta.removed):
213
        return 'removed'
214
    elif len(delta.modified):
215
        return 'modified'
216
    elif len(delta.unchanged):
217
        return 'unchanged'
218
    else:
219
        return 'unknown'