57 |
57 |
58 if reply == "Getcwd": |
58 if reply == "Getcwd": |
59 cwd = params["directory"] |
59 cwd = params["directory"] |
60 loop.quit() |
60 loop.quit() |
61 |
61 |
62 self.__serverInterface.sendJson( |
62 if self.__serverInterface.isServerConnected(): |
63 category=EricRequestCategory.FileSystem, |
63 self.__serverInterface.sendJson( |
64 request="Getcwd", |
64 category=EricRequestCategory.FileSystem, |
65 params={}, |
65 request="Getcwd", |
66 callback=callback, |
66 params={}, |
67 ) |
67 callback=callback, |
68 |
68 ) |
69 loop.exec() |
69 |
|
70 loop.exec() |
|
71 |
70 return cwd |
72 return cwd |
71 |
73 |
72 def chdir(self, directory): |
74 def chdir(self, directory): |
73 """ |
75 """ |
74 Public method to change the current working directory of the eric-ide server. |
76 Public method to change the current working directory of the eric-ide server. |
97 ok = params["ok"] |
99 ok = params["ok"] |
98 with contextlib.suppress(KeyError): |
100 with contextlib.suppress(KeyError): |
99 error = params["error"] |
101 error = params["error"] |
100 loop.quit() |
102 loop.quit() |
101 |
103 |
102 self.__serverInterface.sendJson( |
104 if self.__serverInterface.isServerConnected(): |
103 category=EricRequestCategory.FileSystem, |
105 self.__serverInterface.sendJson( |
104 request="Chdir", |
106 category=EricRequestCategory.FileSystem, |
105 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
107 request="Chdir", |
106 callback=callback, |
108 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
107 ) |
109 callback=callback, |
108 |
110 ) |
109 loop.exec() |
111 |
110 return ok, error |
112 loop.exec() |
|
113 return ok, error |
|
114 |
|
115 else: |
|
116 return False, "Not connected to an 'eric-ide' server." |
111 |
117 |
112 def listdir(self, directory=""): |
118 def listdir(self, directory=""): |
113 """ |
119 """ |
114 Public method to get a directory listing. |
120 Public method to get a directory listing. |
115 |
121 |
152 separator = params["separator"] |
158 separator = params["separator"] |
153 else: |
159 else: |
154 error = params["error"] |
160 error = params["error"] |
155 loop.quit() |
161 loop.quit() |
156 |
162 |
157 self.__serverInterface.sendJson( |
163 if self.__serverInterface.isServerConnected(): |
158 category=EricRequestCategory.FileSystem, |
164 self.__serverInterface.sendJson( |
159 request="Listdir", |
165 category=EricRequestCategory.FileSystem, |
160 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
166 request="Listdir", |
161 callback=callback, |
167 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
162 ) |
168 callback=callback, |
163 |
169 ) |
164 loop.exec() |
170 |
165 if not ok: |
171 loop.exec() |
166 raise OSError(error) |
172 if not ok: |
|
173 raise OSError(error) |
167 |
174 |
168 return listedDirectory, separator, listing |
175 return listedDirectory, separator, listing |
169 |
176 |
170 def direntries( |
177 def direntries( |
171 self, directory, filesonly=False, pattern=None, followsymlinks=True, ignore=None |
178 self, directory, filesonly=False, pattern=None, followsymlinks=True, ignore=None |
212 result = params["result"] |
219 result = params["result"] |
213 else: |
220 else: |
214 error = params["error"] |
221 error = params["error"] |
215 loop.quit() |
222 loop.quit() |
216 |
223 |
217 self.__serverInterface.sendJson( |
224 if self.__serverInterface.isServerConnected(): |
218 category=EricRequestCategory.FileSystem, |
225 self.__serverInterface.sendJson( |
219 request="DirEntries", |
226 category=EricRequestCategory.FileSystem, |
220 params={ |
227 request="DirEntries", |
221 "directory": FileSystemUtilities.plainFileName(directory), |
228 params={ |
222 "files_only": filesonly, |
229 "directory": FileSystemUtilities.plainFileName(directory), |
223 "pattern": [] if pattern is None else pattern, |
230 "files_only": filesonly, |
224 "follow_symlinks": followsymlinks, |
231 "pattern": [] if pattern is None else pattern, |
225 "ignore": [] if ignore is None else ignore, |
232 "follow_symlinks": followsymlinks, |
226 }, |
233 "ignore": [] if ignore is None else ignore, |
227 callback=callback, |
234 }, |
228 ) |
235 callback=callback, |
229 |
236 ) |
230 loop.exec() |
237 |
231 if not ok: |
238 loop.exec() |
232 raise OSError(error) |
239 if not ok: |
|
240 raise OSError(error) |
233 |
241 |
234 return result |
242 return result |
235 |
243 |
236 def stat(self, filename, stNames): |
244 def stat(self, filename, stNames): |
237 """ |
245 """ |
267 stResult = params["result"] |
275 stResult = params["result"] |
268 else: |
276 else: |
269 error = params["error"] |
277 error = params["error"] |
270 loop.quit() |
278 loop.quit() |
271 |
279 |
272 self.__serverInterface.sendJson( |
280 if self.__serverInterface.isServerConnected(): |
273 category=EricRequestCategory.FileSystem, |
281 self.__serverInterface.sendJson( |
274 request="Stat", |
282 category=EricRequestCategory.FileSystem, |
275 params={ |
283 request="Stat", |
276 "filename": FileSystemUtilities.plainFileName(filename), |
284 params={ |
277 "st_names": stNames, |
285 "filename": FileSystemUtilities.plainFileName(filename), |
278 }, |
286 "st_names": stNames, |
279 callback=callback, |
287 }, |
280 ) |
288 callback=callback, |
281 |
289 ) |
282 loop.exec() |
290 |
283 if not ok: |
291 loop.exec() |
284 raise OSError(error) |
292 if not ok: |
|
293 raise OSError(error) |
285 |
294 |
286 return stResult |
295 return stResult |
287 |
296 |
288 def isdir(self, name): |
297 def isdir(self, name): |
289 """ |
298 """ |
292 @param name name to be checked |
301 @param name name to be checked |
293 @type str |
302 @type str |
294 @return flag indicating a directory |
303 @return flag indicating a directory |
295 @rtype bool |
304 @rtype bool |
296 """ |
305 """ |
297 result = self.stat(name, ["st_mode"]) |
306 with contextlib.suppress(KeyError, OSError): |
298 return stat.S_ISDIR(result["st_mode"]) |
307 result = self.stat(name, ["st_mode"]) |
|
308 return stat.S_ISDIR(result["st_mode"]) |
|
309 |
|
310 return False |
299 |
311 |
300 def isfile(self, name): |
312 def isfile(self, name): |
301 """ |
313 """ |
302 Public method to check, if the given name is a regular file. |
314 Public method to check, if the given name is a regular file. |
303 |
315 |
304 @param name name to be checked |
316 @param name name to be checked |
305 @type str |
317 @type str |
306 @return flag indicating a regular file |
318 @return flag indicating a regular file |
307 @rtype bool |
319 @rtype bool |
308 """ |
320 """ |
309 result = self.stat(name, ["st_mode"]) |
321 with contextlib.suppress(KeyError, OSError): |
310 return stat.S_ISREG(result["st_mode"]) |
322 result = self.stat(name, ["st_mode"]) |
|
323 return stat.S_ISREG(result["st_mode"]) |
|
324 |
|
325 return False |
311 |
326 |
312 def exists(self, name): |
327 def exists(self, name): |
313 """ |
328 """ |
314 Public method the existence of a file or directory. |
329 Public method the existence of a file or directory. |
315 |
330 |
334 |
349 |
335 if reply == "Exists": |
350 if reply == "Exists": |
336 nameExists = params["exists"] |
351 nameExists = params["exists"] |
337 loop.quit() |
352 loop.quit() |
338 |
353 |
339 self.__serverInterface.sendJson( |
354 if self.__serverInterface.isServerConnected(): |
340 category=EricRequestCategory.FileSystem, |
355 self.__serverInterface.sendJson( |
341 request="Exists", |
356 category=EricRequestCategory.FileSystem, |
342 params={"name": FileSystemUtilities.plainFileName(name)}, |
357 request="Exists", |
343 callback=callback, |
358 params={"name": FileSystemUtilities.plainFileName(name)}, |
344 ) |
359 callback=callback, |
345 |
360 ) |
346 loop.exec() |
361 |
|
362 loop.exec() |
|
363 |
347 return nameExists |
364 return nameExists |
348 |
365 |
349 def access(self, name, modes): |
366 def access(self, name, modes): |
350 """ |
367 """ |
351 Public method to test the given access rights to a file or directory. |
368 Public method to test the given access rights to a file or directory. |
385 |
402 |
386 if reply == "Access": |
403 if reply == "Access": |
387 accessOK = params["ok"] |
404 accessOK = params["ok"] |
388 loop.quit() |
405 loop.quit() |
389 |
406 |
390 self.__serverInterface.sendJson( |
407 if self.__serverInterface.isServerConnected(): |
391 category=EricRequestCategory.FileSystem, |
408 self.__serverInterface.sendJson( |
392 request="Access", |
409 category=EricRequestCategory.FileSystem, |
393 params={"name": FileSystemUtilities.plainFileName(name), "modes": modes}, |
410 request="Access", |
394 callback=callback, |
411 params={ |
395 ) |
412 "name": FileSystemUtilities.plainFileName(name), |
396 |
413 "modes": modes, |
397 loop.exec() |
414 }, |
|
415 callback=callback, |
|
416 ) |
|
417 |
|
418 loop.exec() |
|
419 |
398 return accessOK |
420 return accessOK |
399 |
421 |
400 def mkdir(self, directory): |
422 def mkdir(self, directory): |
401 """ |
423 """ |
402 Public method to create a new directory on the eric-ide server. |
424 Public method to create a new directory on the eric-ide server. |
425 ok = params["ok"] |
447 ok = params["ok"] |
426 with contextlib.suppress(KeyError): |
448 with contextlib.suppress(KeyError): |
427 error = params["error"] |
449 error = params["error"] |
428 loop.quit() |
450 loop.quit() |
429 |
451 |
430 self.__serverInterface.sendJson( |
452 if self.__serverInterface.isServerConnected(): |
431 category=EricRequestCategory.FileSystem, |
453 self.__serverInterface.sendJson( |
432 request="Mkdir", |
454 category=EricRequestCategory.FileSystem, |
433 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
455 request="Mkdir", |
434 callback=callback, |
456 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
435 ) |
457 callback=callback, |
436 |
458 ) |
437 loop.exec() |
459 |
438 return ok, error |
460 loop.exec() |
|
461 return ok, error |
|
462 |
|
463 else: |
|
464 return False, "Not connected to an 'eric-ide' server." |
439 |
465 |
440 def rmdir(self, directory): |
466 def rmdir(self, directory): |
441 """ |
467 """ |
442 Public method to delete a directory on the eric-ide server. |
468 Public method to delete a directory on the eric-ide server. |
443 |
469 |
465 ok = params["ok"] |
491 ok = params["ok"] |
466 with contextlib.suppress(KeyError): |
492 with contextlib.suppress(KeyError): |
467 error = params["error"] |
493 error = params["error"] |
468 loop.quit() |
494 loop.quit() |
469 |
495 |
470 self.__serverInterface.sendJson( |
496 if self.__serverInterface.isServerConnected(): |
471 category=EricRequestCategory.FileSystem, |
497 self.__serverInterface.sendJson( |
472 request="Rmdir", |
498 category=EricRequestCategory.FileSystem, |
473 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
499 request="Rmdir", |
474 callback=callback, |
500 params={"directory": FileSystemUtilities.plainFileName(directory)}, |
475 ) |
501 callback=callback, |
476 |
502 ) |
477 loop.exec() |
503 |
478 return ok, error |
504 loop.exec() |
|
505 return ok, error |
|
506 |
|
507 else: |
|
508 return False, "Not connected to an 'eric-ide' server." |
479 |
509 |
480 def replace(self, oldName, newName): |
510 def replace(self, oldName, newName): |
481 """ |
511 """ |
482 Public method to rename a file or directory. |
512 Public method to rename a file or directory. |
483 |
513 |
507 ok = params["ok"] |
537 ok = params["ok"] |
508 with contextlib.suppress(KeyError): |
538 with contextlib.suppress(KeyError): |
509 error = params["error"] |
539 error = params["error"] |
510 loop.quit() |
540 loop.quit() |
511 |
541 |
512 self.__serverInterface.sendJson( |
542 if self.__serverInterface.isServerConnected(): |
513 category=EricRequestCategory.FileSystem, |
543 self.__serverInterface.sendJson( |
514 request="Replace", |
544 category=EricRequestCategory.FileSystem, |
515 params={ |
545 request="Replace", |
516 "old_name": FileSystemUtilities.plainFileName(oldName), |
546 params={ |
517 "new_name": FileSystemUtilities.plainFileName(newName), |
547 "old_name": FileSystemUtilities.plainFileName(oldName), |
518 }, |
548 "new_name": FileSystemUtilities.plainFileName(newName), |
519 callback=callback, |
549 }, |
520 ) |
550 callback=callback, |
521 |
551 ) |
522 loop.exec() |
552 |
523 return ok, error |
553 loop.exec() |
|
554 return ok, error |
|
555 |
|
556 else: |
|
557 return False, "Not connected to an 'eric-ide' server." |
524 |
558 |
525 def remove(self, filename): |
559 def remove(self, filename): |
526 """ |
560 """ |
527 Public method to delete a file on the eric-ide server. |
561 Public method to delete a file on the eric-ide server. |
528 |
562 |
550 ok = params["ok"] |
584 ok = params["ok"] |
551 with contextlib.suppress(KeyError): |
585 with contextlib.suppress(KeyError): |
552 error = params["error"] |
586 error = params["error"] |
553 loop.quit() |
587 loop.quit() |
554 |
588 |
555 self.__serverInterface.sendJson( |
589 if self.__serverInterface.isServerConnected(): |
556 category=EricRequestCategory.FileSystem, |
590 self.__serverInterface.sendJson( |
557 request="Remove", |
591 category=EricRequestCategory.FileSystem, |
558 params={"filename": FileSystemUtilities.plainFileName(filename)}, |
592 request="Remove", |
559 callback=callback, |
593 params={"filename": FileSystemUtilities.plainFileName(filename)}, |
560 ) |
594 callback=callback, |
561 |
595 ) |
562 loop.exec() |
596 |
563 return ok, error |
597 loop.exec() |
|
598 return ok, error |
|
599 |
|
600 else: |
|
601 return False, "Not connected to an 'eric-ide' server." |
564 |
602 |
565 ####################################################################### |
603 ####################################################################### |
566 ## Methods for reading and writing files |
604 ## Methods for reading and writing files |
567 ####################################################################### |
605 ####################################################################### |
568 |
606 |
603 ) |
641 ) |
604 else: |
642 else: |
605 error = params["error"] |
643 error = params["error"] |
606 loop.quit() |
644 loop.quit() |
607 |
645 |
608 self.__serverInterface.sendJson( |
646 if not self.__serverInterface.isServerConnected(): |
609 category=EricRequestCategory.FileSystem, |
647 raise OSError("Not connected to an 'eric-ide' server.") |
610 request="ReadFile", |
648 |
611 params={ |
649 else: |
612 "filename": FileSystemUtilities.plainFileName(filename), |
650 self.__serverInterface.sendJson( |
613 "create": create, |
651 category=EricRequestCategory.FileSystem, |
614 }, |
652 request="ReadFile", |
615 callback=callback, |
653 params={ |
616 ) |
654 "filename": FileSystemUtilities.plainFileName(filename), |
617 |
655 "create": create, |
618 loop.exec() |
656 }, |
619 if not ok: |
657 callback=callback, |
620 raise OSError(error) |
658 ) |
621 |
659 |
622 return bText |
660 loop.exec() |
|
661 if not ok: |
|
662 raise OSError(error) |
|
663 |
|
664 return bText |
623 |
665 |
624 def writeFile(self, filename, data, withBackup=False): |
666 def writeFile(self, filename, data, withBackup=False): |
625 """ |
667 """ |
626 Public method to write the data to a file on the eric-ide server. |
668 Public method to write the data to a file on the eric-ide server. |
627 |
669 |
653 ok = params["ok"] |
695 ok = params["ok"] |
654 with contextlib.suppress(KeyError): |
696 with contextlib.suppress(KeyError): |
655 error = params["error"] |
697 error = params["error"] |
656 loop.quit() |
698 loop.quit() |
657 |
699 |
658 self.__serverInterface.sendJson( |
700 if not self.__serverInterface.isServerConnected(): |
659 category=EricRequestCategory.FileSystem, |
701 raise OSError("Not connected to an 'eric-ide' server.") |
660 request="WriteFile", |
702 |
661 params={ |
703 else: |
662 "filename": FileSystemUtilities.plainFileName(filename), |
704 self.__serverInterface.sendJson( |
663 "filedata": str(base64.b85encode(data), encoding="ascii"), |
705 category=EricRequestCategory.FileSystem, |
664 "with_backup": withBackup, |
706 request="WriteFile", |
665 }, |
707 params={ |
666 callback=callback, |
708 "filename": FileSystemUtilities.plainFileName(filename), |
667 ) |
709 "filedata": str(base64.b85encode(data), encoding="ascii"), |
668 |
710 "with_backup": withBackup, |
669 loop.exec() |
711 }, |
670 if not ok: |
712 callback=callback, |
671 raise OSError(error) |
713 ) |
|
714 |
|
715 loop.exec() |
|
716 if not ok: |
|
717 raise OSError(error) |