1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
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.
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.
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
21
from bzrlib.errors import (BzrError, NotBranchError, NotVersionedError,
25
class MultipleMoveError(BzrError):
26
""" Occurs when moving/renaming more than 2 files, but the last argument is not a directory
33
class NoMatchingFiles(BzrError):
34
""" No files found which could match the criteria
42
""" Move or rename given files.
44
: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
46
from bzrlib.builtins import tree_files
48
tree, rel_names = tree_files(names_list)
50
if os.path.isdir(names_list[-1]):
51
# move into existing directory
52
for pair in tree.move(rel_names[:-1], rel_names[-1]):
55
if len(names_list) != 2:
56
raise MultipleMoveError
57
tree.rename_one(rel_names[0], rel_names[1])
60
def remove(file_list, new=False):
61
""" Make selected files unversioned.
63
:param file_list: list of files/directories to be removed
65
:param new: if True, the 'added' files will be removed
68
from bzrlib.builtins import tree_files
70
tree, file_list = tree_files(file_list)
73
from bzrlib.delta import compare_trees
74
if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9):
75
added = [compare_trees(tree.basis_tree(), tree,
76
specific_files=file_list).added]
78
added = [tree.changes_from(tree.basis_tree(),
79
specific_files=file_list).added]
80
file_list = sorted([f[0] for f in added[0]], reverse=True)
81
if len(file_list) == 0:
84
tree.remove(file_list)
88
""" Get the status of a file.
90
:param filename: the full path to the file
92
:return: renamed | added | removed | modified | unchanged | unknown
95
from bzrlib.delta import compare_trees
96
from bzrlib.workingtree import WorkingTree
99
tree1 = WorkingTree.open_containing(filename)[0]
100
except NotBranchError:
103
branch = tree1.branch
104
tree2 = tree1.branch.repository.revision_tree(branch.last_revision())
106
# find the relative path to the given file (needed for proper delta)
107
wtpath = tree1.basedir
110
wtsplit = wtpath.split('/')
111
fpsplit = fullpath.split('/')
112
fpcopy = fullpath.split('/')
114
if i is not len(wtsplit):
115
if item == wtsplit[i]:
118
rel = '/'.join(fpcopy)
120
delta = tree1.changes_from(tree2,
122
specific_files=[rel])
124
if len(delta.renamed):
126
elif len(delta.added):
128
elif len(delta.removed):
130
elif len(delta.modified):
132
elif len(delta.unchanged):