/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: Jelmer Vernooij
  • Date: 2006-09-04 23:33:13 UTC
  • mto: (0.8.83 merge)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060904233313-f8d303ec87f6de13
Eliminate olive.backend.errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
 
21
 
import bzrlib.errors as errors
22
 
 
23
 
from errors import (DirectoryAlreadyExists, MissingArgumentError,
24
 
                    MultipleMoveError, NoFilesSpecified, NoMatchingFiles,
25
 
                    NonExistingSource, NotBranchError, NotSameBranchError,
26
 
                    NotVersionedError, PermissionDenied)
 
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
 
27
48
 
28
49
def add(file_list, recursive=False):
29
50
    """ Add listed files to the branch. 
36
57
    """
37
58
    import bzrlib.add
38
59
    
39
 
    try:
40
 
        added, ignored = bzrlib.add.smart_add(file_list, recursive)
41
 
    except errors.NotBranchError:
42
 
        raise NotBranchError
43
 
    except:
44
 
        raise
 
60
    added, ignored = bzrlib.add.smart_add(file_list, recursive)
45
61
    
46
62
    match_len = 0
47
63
    for glob, paths in ignored.items():
62
78
        if e.errno == 17:
63
79
            raise DirectoryAlreadyExists(directory)
64
80
    else:
65
 
        try:
66
 
            wt, dd = WorkingTree.open_containing(directory)
67
 
        except errors.NotBranchError:
68
 
            raise NotBranchError
69
 
        else:
70
 
            wt.add([dd])
 
81
        wt, dd = WorkingTree.open_containing(directory)
 
82
        wt.add([dd])
71
83
 
72
84
def move(names_list):
73
85
    """ Move or rename given files.
76
88
    """
77
89
    from bzrlib.builtins import tree_files
78
90
    
79
 
    if len(names_list) < 2:
80
 
        raise MissingArgumentError
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
 
91
    tree, rel_names = tree_files(names_list)
89
92
        
90
93
    if os.path.isdir(names_list[-1]):
91
94
        # move into existing directory
96
99
            raise MultipleMoveError
97
100
        tree.rename_one(rel_names[0], rel_names[1])
98
101
 
 
102
 
99
103
def remove(file_list, new=False):
100
104
    """ Make selected files unversioned.
101
105
    
106
110
    import bzrlib
107
111
    from bzrlib.builtins import tree_files
108
112
    
109
 
    try:
110
 
        tree, file_list = tree_files(file_list)
111
 
    except errors.NotBranchError:
112
 
        raise NotBranchError
113
 
    except:
114
 
        raise
 
113
    tree, file_list = tree_files(file_list)
115
114
    
116
 
    if new is False:
117
 
        if file_list is None:
118
 
            raise NoFilesSpecified
119
 
    else:
 
115
    if new:
120
116
        from bzrlib.delta import compare_trees
121
117
        if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9):
122
118
            added = [compare_trees(tree.basis_tree(), tree,
128
124
        if len(file_list) == 0:
129
125
            raise NoMatchingFiles
130
126
    
131
 
    try:
132
 
        tree.remove(file_list)
133
 
    except errors.NotVersionedError:
134
 
        raise NotVersionedError
 
127
    tree.remove(file_list)
 
128
 
135
129
 
136
130
def rename(source, target):
137
131
    """ Rename a versioned file
140
134
    
141
135
    :param target: full path to the new file
142
136
    """
143
 
    if os.access(source, os.F_OK) is not True:
144
 
        raise NonExistingSource(source)
145
 
    
146
137
    move([source, target])
147
138
 
148
139
def status(filename):
158
149
    
159
150
    try:
160
151
        tree1 = WorkingTree.open_containing(filename)[0]
161
 
    except errors.NotBranchError:
 
152
    except NotBranchError:
162
153
        return 'unknown'
163
 
    except errors.PermissionDenied:
164
 
        raise PermissionDenied(filename)
165
154
    
166
155
    branch = tree1.branch
167
156
    tree2 = tree1.branch.repository.revision_tree(branch.last_revision())