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 |
|
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
21 |
from bzrlib.errors import (BzrError, NotBranchError, NotVersionedError, |
22 |
PermissionDenied) |
|
23 |
||
24 |
||
25 |
class DirectoryAlreadyExists(BzrError): |
|
26 |
""" The specified directory already exists |
|
27 |
|
|
28 |
May occur in:
|
|
29 |
fileops.mkdir()
|
|
30 |
"""
|
|
31 |
||
32 |
||
33 |
class MultipleMoveError(BzrError): |
|
34 |
""" Occurs when moving/renaming more than 2 files, but the last argument is not a directory |
|
35 |
|
|
36 |
May occur in:
|
|
37 |
fileops.move()
|
|
38 |
"""
|
|
39 |
||
40 |
||
41 |
class NoMatchingFiles(BzrError): |
|
42 |
""" No files found which could match the criteria |
|
43 |
|
|
44 |
May occur in:
|
|
45 |
fileops.remove()
|
|
46 |
"""
|
|
47 |
||
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
48 |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
49 |
def add(file_list, recursive=False): |
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
50 |
""" Add listed files to the branch. |
51 |
|
|
52 |
:param file_list - list of files to be added (using full paths)
|
|
53 |
|
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
54 |
:param recursive - if True, all unknown files will be added
|
55 |
|
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
56 |
:return: count of ignored files
|
57 |
"""
|
|
58 |
import bzrlib.add |
|
59 |
||
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
60 |
added, ignored = bzrlib.add.smart_add(file_list, recursive) |
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
61 |
|
62 |
match_len = 0 |
|
63 |
for glob, paths in ignored.items(): |
|
64 |
match_len += len(paths) |
|
65 |
||
66 |
return match_len |
|
67 |
||
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
68 |
def mkdir(directory): |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
69 |
""" Create new versioned directory. |
70 |
|
|
71 |
:param directory: the full path to the directory to be created
|
|
72 |
"""
|
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
73 |
from bzrlib.workingtree import WorkingTree |
74 |
||
75 |
try: |
|
76 |
os.mkdir(directory) |
|
77 |
except OSError, e: |
|
78 |
if e.errno == 17: |
|
79 |
raise DirectoryAlreadyExists(directory) |
|
80 |
else: |
|
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
81 |
wt, dd = WorkingTree.open_containing(directory) |
82 |
wt.add([dd]) |
|
0.8.1
by Szilveszter Farkas (Phanatic)
* backend/errors.py: some basic exceptions added |
83 |
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
84 |
def move(names_list): |
85 |
""" Move or rename given files. |
|
86 |
|
|
87 |
: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 |
88 |
"""
|
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
89 |
from bzrlib.builtins import tree_files |
90 |
||
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
91 |
tree, rel_names = tree_files(names_list) |
0.8.8
by Szilveszter Farkas (Phanatic)
2006-07-06 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
92 |
|
93 |
if os.path.isdir(names_list[-1]): |
|
94 |
# move into existing directory
|
|
95 |
for pair in tree.move(rel_names[:-1], rel_names[-1]): |
|
96 |
pass
|
|
97 |
else: |
|
98 |
if len(names_list) != 2: |
|
99 |
raise MultipleMoveError |
|
100 |
tree.rename_one(rel_names[0], rel_names[1]) |
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
101 |
|
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
102 |
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
103 |
def remove(file_list, new=False): |
104 |
""" Make selected files unversioned. |
|
105 |
|
|
106 |
:param file_list: list of files/directories to be removed
|
|
107 |
|
|
108 |
:param new: if True, the 'added' files will be removed
|
|
109 |
"""
|
|
0.8.29
by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups. |
110 |
import bzrlib |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
111 |
from bzrlib.builtins import tree_files |
112 |
||
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
113 |
tree, file_list = tree_files(file_list) |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
114 |
|
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
115 |
if new: |
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
116 |
from bzrlib.delta import compare_trees |
0.8.29
by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups. |
117 |
if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9): |
118 |
added = [compare_trees(tree.basis_tree(), tree, |
|
119 |
specific_files=file_list).added] |
|
120 |
else: |
|
121 |
added = [tree.changes_from(tree.basis_tree(), |
|
122 |
specific_files=file_list).added] |
|
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
123 |
file_list = sorted([f[0] for f in added[0]], reverse=True) |
124 |
if len(file_list) == 0: |
|
125 |
raise NoMatchingFiles |
|
126 |
||
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
127 |
tree.remove(file_list) |
128 |
||
0.8.2
by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented |
129 |
|
0.8.9
by Szilveszter Farkas (Phanatic)
2006-07-08 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
130 |
def rename(source, target): |
131 |
""" Rename a versioned file |
|
132 |
|
|
133 |
:param source: full path to the original file
|
|
134 |
|
|
135 |
:param target: full path to the new file
|
|
136 |
"""
|
|
137 |
move([source, target]) |
|
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
138 |
|
139 |
def status(filename): |
|
140 |
""" Get the status of a file. |
|
141 |
|
|
142 |
:param filename: the full path to the file
|
|
143 |
|
|
144 |
:return: renamed | added | removed | modified | unchanged | unknown
|
|
145 |
"""
|
|
0.8.23
by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update |
146 |
import bzrlib |
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
147 |
from bzrlib.delta import compare_trees |
148 |
from bzrlib.workingtree import WorkingTree |
|
149 |
||
150 |
try: |
|
151 |
tree1 = WorkingTree.open_containing(filename)[0] |
|
0.11.1
by Jelmer Vernooij
Eliminate olive.backend.errors. |
152 |
except NotBranchError: |
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
153 |
return 'unknown' |
154 |
||
155 |
branch = tree1.branch |
|
156 |
tree2 = tree1.branch.repository.revision_tree(branch.last_revision()) |
|
157 |
||
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
158 |
# find the relative path to the given file (needed for proper delta)
|
159 |
wtpath = tree1.basedir |
|
160 |
fullpath = filename |
|
161 |
i = 0 |
|
162 |
wtsplit = wtpath.split('/') |
|
163 |
fpsplit = fullpath.split('/') |
|
164 |
fpcopy = fullpath.split('/') |
|
165 |
for item in fpsplit: |
|
166 |
if i is not len(wtsplit): |
|
167 |
if item == wtsplit[i]: |
|
168 |
del fpcopy[0] |
|
169 |
i = i + 1 |
|
170 |
rel = '/'.join(fpcopy) |
|
171 |
||
0.11.3
by Jelmer Vernooij
Remove more unused functions, imports |
172 |
delta = tree1.changes_from(tree2, |
0.8.23
by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update |
173 |
want_unchanged=True, |
174 |
specific_files=[rel]) |
|
0.8.18
by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
175 |
|
0.8.13
by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
176 |
if len(delta.renamed): |
177 |
return 'renamed' |
|
178 |
elif len(delta.added): |
|
179 |
return 'added' |
|
180 |
elif len(delta.removed): |
|
181 |
return 'removed' |
|
182 |
elif len(delta.modified): |
|
183 |
return 'modified' |
|
184 |
elif len(delta.unchanged): |
|
185 |
return 'unchanged' |
|
186 |
else: |
|
187 |
return 'unknown' |