/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/backend/fileops.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-08-03 10:44:56 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060803104456-b5f901b6775ef158
Push dialog now displays stored location

2006-08-03  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * olive/frontend/gtk/push.py: display known push location if available
    * olive/backend/info.py: implemented get_push_location()

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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
 
20
 
 
21
import bzrlib.errors as errors
 
22
 
 
23
from errors import (DirectoryAlreadyExists, MissingArgumentError,
 
24
                    MultipleMoveError, NoFilesSpecified, NoMatchingFiles,
 
25
                    NonExistingSource, NotBranchError, NotVersionedError)
 
26
 
 
27
def add(file_list, recursive=False):
 
28
    """ Add listed files to the branch. 
 
29
    
 
30
    :param file_list - list of files to be added (using full paths)
 
31
    
 
32
    :param recursive - if True, all unknown files will be added
 
33
    
 
34
    :return: count of ignored files
 
35
    """
 
36
    import bzrlib.add
 
37
    
 
38
    try:
 
39
        added, ignored = bzrlib.add.smart_add(file_list, recursive)
 
40
    except errors.NotBranchError:
 
41
        raise NotBranchError
 
42
    except:
 
43
        raise
 
44
    
 
45
    match_len = 0
 
46
    for glob, paths in ignored.items():
 
47
        match_len += len(paths)
 
48
    
 
49
    return match_len
 
50
 
 
51
def mkdir(directory):
 
52
    """ Create new versioned directory.
 
53
    
 
54
    :param directory: the full path to the directory to be created
 
55
    """
 
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:
 
64
        wt, dd = WorkingTree.open_containing(directory)
 
65
        wt.add([dd])
 
66
 
 
67
def move(names_list):
 
68
    """ Move or rename given files.
 
69
    
 
70
    :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
 
71
    """
 
72
    from bzrlib.builtins import tree_files
 
73
    
 
74
    if len(names_list) < 2:
 
75
        raise MissingArgumentError
 
76
    tree, rel_names = tree_files(names_list)
 
77
        
 
78
    if os.path.isdir(names_list[-1]):
 
79
        # move into existing directory
 
80
        for pair in tree.move(rel_names[:-1], rel_names[-1]):
 
81
            pass
 
82
    else:
 
83
        if len(names_list) != 2:
 
84
            raise MultipleMoveError
 
85
        tree.rename_one(rel_names[0], rel_names[1])
 
86
 
 
87
def remove(file_list, new=False):
 
88
    """ Make selected files unversioned.
 
89
    
 
90
    :param file_list: list of files/directories to be removed
 
91
    
 
92
    :param new: if True, the 'added' files will be removed
 
93
    """
 
94
    from bzrlib.builtins import tree_files
 
95
    
 
96
    try:
 
97
        tree, file_list = tree_files(file_list)
 
98
    except errors.NotBranchError:
 
99
        raise NotBranchError
 
100
    except:
 
101
        raise
 
102
    
 
103
    if new is False:
 
104
        if file_list is None:
 
105
            raise NoFilesSpecified
 
106
    else:
 
107
        from bzrlib.delta import compare_trees
 
108
        added = [compare_trees(tree.basis_tree(), tree,
 
109
                               specific_files=file_list).added]
 
110
        file_list = sorted([f[0] for f in added[0]], reverse=True)
 
111
        if len(file_list) == 0:
 
112
            raise NoMatchingFiles
 
113
    
 
114
    try:
 
115
        tree.remove(file_list)
 
116
    except errors.NotVersionedError:
 
117
        raise NotVersionedError
 
118
 
 
119
def rename(source, target):
 
120
    """ Rename a versioned file
 
121
    
 
122
    :param source: full path to the original file
 
123
    
 
124
    :param target: full path to the new file
 
125
    """
 
126
    if os.access(source, os.F_OK) is not True:
 
127
        raise NonExistingSource(source)
 
128
    
 
129
    move([source, target])
 
130
 
 
131
def status(filename):
 
132
    """ Get the status of a file.
 
133
    
 
134
    :param filename: the full path to the file
 
135
    
 
136
    :return: renamed | added | removed | modified | unchanged | unknown
 
137
    """
 
138
    import bzrlib
 
139
    from bzrlib.delta import compare_trees
 
140
    from bzrlib.workingtree import WorkingTree
 
141
    
 
142
    try:
 
143
        tree1 = WorkingTree.open_containing(filename)[0]
 
144
    except errors.NotBranchError:
 
145
        return 'unknown'
 
146
    
 
147
    branch = tree1.branch
 
148
    tree2 = tree1.branch.repository.revision_tree(branch.last_revision())
 
149
    
 
150
    # find the relative path to the given file (needed for proper delta)
 
151
    wtpath = tree1.basedir
 
152
    #print "DEBUG: wtpath =", wtpath
 
153
    fullpath = filename
 
154
    #print "DEBUG: fullpath =", fullpath
 
155
    i = 0
 
156
    wtsplit = wtpath.split('/')
 
157
    fpsplit = fullpath.split('/')
 
158
    fpcopy = fullpath.split('/')
 
159
    for item in fpsplit:
 
160
        if i is not len(wtsplit):
 
161
            if item == wtsplit[i]:
 
162
                del fpcopy[0]
 
163
            i = i + 1
 
164
    rel = '/'.join(fpcopy)
 
165
    #print "DEBUG: rel =", rel
 
166
    
 
167
    if bzrlib.version_info[1] < 9:
 
168
        delta = compare_trees(old_tree=tree2,
 
169
                              new_tree=tree1,
 
170
                              want_unchanged=True,
 
171
                              specific_files=[rel])
 
172
    else:
 
173
        delta = tree1.changes_from(tree2,
 
174
                                   want_unchanged=True,
 
175
                                   specific_files=[rel])
 
176
    
 
177
    """ Debug information (could be usable in the future, so didn't cut out)
 
178
    print "DEBUG: delta.renamed:"
 
179
    for path, id, kind, text_modified, meta_modified in delta.renamed:
 
180
        print path
 
181
    print
 
182
    print "DEBUG: delta.added:"
 
183
    for path, id, kind in delta.added:
 
184
        print path
 
185
    print
 
186
    print "DEBUG: delta.removed:"
 
187
    for path, id, kind, text_modified, meta_modified in delta.removed:
 
188
        print path
 
189
    print
 
190
    print "DEBUG: delta.modified:"
 
191
    for path, id, kind, text_modified, meta_modified in delta.modified:
 
192
        print path
 
193
    print
 
194
    print "DEBUG: delta.unchanged:"
 
195
    for path, id, kind in delta.unchanged:
 
196
        print path
 
197
    """
 
198
    
 
199
    if len(delta.renamed):
 
200
        return 'renamed'
 
201
    elif len(delta.added):
 
202
        return 'added'
 
203
    elif len(delta.removed):
 
204
        return 'removed'
 
205
    elif len(delta.modified):
 
206
        return 'modified'
 
207
    elif len(delta.unchanged):
 
208
        return 'unchanged'
 
209
    else:
 
210
        return 'unknown'