src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py

branch
server
changeset 10596
ea35c92a3c7c
parent 10589
75b656c80a40
child 10605
b6f5e27daeb5
diff -r 6156d9675f62 -r ea35c92a3c7c src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py
--- a/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py	Mon Feb 19 19:37:00 2024 +0100
+++ b/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py	Thu Feb 22 16:26:46 2024 +0100
@@ -74,6 +74,9 @@
     def __getPathSep(self):
         """
         Private method to get the path separator of the connected server.
+
+        @return path separator character of the server
+        @rtype str
         """
         loop = QEventLoop()
         sep = ""
@@ -349,10 +352,11 @@
                 entries = self.direntries(
                     dirname, pattern=basename, recursive=recursive, filesonly=True
                 )
-                if includeHidden:
-                    result = entries
-                else:
-                    result = [e for e in entries if not e.startswith(".")]
+                result = (
+                    entries
+                    if includeHidden
+                    else [e for e in entries if not e.startswith(".")]
+                )
 
         return result
 
@@ -578,6 +582,57 @@
         else:
             return False, "Not connected to an 'eric-ide' server."
 
+    def makedirs(self, directory, exist_ok=False):
+        """
+        Public method to create a new directory on the eric-ide serverincluding all
+        intermediate-level directories.
+
+        @param directory absolute path of the new directory
+        @type str
+        @param exist_ok flag indicating that the existence of the directory is
+            acceptable (defaults to False)
+        @type bool (optional)
+        @return tuple containing an OK flag and an error string in case of an issue
+        @rtype tuple of (bool, str)
+        """
+        loop = QEventLoop()
+        ok = False
+        error = ""
+
+        def callback(reply, params):
+            """
+            Function to handle the server reply
+
+            @param reply name of the server reply
+            @type str
+            @param params dictionary containing the reply data
+            @type dict
+            """
+            nonlocal ok, error
+
+            if reply == "MakeDirs":
+                ok = params["ok"]
+                with contextlib.suppress(KeyError):
+                    error = params["error"]
+                loop.quit()
+
+        if self.__serverInterface.isServerConnected():
+            self.__serverInterface.sendJson(
+                category=EricRequestCategory.FileSystem,
+                request="MakeDirs",
+                params={
+                    "directory": FileSystemUtilities.plainFileName(directory),
+                    "exist_ok": exist_ok,
+                },
+                callback=callback,
+            )
+
+            loop.exec()
+            return ok, error
+
+        else:
+            return False, "Not connected to an 'eric-ide' server."
+
     def rmdir(self, directory):
         """
         Public method to delete a directory on the eric-ide server.
@@ -844,6 +899,32 @@
         """
         return self.split(p)[1]
 
+    def toNativeSeparators(self, p):
+        """
+        Public method to convert a path to use server native separator characters.
+
+        @param p path name to be converted
+        @type str
+        @return path name with converted separator characters
+        @rtype str
+        """
+        if self.__serverPathSep == "/":
+            return p.replace("\\", "/")
+        else:
+            return p.replace("/", "\\")
+
+    def fromNativeSeparators(self, p):
+        """
+        Public method to convert a path using server native separator characters to
+        use "/" separator characters.
+
+        @param p path name to be converted
+        @type str
+        @return path name with converted separator characters
+        @rtype str
+        """
+        return p.replace(self.__serverPathSep, "/")
+
     #######################################################################
     ## Methods for reading and writing files
     #######################################################################
@@ -962,7 +1043,7 @@
 
     def readEncodedFile(self, filename, create=False):
         """
-        Function to read a file and decode its contents into proper text.
+        Public method to read a file and decode its contents into proper text.
 
         @param filename name of the file to read
         @type str
@@ -977,7 +1058,7 @@
 
     def readEncodedFileWithEncoding(self, filename, encoding, create=False):
         """
-        Function to read a file and decode its contents into proper text.
+        Public method to read a file and decode its contents into proper text.
 
         @param filename name of the file to read
         @type str
@@ -992,9 +1073,11 @@
         data = self.readFile(filename, create=create)
         return Utilities.decodeWithEncoding(data, encoding)
 
-    def writeEncodedFile(self, filename, text, origEncoding, forcedEncoding="", withBackup=False):
+    def writeEncodedFile(
+        self, filename, text, origEncoding, forcedEncoding="", withBackup=False
+    ):
         """
-        Function to write a file with properly encoded text.
+        Public method to write a file with properly encoded text.
 
         @param filename name of the file to read
         @type str

eric ide

mercurial