src/eric7/MicroPython/MicroPythonFileManager.py

branch
eric7
changeset 11190
f5ffdf0164ab
parent 11186
c2d18aefef6b
diff -r 289c7150ec4b -r f5ffdf0164ab src/eric7/MicroPython/MicroPythonFileManager.py
--- a/src/eric7/MicroPython/MicroPythonFileManager.py	Mon Mar 24 14:16:32 2025 +0100
+++ b/src/eric7/MicroPython/MicroPythonFileManager.py	Wed Mar 26 19:46:41 2025 +0100
@@ -38,8 +38,12 @@
         copied to the connected device
     @signal deleteFileDone(deviceFile) emitted after the file has been deleted
         on the connected device
+    @signal touchFileDone(deviceFile) emitted after the file has been touched
+        on the connected device
     @signal putDataDone(deviceFile) emitted after data has been save to a file
         on the connected device
+    @signal hashDone(deviceFile, hash) emitted after the hash has been calculated
+        for the file on the connected device
     @signal rsyncDone(localName, deviceName) emitted after the rsync operation
         has been completed
     @signal rsyncProgressMessage(msg) emitted to send a message about what
@@ -59,7 +63,9 @@
     getFileDone = pyqtSignal(str, str)
     putFileDone = pyqtSignal(str, str)
     deleteFileDone = pyqtSignal(str)
+    touchFileDone = pyqtSignal(str)
     putDataDone = pyqtSignal(str)
+    hashDone = pyqtSignal(str, str)
     rsyncDone = pyqtSignal(str, str)
     rsyncProgressMessage = pyqtSignal(str)
     removeDirectoryDone = pyqtSignal()
@@ -283,6 +289,39 @@
         except Exception as exc:
             self.error.emit("delete", str(exc))
 
+    def touchFile(self, deviceFileName):
+        """
+        Public method to touch a file on the connected device.
+
+        @param deviceFileName name of the file on the connected device
+        @type str
+        """
+        try:
+            self.__device.touch(deviceFileName=deviceFileName)
+            self.touchFileDone.emit(deviceFileName)
+        except Exception as exc:
+            self.error.emit("delete", str(exc))
+
+    def hashFile(self, deviceFileName, algorithm="sha256", chunkSize=256):
+        """
+        Public method to generate a hash of a file on the connected device.
+
+        @param deviceFileName name of the file on the connected device
+        @type str
+        @param algorithm hashing algorithm to be used (defaults to "sha256")
+        @type str (optional)
+        @param chunkSize size of data chunks to be sent to the algorithm
+            (defaults to 256)
+        @type int (optional)
+        """
+        try:
+            digest = self.__device.hash(
+                deviceFileName=deviceFileName, algorithm=algorithm, chunkSize=chunkSize
+            )
+            self.hashDone.emit(deviceFileName, digest.hex())
+        except Exception as exc:
+            self.error.emit("hash", str(exc))
+
     def __rsync(
         self,
         hostDirectory,

eric ide

mercurial