327 @exception IOError raised to indicate an issue with the device |
327 @exception IOError raised to indicate an issue with the device |
328 """ |
328 """ |
329 assert name |
329 assert name |
330 |
330 |
331 commands = [ |
331 commands = [ |
332 "import os" |
332 "import os", |
333 "\n".join([ |
333 "\n".join([ |
334 "def remove_file(name, recursive=False, force=False):", |
334 "def remove_file(name, recursive=False, force=False):", |
335 " try:", |
335 " try:", |
336 " mode = os.stat(name)[0]", |
336 " mode = os.stat(name)[0]", |
337 " if mode & 0x4000 != 0:", |
337 " if mode & 0x4000 != 0:", |
411 if not os.path.isfile(hostFileName): |
411 if not os.path.isfile(hostFileName): |
412 raise IOError("No such file: {0}".format(hostFileName)) |
412 raise IOError("No such file: {0}".format(hostFileName)) |
413 |
413 |
414 with open(hostFileName, "rb") as hostFile: |
414 with open(hostFileName, "rb") as hostFile: |
415 content = hostFile.read() |
415 content = hostFile.read() |
|
416 # convert eol '\r' |
|
417 content = content.replace(b"\r\n", b"\r") |
|
418 content = content.replace(b"\n", b"\r") |
416 |
419 |
417 if not deviceFileName: |
420 if not deviceFileName: |
418 deviceFileName = os.path.basename(hostFileName) |
421 deviceFileName = os.path.basename(hostFileName) |
419 |
422 |
420 commands = [ |
423 commands = [ |
476 out, err = self.__execute(commands) |
479 out, err = self.__execute(commands) |
477 if err: |
480 if err: |
478 raise IOError(self.__shortError(err)) |
481 raise IOError(self.__shortError(err)) |
479 |
482 |
480 # write the received bytes to the local file |
483 # write the received bytes to the local file |
|
484 # convert eol to "\n" |
|
485 out = out.replace(b"\r\n", b"\n") |
|
486 out = out.replace(b"\r", b"\n") |
481 with open(hostFileName, "wb") as hostFile: |
487 with open(hostFileName, "wb") as hostFile: |
482 hostFile.write(out) |
488 hostFile.write(out) |
483 return True |
489 return True |
484 |
490 |
485 def version(self): |
491 def version(self): |
600 @signal deleteFileDone(deviceFile) emitted after the file has been deleted |
606 @signal deleteFileDone(deviceFile) emitted after the file has been deleted |
601 on the connected device |
607 on the connected device |
602 @signal rsyncDone(localName, deviceName) emitted after the rsync operation |
608 @signal rsyncDone(localName, deviceName) emitted after the rsync operation |
603 has been completed |
609 has been completed |
604 @signal rsyncMessages(list) emitted with a list of messages |
610 @signal rsyncMessages(list) emitted with a list of messages |
|
611 @signal rsyncProgressMessage(msg) emitted to send a message about what |
|
612 rsync is doing |
605 @signal removeDirectoryDone() emitted after a directory has been deleted |
613 @signal removeDirectoryDone() emitted after a directory has been deleted |
606 @signal createDirectoryDone() emitted after a directory was created |
614 @signal createDirectoryDone() emitted after a directory was created |
607 @signal synchTimeDone() emitted after the time was synchronizde to the |
615 @signal synchTimeDone() emitted after the time was synchronizde to the |
608 device |
616 device |
609 @signal showTimeDone(dateTime) emitted after the date and time was fetched |
617 @signal showTimeDone(dateTime) emitted after the date and time was fetched |
620 getFileDone = pyqtSignal(str, str) |
628 getFileDone = pyqtSignal(str, str) |
621 putFileDone = pyqtSignal(str, str) |
629 putFileDone = pyqtSignal(str, str) |
622 deleteFileDone = pyqtSignal(str) |
630 deleteFileDone = pyqtSignal(str) |
623 rsyncDone = pyqtSignal(str, str) |
631 rsyncDone = pyqtSignal(str, str) |
624 rsyncMessages = pyqtSignal(list) |
632 rsyncMessages = pyqtSignal(list) |
|
633 rsyncProgressMessage = pyqtSignal(str) |
625 removeDirectoryDone = pyqtSignal() |
634 removeDirectoryDone = pyqtSignal() |
626 createDirectoryDone = pyqtSignal() |
635 createDirectoryDone = pyqtSignal() |
627 synchTimeDone = pyqtSignal() |
636 synchTimeDone = pyqtSignal() |
628 showTimeDone = pyqtSignal(str) |
637 showTimeDone = pyqtSignal(str) |
629 showVersionDone = pyqtSignal(dict) |
638 showVersionDone = pyqtSignal(dict) |
768 the device directory |
777 the device directory |
769 @type bool |
778 @type bool |
770 @return tuple containing a list of messages and list of errors |
779 @return tuple containing a list of messages and list of errors |
771 @rtype tuple of (list of str, list of str) |
780 @rtype tuple of (list of str, list of str) |
772 """ |
781 """ |
|
782 # TODO: get rid of messages and replace by rsyncProgressMessage signal |
773 messages = [] |
783 messages = [] |
774 errors = [] |
784 errors = [] |
775 |
785 |
776 if not os.isdir(hostDirectory): |
786 if not os.path.isdir(hostDirectory): |
777 return ([], [self.tr( |
787 return ([], [self.tr( |
778 "The given name '{0}' is not a directory or does not exist.") |
788 "The given name '{0}' is not a directory or does not exist.") |
779 .format(hostDirectory) |
789 .format(hostDirectory) |
780 ]) |
790 ]) |
781 |
791 |