1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import os
18
19 from libxyz.core.utils import bstring, ustring
20 from libxyz.vfs import types
21
23 """
24 Abstract interface for VFS objects
25 """
26
27 - def __init__(self, xyz, path, full_path, ext_path, driver, parent,
28 enc=None, **kwargs):
29 self.xyz = xyz
30 self.enc = enc or xyzenc
31 self.path = bstring(path, self.enc)
32 self.full_path = bstring(full_path, self.enc)
33 self.ext_path = bstring(ext_path, self.enc)
34 self.parent = parent
35 self.driver = driver
36 self.kwargs = kwargs
37
38
39 self.name = os.path.basename(self.path)
40
41
42 self.ftype = None
43
44
45 self.atime = None
46
47
48 self.mtime = None
49
50
51 self.ctime = None
52
53
54 self.size = None
55
56
57 self.uid = None
58
59
60 self.gid = None
61
62
63 self.mode = None
64
65
66 self.inode = None
67
68
69 self.vtype = None
70
71
72 self.visual = None
73
74
75 self.info = None
76
77
78 self.data = None
79
80
81 self.attributes = ()
82
83
84 self._prepare()
85
86 self.__ni_msg = _(u"Feature not implemented")
87
88
89
91 """
92 Return True if instance is representing regular file
93 """
94
95 return isinstance(self.ftype, types.VFSTypeFile)
96
97
98
100 """
101 Return True if instance is representing directory
102 """
103
104 return isinstance(self.ftype, types.VFSTypeDir)
105
106
107
109 """
110 Return True if instance is representing directory and it is empty
111 """
112
113 if not self.is_dir():
114 return False
115
116 _, _, dirs, files = self.walk()
117
118 return len(dirs) == 0 and len(files) == 0
119
120
121
123 """
124 Return True if instance is representing soft link
125 """
126
127 return isinstance(self.ftype, types.VFSTypeLink)
128
129
130
132 """
133 Return True if instance is representing soft char device
134 """
135
136 return isinstance(self.ftype, types.VFSTypeChar)
137
138
139
141 """
142 Return True if instance is representing block device
143 """
144
145 return isinstance(self.ftype, types.VFSTypeBlock)
146
147
148
150 """
151 Return True if instance is representing FIFO
152 """
153
154 return isinstance(self.ftype, types.VFSTypeFifo)
155
156
157
159 """
160 Return True if instance is representing socket
161 """
162
163 return isinstance(self.ftype, types.VFSTypeSocket)
164
165
166
167 - def copy(self, path, existcb=None, errorcb=None,
168 save_attrs=True, follow_links=False, cancel=None):
169 """
170 Copy file to specified location
171
172 @param path: Local path to copy file to
173 @param existcb: Callback function to be called if there exists
174 an object in target directory with the same name.
175 Callback function receives VFSObject instance as an
176 argument and must return one of:
177 'override' - to override this very object
178 'override all' - to override any future collisions
179 'skip' - to skip the object
180 'skip all' - to skip all future collisions
181 'abort' - to abort the process.
182 If no existscb provided 'abort' is used as default
183 @param errorcb: Callback function to be called in case an error occured
184 during copying. Function receives VFSObject instance
185 and error string as arguments and must return one of:
186 'skip' - to continue the process
187 'skip all' - to skip all future errors
188 'abort' - to abort the process.
189 If no errorcb provided 'abort' is used as default
190 @param save_attrs: Whether to save object attributes
191 @param follow_links: Whether to follow symlinks
192 @param cancel: a threading.Event instance, if it is found set - abort
193 """
194
195 raise NotImplementedError(self.__ni_msg)
196
197
198
199 - def move(self, path, existcb=None, errorcb=None, save_attrs=True,
200 follow_links=False, cancel=None):
201 """
202 Move object
203 Arguments are the same as for copy()
204 """
205
206 raise NotImplementedError(self.__ni_msg)
207
208
209
210 - def mkdir(self, newdir):
211 """
212 Create new dir inside object (only valid for directory object types)
213 """
214
215 raise NotImplementedError(self.__ni_msg)
216
217
218
219 - def remove(self, recursive=True):
220 """
221 [Recursively] remove object
222 """
223
224 raise NotImplementedError(self.__ni_msg)
225
226
227
229 """
230 Directory tree generator
231 """
232
233 raise NotImplementedError(self.__ni_msg)
234
235
236
239
240
241
244
245
246
248 raise NotImplementedError(self.__ni_msg)
249