src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py

branch
server
changeset 10576
0cf5ebf17411
parent 10574
622e59b51640
child 10577
b9edebd77c91
--- a/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py	Fri Feb 16 09:32:27 2024 +0100
+++ b/src/eric7/RemoteServerInterface/EricServerFileSystemInterface.py	Fri Feb 16 11:45:08 2024 +0100
@@ -9,6 +9,7 @@
 
 import base64
 import contextlib
+import stat
 
 from PyQt6.QtCore import QEventLoop, QObject
 
@@ -166,6 +167,72 @@
 
         return listedDirectory, separator, listing
 
+    def direntries(
+        self, directory, filesonly=False, pattern=None, followsymlinks=True, ignore=None
+    ):
+        """
+        Public method to get a list of all files and directories of a given directory.
+
+        @param directory root of the tree to check
+        @type str
+        @param filesonly flag indicating that only files are wanted (defaults to False)
+        @type bool (optional)
+        @param pattern a filename pattern or list of filename patterns to check
+            against (defaults to None)
+        @type str or list of str (optional)
+        @param followsymlinks flag indicating whether symbolic links should be
+            followed (defaults to True)
+        @type bool (optional)
+        @param ignore list of entries to be ignored (defaults to None)
+        @type list of str (optional)
+        @return list of all files and directories in the tree rooted at path.
+            The names are expanded to start with the given directory name.
+        @rtype list of str
+        @exception OSError raised in case the server reported an issue
+        """
+        loop = QEventLoop()
+        ok = False
+        error = ""
+        result = []
+
+        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 result, ok, error
+
+            if reply == "DirEntries":
+                ok = params["ok"]
+                if ok:
+                    result = params["result"]
+                else:
+                    error = params["error"]
+                loop.quit()
+
+        self.__serverInterface.sendJson(
+            category=EricRequestCategory.FileSystem,
+            request="DirEntries",
+            params={
+                "directory": FileSystemUtilities.plainFileName(directory),
+                "files_only": filesonly,
+                "pattern": [] if pattern is None else pattern,
+                "follow_symlinks": followsymlinks,
+                "ignore": [] if ignore is None else ignore,
+            },
+            callback=callback,
+        )
+
+        loop.exec()
+        if not ok:
+            raise OSError(error)
+
+        return result
+
     def stat(self, filename, stNames):
         """
         Public method to get the status of a file.
@@ -218,6 +285,30 @@
 
         return stResult
 
+    def isdir(self, name):
+        """
+        Public method to check, if the given name is a directory.
+
+        @param name name to be checked
+        @type str
+        @return flag indicating a directory
+        @rtype bool
+        """
+        result = self.stat(name, ["st_mode"])
+        return stat.S_ISDIR(result["st_mode"])
+
+    def isfile(self, name):
+        """
+        Public method to check, if the given name is a regular file.
+
+        @param name name to be checked
+        @type str
+        @return flag indicating a regular file
+        @rtype bool
+        """
+        result = self.stat(name, ["st_mode"])
+        return stat.S_ISREG(result["st_mode"])
+
     def exists(self, name):
         """
         Public method the existence of a file or directory.

eric ide

mercurial