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
32 self.path = bstring(path, self.enc)
33
34 self.full_path = bstring(full_path, self.enc)
35
36 self.ext_path = bstring(ext_path, self.enc)
37 self.parent = parent
38 self.driver = driver
39 self.kwargs = kwargs
40 self.fileobj = None
41
42
43 self.name = os.path.basename(self.path)
44
45
46 self.ftype = None
47
48
49 self.atime = None
50
51
52 self.mtime = None
53
54
55 self.ctime = None
56
57
58 self.size = None
59
60
61 self.uid = None
62
63
64 self.gid = None
65
66
67 self.mode = None
68
69
70 self.inode = None
71
72
73 self.vtype = None
74
75
76 self.visual = None
77
78
79 self.info = None
80
81
82 self.data = None
83
84
85 self.attributes = ()
86
87
88 self._prepare()
89
90 self.__ni_msg = _(u"Feature not implemented")
91
92
93
95 """
96 Return True if instance is representing regular file
97 """
98
99 return isinstance(self.ftype, types.VFSTypeFile)
100
101
102
104 """
105 Return True if instance is representing directory
106 """
107
108 return isinstance(self.ftype, types.VFSTypeDir)
109
110
111
113 """
114 Return True if instance is representing directory and it is empty
115 """
116
117 if not self.is_dir():
118 return False
119
120 _, _, objs = self.walk()
121
122 return len(objs) == 0
123
124
125
127 """
128 Return True if instance is representing soft link
129 """
130
131 return isinstance(self.ftype, types.VFSTypeLink)
132
133
134
136 """
137 Return True if instance is representing soft char device
138 """
139
140 return isinstance(self.ftype, types.VFSTypeChar)
141
142
143
145 """
146 Return True if instance is representing block device
147 """
148
149 return isinstance(self.ftype, types.VFSTypeBlock)
150
151
152
154 """
155 Return True if instance is representing FIFO
156 """
157
158 return isinstance(self.ftype, types.VFSTypeFifo)
159
160
161
163 """
164 Return True if instance is representing socket
165 """
166
167 return isinstance(self.ftype, types.VFSTypeSocket)
168
169
170
171 - def copy(self, path, existcb=None, errorcb=None,
172 save_attrs=True, follow_links=False, cancel=None):
173 """
174 Copy file to specified location
175
176 @param path: Local path to copy file to
177 @param existcb: Callback function to be called if there exists
178 an object in target directory with the same name.
179 Callback function receives VFSObject instance as an
180 argument and must return one of:
181 'override' - to override this very object
182 'override all' - to override any future collisions
183 'skip' - to skip the object
184 'skip all' - to skip all future collisions
185 'abort' - to abort the process.
186 If no existscb provided 'abort' is used as default
187 @param errorcb: Callback function to be called in case an error occured
188 during copying. Function receives VFSObject instance
189 and error string as arguments and must return one of:
190 'skip' - to continue the process
191 'skip all' - to skip all future errors
192 'abort' - to abort the process.
193 If no errorcb provided 'abort' is used as default
194 @param save_attrs: Whether to save object attributes
195 @param follow_links: Whether to follow symlinks
196 @param cancel: a threading.Event instance, if it is found set - abort
197 """
198
199 raise NotImplementedError(self.__ni_msg)
200
201
202
203 - def move(self, path, existcb=None, errorcb=None, save_attrs=True,
204 follow_links=False, cancel=None):
205 """
206 Move object
207 Arguments are the same as for copy()
208 """
209
210 raise NotImplementedError(self.__ni_msg)
211
212
213
214 - def mkdir(self, newdir):
215 """
216 Create new dir inside object (only valid for directory object types)
217 """
218
219 raise NotImplementedError(self.__ni_msg)
220
221
222
223 - def remove(self, recursive=True):
224 """
225 [Recursively] remove object
226 """
227
228 raise NotImplementedError(self.__ni_msg)
229
230
231
233 """
234 Directory tree walker
235 """
236
237 raise NotImplementedError(self.__ni_msg)
238
239
240
241 - def open(self, mode='r'):
242 """
243 Open self object in provided mode
244 """
245
246 raise NotImplementedError(self.__ni_msg)
247
248
249
251 """
252 Close self object
253 """
254
255 raise NotImplementedError(self.__ni_msg)
256
257
258
259 - def read(self, bytes=None):
260 """
261 Read bytes from self object
262 """
263
264 raise NotImplementedError(self.__ni_msg)
265
266
267
269 """
270 Tell file position
271 """
272
273 raise NotImplementedError(self.__ni_msg)
274
275
276
277 - def seek(self, offset, whence=None):
278 """
279 Perform seek() on object
280 """
281
282 raise NotImplementedError(self.__ni_msg)
283
284
285
288
289
290
293
294
295
297 raise NotImplementedError(self.__ni_msg)
298
299
300
302 if self.fileobj:
303 try:
304 self.close()
305 except Exception:
306 pass
307