eric6/MicroPython/MicroPythonFileSystem.py

branch
micropython
changeset 7084
3eddfc540614
parent 7083
217862c28319
child 7088
e29b0ee86b29
diff -r 217862c28319 -r 3eddfc540614 eric6/MicroPython/MicroPythonFileSystem.py
--- a/eric6/MicroPython/MicroPythonFileSystem.py	Thu Jul 25 19:55:40 2019 +0200
+++ b/eric6/MicroPython/MicroPythonFileSystem.py	Fri Jul 26 20:05:49 2019 +0200
@@ -607,7 +607,6 @@
         on the connected device
     @signal rsyncDone(localName, deviceName) emitted after the rsync operation
         has been completed
-    @signal rsyncMessages(list) emitted with a list of messages
     @signal rsyncProgressMessage(msg) emitted to send a message about what
         rsync is doing
     @signal removeDirectoryDone() emitted after a directory has been deleted
@@ -629,7 +628,6 @@
     putFileDone = pyqtSignal(str, str)
     deleteFileDone = pyqtSignal(str)
     rsyncDone = pyqtSignal(str, str)
-    rsyncMessages = pyqtSignal(list)
     rsyncProgressMessage = pyqtSignal(str)
     removeDirectoryDone = pyqtSignal()
     createDirectoryDone = pyqtSignal()
@@ -776,18 +774,20 @@
         @param mirror flag indicating to mirror the local directory to
             the device directory
         @type bool
-        @return tuple containing a list of messages and list of errors
-        @rtype tuple of (list of str, list of str)
+        @return list of errors
+        @rtype list of str
         """
-        # TODO: get rid of messages and replace by rsyncProgressMessage signal
-        messages = []
         errors = []
         
         if not os.path.isdir(hostDirectory):
-            return ([], [self.tr(
+            return [self.tr(
                 "The given name '{0}' is not a directory or does not exist.")
                 .format(hostDirectory)
-            ])
+            ]
+        
+        self.rsyncProgressMessage.emit(
+            self.tr("Synchronizing <b>{0}</b>.").format(deviceDirectory)
+        )
         
         sourceDict = {}
         sourceFiles = listdirStat(hostDirectory)
@@ -798,13 +798,13 @@
         try:
             destinationFiles = self.__fs.lls(deviceDirectory, fullstat=True)
         except Exception as exc:
-            return ([], [str(exc)])
+            return [str(exc)]
         if destinationFiles is None:
             # the destination directory does not exist
             try:
                 self.__fs.mkdir(deviceDirectory)
             except Exception as exc:
-                return ([], [str(exc)])
+                return [str(exc)]
         else:
             for name, nstat in destinationFiles:
                 destinationDict[name] = nstat
@@ -819,27 +819,32 @@
             # name exists in source but not in device
             sourceFilename = os.path.join(hostDirectory, sourceBasename)
             destFilename = deviceDirectory + "/" + sourceBasename
+            self.rsyncProgressMessage.emit(
+                self.tr("Adding <b>{0}</b>...").format(destFilename))
             if os.path.isfile(sourceFilename):
                 try:
                     self.__fs.put(sourceFilename, destFilename)
                 except Exception as exc:
-                    messages.append(str(exc))
+                    # just note issues but ignore them otherwise
+                    errors.append(str(exc))
             if os.path.isdir(sourceFilename):
                 # recurse
-                msg, err = self.__rsync(sourceFilename, destFilename,
-                                        mirror=mirror)
-                messages.extend(msg)
-                errors.extend(err)
+                errs = self.__rsync(sourceFilename, destFilename,
+                                    mirror=mirror)
+                # just note issues but ignore them otherwise
+                errors.extend(errs)
         
         if mirror:
             for destBasename in toDelete:
                 # name exists in device but not local, delete
                 destFilename = deviceDirectory + "/" + destBasename
+                self.rsyncProgressMessage.emit(
+                    self.tr("Removing <b>{0}</b>...").format(destFilename))
                 try:
                     self.__fs.rmrf(destFilename, recursive=True, force=True)
                 except Exception as exc:
-                    # ignore errors here
-                    messages.append(str(exc))
+                    # just note issues but ignore them otherwise
+                    errors.append(str(exc))
         
         for sourceBasename in toUpdate:
             # names exist in both; do an update
@@ -850,33 +855,41 @@
             destMode = destStat[0]
             if os.path.isdir(sourceFilename):
                 if stat.S_ISDIR(destMode):
-                    # both are directories => recurse
-                    msg, err = self.__rsync(sourceFilename, destFilename,
-                                            mirror=mirror)
-                    messages.extend(msg)
-                    errors.extend(err)
+                    # both are directories => recurs
+                    errs = self.__rsync(sourceFilename, destFilename,
+                                        mirror=mirror)
+                    # just note issues but ignore them otherwise
+                    errors.extend(errs)
                 else:
-                    messages.append(self.tr(
-                        "Source '{0}' is a directory and destination '{1}'"
-                        " is a file. Ignoring it."
-                    ).format(sourceFilename, destFilename))
+                    self.rsyncProgressMessage.emit(
+                        self.tr("Source <b>{0}</b> is a directory and"
+                                " destination <b>{1}</b> is a file. Ignoring"
+                                " it.")
+                        .format(sourceFilename, destFilename)
+                    )
             else:
                 if stat.S_ISDIR(destMode):
-                    messages.append(self.tr(
-                        "Source '{0}' is a file and destination '{1}' is"
-                        " a directory. Ignoring it."
-                    ).format(sourceFilename, destFilename))
+                    self.rsyncProgressMessage.emit(
+                        self.tr("Source <b>{0}</b> is a file and destination"
+                                " <b>{1}</b> is a directory. Ignoring it.")
+                        .format(sourceFilename, destFilename)
+                    )
                 else:
                     if sourceStat[8] > destStat[8]:     # mtime
-                        messages.append(self.tr(
-                            "'{0}' is newer than '{1}' - copying"
-                        ).format(sourceFilename, destFilename))
+                        self.rsyncProgressMessage.emit(
+                            self.tr("Updating <b>{0}</b>...")
+                            .format(destFilename)
+                        )
                         try:
                             self.__fs.put(sourceFilename, destFilename)
                         except Exception as exc:
-                            messages.append(str(exc))
+                            errors.append(str(exc))
         
-        return messages, errors
+        self.rsyncProgressMessage.emit(
+            self.tr("Done synchronizing <b>{0}</b>.").format(deviceDirectory)
+        )
+        
+        return errors
     
     @pyqtSlot(str, str)
     @pyqtSlot(str, str, bool)
@@ -892,14 +905,10 @@
             the device directory
         @type bool
         """
-        messages, errors = self.__rsync(hostDirectory, deviceDirectory,
-                                        mirror=mirror)
+        errors = self.__rsync(hostDirectory, deviceDirectory, mirror=mirror)
         if errors:
             self.error.emit("rsync", "\n".join(errors))
         
-        if messages:
-            self.rsyncMessages.emit(messages)
-        
         self.rsyncDone.emit(hostDirectory, deviceDirectory)
     
     @pyqtSlot(str)

eric ide

mercurial