164 if not ok: |
165 if not ok: |
165 raise OSError(error) |
166 raise OSError(error) |
166 |
167 |
167 return listedDirectory, separator, listing |
168 return listedDirectory, separator, listing |
168 |
169 |
|
170 def direntries( |
|
171 self, directory, filesonly=False, pattern=None, followsymlinks=True, ignore=None |
|
172 ): |
|
173 """ |
|
174 Public method to get a list of all files and directories of a given directory. |
|
175 |
|
176 @param directory root of the tree to check |
|
177 @type str |
|
178 @param filesonly flag indicating that only files are wanted (defaults to False) |
|
179 @type bool (optional) |
|
180 @param pattern a filename pattern or list of filename patterns to check |
|
181 against (defaults to None) |
|
182 @type str or list of str (optional) |
|
183 @param followsymlinks flag indicating whether symbolic links should be |
|
184 followed (defaults to True) |
|
185 @type bool (optional) |
|
186 @param ignore list of entries to be ignored (defaults to None) |
|
187 @type list of str (optional) |
|
188 @return list of all files and directories in the tree rooted at path. |
|
189 The names are expanded to start with the given directory name. |
|
190 @rtype list of str |
|
191 @exception OSError raised in case the server reported an issue |
|
192 """ |
|
193 loop = QEventLoop() |
|
194 ok = False |
|
195 error = "" |
|
196 result = [] |
|
197 |
|
198 def callback(reply, params): |
|
199 """ |
|
200 Function to handle the server reply |
|
201 |
|
202 @param reply name of the server reply |
|
203 @type str |
|
204 @param params dictionary containing the reply data |
|
205 @type dict |
|
206 """ |
|
207 nonlocal result, ok, error |
|
208 |
|
209 if reply == "DirEntries": |
|
210 ok = params["ok"] |
|
211 if ok: |
|
212 result = params["result"] |
|
213 else: |
|
214 error = params["error"] |
|
215 loop.quit() |
|
216 |
|
217 self.__serverInterface.sendJson( |
|
218 category=EricRequestCategory.FileSystem, |
|
219 request="DirEntries", |
|
220 params={ |
|
221 "directory": FileSystemUtilities.plainFileName(directory), |
|
222 "files_only": filesonly, |
|
223 "pattern": [] if pattern is None else pattern, |
|
224 "follow_symlinks": followsymlinks, |
|
225 "ignore": [] if ignore is None else ignore, |
|
226 }, |
|
227 callback=callback, |
|
228 ) |
|
229 |
|
230 loop.exec() |
|
231 if not ok: |
|
232 raise OSError(error) |
|
233 |
|
234 return result |
|
235 |
169 def stat(self, filename, stNames): |
236 def stat(self, filename, stNames): |
170 """ |
237 """ |
171 Public method to get the status of a file. |
238 Public method to get the status of a file. |
172 |
239 |
173 @param filename name of the file |
240 @param filename name of the file |
215 loop.exec() |
282 loop.exec() |
216 if not ok: |
283 if not ok: |
217 raise OSError(error) |
284 raise OSError(error) |
218 |
285 |
219 return stResult |
286 return stResult |
|
287 |
|
288 def isdir(self, name): |
|
289 """ |
|
290 Public method to check, if the given name is a directory. |
|
291 |
|
292 @param name name to be checked |
|
293 @type str |
|
294 @return flag indicating a directory |
|
295 @rtype bool |
|
296 """ |
|
297 result = self.stat(name, ["st_mode"]) |
|
298 return stat.S_ISDIR(result["st_mode"]) |
|
299 |
|
300 def isfile(self, name): |
|
301 """ |
|
302 Public method to check, if the given name is a regular file. |
|
303 |
|
304 @param name name to be checked |
|
305 @type str |
|
306 @return flag indicating a regular file |
|
307 @rtype bool |
|
308 """ |
|
309 result = self.stat(name, ["st_mode"]) |
|
310 return stat.S_ISREG(result["st_mode"]) |
220 |
311 |
221 def exists(self, name): |
312 def exists(self, name): |
222 """ |
313 """ |
223 Public method the existence of a file or directory. |
314 Public method the existence of a file or directory. |
224 |
315 |