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.38
by Szilveszter Farkas (Phanatic)
Implemented Move functionality; move() backend code refined. |
25 |
NonExistingSource, NotBranchError, NotSameBranchError, |
0.8.56
by Szilveszter Farkas (Phanatic)
Handle permission denied exceptions properly. |
26 |
NotVersionedError, PermissionDenied) |
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
27 |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
28 |
def add(file_list, recursive=False): |
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
29 |
""" Add listed files to the branch. |
30 |
|
|
31 |
:param file_list - list of files to be added (using full paths)
|
|
32 |
|
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
33 |
:param recursive - if True, all unknown files will be added
|
34 |
|
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
35 |
:return: count of ignored files
|
36 |
"""
|
|
37 |
import bzrlib.add |
|
38 |
||
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
39 |
try: |
40 |
added, ignored = bzrlib.add.smart_add(file_list, recursive) |
|
41 |
except errors.NotBranchError: |
|
42 |
raise NotBranchError |
|
43 |
except: |
|
44 |
raise
|
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
45 |
|
46 |
match_len = 0 |
|
47 |
for glob, paths in ignored.items(): |
|
48 |
match_len += len(paths) |
|
49 |
||
50 |
return match_len |
|
51 |
||
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
52 |
def mkdir(directory): |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
53 |
""" Create new versioned directory. |
54 |
|
|
55 |
:param directory: the full path to the directory to be created
|
|
56 |
"""
|
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
57 |
from bzrlib.workingtree import WorkingTree |
58 |
||
59 |
try: |
|
60 |
os.mkdir(directory) |
|
61 |
except OSError, e: |
|
62 |
if e.errno == 17: |
|
63 |
raise DirectoryAlreadyExists(directory) |
|
64 |
else: |
|
0.8.37
by Szilveszter Farkas (Phanatic)
Implemented Make directory functionality; some cleanups. |
65 |
try: |
66 |
wt, dd = WorkingTree.open_containing(directory) |
|
67 |
except errors.NotBranchError: |
|
68 |
raise NotBranchError |
|
69 |
else: |
|
70 |
wt.add([dd]) |
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
71 |
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
72 |
def move(names_list): |
73 |
""" Move or rename given files. |
|
74 |
|
|
75 |
: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 |
76 |
"""
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
77 |
from bzrlib.builtins import tree_files |
78 |
||
79 |
if len(names_list) < 2: |
|
80 |
raise MissingArgumentError |
|
0.8.38
by Szilveszter Farkas (Phanatic)
Implemented Move functionality; move() backend code refined. |
81 |
|
82 |
try: |
|
83 |
tree, rel_names = tree_files(names_list) |
|
84 |
except errors.NotBranchError: |
|
85 |
raise NotBranchError |
|
86 |
except errors.BzrCommandError: |
|
87 |
# not the same branch presumably
|
|
88 |
raise NotSameBranchError |
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
89 |
|
90 |
if os.path.isdir(names_list[-1]): |
|
91 |
# move into existing directory
|
|
92 |
for pair in tree.move(rel_names[:-1], rel_names[-1]): |
|
93 |
pass
|
|
94 |
else: |
|
95 |
if len(names_list) != 2: |
|
96 |
raise MultipleMoveError |
|
97 |
tree.rename_one(rel_names[0], rel_names[1]) |
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
98 |
|
99 |
def remove(file_list, new=False): |
|
100 |
""" Make selected files unversioned. |
|
101 |
|
|
102 |
:param file_list: list of files/directories to be removed
|
|
103 |
|
|
104 |
:param new: if True, the 'added' files will be removed
|
|
105 |
"""
|
|
0.8.29
by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups. |
106 |
import bzrlib |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
107 |
from bzrlib.builtins import tree_files |
108 |
||
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
109 |
try: |
110 |
tree, file_list = tree_files(file_list) |
|
111 |
except errors.NotBranchError: |
|
112 |
raise NotBranchError |
|
113 |
except: |
|
114 |
raise
|
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
115 |
|
116 |
if new is False: |
|
117 |
if file_list is None: |
|
118 |
raise NoFilesSpecified |
|
119 |
else: |
|
120 |
from bzrlib.delta import compare_trees |
|
0.8.29
by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups. |
121 |
if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9): |
122 |
added = [compare_trees(tree.basis_tree(), tree, |
|
123 |
specific_files=file_list).added] |
|
124 |
else: |
|
125 |
added = [tree.changes_from(tree.basis_tree(), |
|
126 |
specific_files=file_list).added] |
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
127 |
file_list = sorted([f[0] for f in added[0]], reverse=True) |
128 |
if len(file_list) == 0: |
|
129 |
raise NoMatchingFiles |
|
130 |
||
131 |
try: |
|
132 |
tree.remove(file_list) |
|
133 |
except errors.NotVersionedError: |
|
134 |
raise NotVersionedError |
|
135 |
||
0.8.9
by Szilveszter Farkas (Phanatic)
2006-07-08 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
136 |
def rename(source, target): |
137 |
""" Rename a versioned file |
|
138 |
|
|
139 |
:param source: full path to the original file
|
|
140 |
|
|
141 |
:param target: full path to the new file
|
|
142 |
"""
|
|
143 |
if os.access(source, os.F_OK) is not True: |
|
144 |
raise NonExistingSource(source) |
|
145 |
||
146 |
move([source, target]) |
|
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
147 |
|
148 |
def status(filename): |
|
149 |
""" Get the status of a file. |
|
150 |
|
|
151 |
:param filename: the full path to the file
|
|
152 |
|
|
153 |
:return: renamed | added | removed | modified | unchanged | unknown
|
|
154 |
"""
|
|
0.8.23
by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update |
155 |
import bzrlib |
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
156 |
from bzrlib.delta import compare_trees |
157 |
from bzrlib.workingtree import WorkingTree |
|
158 |
||
159 |
try: |
|
160 |
tree1 = WorkingTree.open_containing(filename)[0] |
|
161 |
except errors.NotBranchError: |
|
162 |
return 'unknown' |
|
0.8.56
by Szilveszter Farkas (Phanatic)
Handle permission denied exceptions properly. |
163 |
except errors.PermissionDenied: |
164 |
raise PermissionDenied(filename) |
|
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
165 |
|
166 |
branch = tree1.branch |
|
167 |
tree2 = tree1.branch.repository.revision_tree(branch.last_revision()) |
|
168 |
||
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
169 |
# find the relative path to the given file (needed for proper delta)
|
170 |
wtpath = tree1.basedir |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
171 |
#print "DEBUG: wtpath =", wtpath
|
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
172 |
fullpath = filename |
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
173 |
#print "DEBUG: fullpath =", fullpath
|
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
174 |
i = 0 |
175 |
wtsplit = wtpath.split('/') |
|
176 |
fpsplit = fullpath.split('/') |
|
177 |
fpcopy = fullpath.split('/') |
|
178 |
for item in fpsplit: |
|
179 |
if i is not len(wtsplit): |
|
180 |
if item == wtsplit[i]: |
|
181 |
del fpcopy[0] |
|
182 |
i = i + 1 |
|
183 |
rel = '/'.join(fpcopy) |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
184 |
#print "DEBUG: rel =", rel
|
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
185 |
|
0.8.23
by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update |
186 |
if bzrlib.version_info[1] < 9: |
187 |
delta = compare_trees(old_tree=tree2, |
|
188 |
new_tree=tree1, |
|
189 |
want_unchanged=True, |
|
190 |
specific_files=[rel]) |
|
191 |
else: |
|
192 |
delta = tree1.changes_from(tree2, |
|
193 |
want_unchanged=True, |
|
194 |
specific_files=[rel]) |
|
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
195 |
|
196 |
""" Debug information (could be usable in the future, so didn't cut out) |
|
197 |
print "DEBUG: delta.renamed:"
|
|
198 |
for path, id, kind, text_modified, meta_modified in delta.renamed:
|
|
199 |
print path
|
|
200 |
print
|
|
201 |
print "DEBUG: delta.added:"
|
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
202 |
for path, id, kind in delta.added:
|
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
203 |
print path
|
204 |
print
|
|
205 |
print "DEBUG: delta.removed:"
|
|
206 |
for path, id, kind, text_modified, meta_modified in delta.removed:
|
|
207 |
print path
|
|
208 |
print
|
|
209 |
print "DEBUG: delta.modified:"
|
|
210 |
for path, id, kind, text_modified, meta_modified in delta.modified:
|
|
211 |
print path
|
|
212 |
print
|
|
213 |
print "DEBUG: delta.unchanged:"
|
|
214 |
for path, id, kind in delta.unchanged:
|
|
215 |
print path
|
|
216 |
"""
|
|
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
217 |
|
218 |
if len(delta.renamed): |
|
219 |
return 'renamed' |
|
220 |
elif len(delta.added): |
|
221 |
return 'added' |
|
222 |
elif len(delta.removed): |
|
223 |
return 'removed' |
|
224 |
elif len(delta.modified): |
|
225 |
return 'modified' |
|
226 |
elif len(delta.unchanged): |
|
227 |
return 'unchanged' |
|
228 |
else: |
|
229 |
return 'unknown' |