src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py

branch
server
changeset 10605
b6f5e27daeb5
parent 10596
ea35c92a3c7c
child 10610
bb0149571d94
diff -r 0f4017309f35 -r b6f5e27daeb5 src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py
--- a/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py	Fri Feb 23 16:50:50 2024 +0100
+++ b/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py	Fri Feb 23 16:52:01 2024 +0100
@@ -246,6 +246,9 @@
             if not ok:
                 raise OSError(error)
 
+            for entry in listing:
+                entry["path"] = FileSystemUtilities.remoteFileName(entry["path"])
+
         return listedDirectory, separator, listing
 
     def direntries(
@@ -353,9 +356,13 @@
                     dirname, pattern=basename, recursive=recursive, filesonly=True
                 )
                 result = (
-                    entries
+                    [FileSystemUtilities.remoteFileName(e) for e in entries]
                     if includeHidden
-                    else [e for e in entries if not e.startswith(".")]
+                    else [
+                        FileSystemUtilities.remoteFileName(e)
+                        for e in entries
+                        if not e.startswith(".")
+                    ]
                 )
 
         return result
@@ -770,6 +777,49 @@
         else:
             return False, "Not connected to an 'eric-ide' server."
 
+    def expanduser(self, name):
+        """
+        Public method to expand an initial '~' or '~user' component.
+
+        @param name path name to be expanded
+        @type str
+        @return expanded path name
+        @rtype str
+        """
+        loop = QEventLoop()
+        ok = False
+        expandedName = name
+
+        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, expandedName
+
+            if reply == "ExpandUser":
+                ok = params["ok"]
+                expandedName = params["name"]
+                loop.quit()
+
+        if self.__serverInterface.isServerConnected():
+            self.__serverInterface.sendJson(
+                category=EricRequestCategory.FileSystem,
+                request="ExpandUser",
+                params={"name": FileSystemUtilities.plainFileName(name)},
+                callback=callback,
+            )
+
+            loop.exec()
+        if FileSystemUtilities.isRemoteFileName(name):
+            return FileSystemUtilities.remoteFileName(expandedName)
+        else:
+            return expandedName
+
     #######################################################################
     ## Methods for splitting or joining remote path names.
     ##
@@ -1100,3 +1150,52 @@
         self.writeFile(filename, data, withBackup=withBackup)
 
         return encoding
+
+    #######################################################################
+    ## Methods implementing some 'shutil' like functionality.
+    #######################################################################
+
+    def shutilCopy(self, srcName, dstName):
+        loop = QEventLoop()
+        ok = False
+        error = ""
+        dst = ""
+
+        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, dst
+
+            if reply == "ShutilCopy":
+                ok = params["ok"]
+                if ok:
+                    dst = params["dst"]
+                else:
+                    error = params["error"]
+                loop.quit()
+
+        if not self.__serverInterface.isServerConnected():
+            raise OSError("Not connected to an 'eric-ide' server.")
+
+        else:
+            self.__serverInterface.sendJson(
+                category=EricRequestCategory.FileSystem,
+                request="ShutilCopy",
+                params={
+                    "src_name": FileSystemUtilities.plainFileName(srcName),
+                    "dst_name": FileSystemUtilities.plainFileName(dstName),
+                },
+                callback=callback,
+            )
+
+            loop.exec()
+            if not ok:
+                raise OSError(error)
+
+            return dst

eric ide

mercurial