17 |
17 |
18 from eric7 import Utilities |
18 from eric7 import Utilities |
19 from eric7.RemoteServer.EricRequestCategory import EricRequestCategory |
19 from eric7.RemoteServer.EricRequestCategory import EricRequestCategory |
20 from eric7.SystemUtilities import FileSystemUtilities |
20 from eric7.SystemUtilities import FileSystemUtilities |
21 |
21 |
22 |
|
23 _RemoteFsCache = {} |
22 _RemoteFsCache = {} |
24 # dictionary containing cached remote file system data keyed by remote path |
23 # dictionary containing cached remote file system data keyed by remote path |
25 |
24 |
26 |
25 |
27 class EricServerNotConnectedError(OSError): |
26 class EricServerNotConnectedError(OSError): |
81 Private slot handling a change of the server connection state. |
80 Private slot handling a change of the server connection state. |
82 |
81 |
83 @param connected flag indicating a connected state |
82 @param connected flag indicating a connected state |
84 @type bool |
83 @type bool |
85 """ |
84 """ |
86 if connected: |
85 if connected and not bool(self.__serverPathSep): |
87 if not bool(self.__serverPathSep): |
86 self.__serverPathSep = self.__getPathSep() |
88 self.__serverPathSep = self.__getPathSep() |
|
89 |
87 |
90 def __getPathSep(self): |
88 def __getPathSep(self): |
91 """ |
89 """ |
92 Private method to get the path separator of the connected server. |
90 Private method to get the path separator of the connected server. |
93 |
91 |
940 @type str |
938 @type str |
941 @return tuple containing head and tail, where tail is everything after the last |
939 @return tuple containing head and tail, where tail is everything after the last |
942 path separator. |
940 path separator. |
943 @rtype tuple of (str, str) |
941 @rtype tuple of (str, str) |
944 """ |
942 """ |
945 if self.__serverPathSep == "\\": |
943 normp = ( |
946 # remote is a Windows system |
944 p.replace("/", "\\") # remote is a Windows system |
947 normp = p.replace("/", "\\") |
945 if self.__serverPathSep == "\\" |
948 else: |
946 else p.replace("\\", "/") # remote is a Posix system |
949 # remote is a Posix system |
947 ) |
950 normp = p.replace("\\", "/") |
|
951 |
948 |
952 i = normp.rfind(self.__serverPathSep) + 1 |
949 i = normp.rfind(self.__serverPathSep) + 1 |
953 head, tail = normp[:i], normp[i:] |
950 head, tail = normp[:i], normp[i:] |
954 if head and head != self.__serverPathSep * len(head): |
951 if head and head != self.__serverPathSep * len(head): |
955 head = head.rstrip(self.__serverPathSep) |
952 head = head.rstrip(self.__serverPathSep) |
1408 raise ValueError("The directory to be cached must not be empty.") |
1405 raise ValueError("The directory to be cached must not be empty.") |
1409 |
1406 |
1410 try: |
1407 try: |
1411 listing = self.listdir(directory=directory, recursive=True)[2] |
1408 listing = self.listdir(directory=directory, recursive=True)[2] |
1412 for entry in listing: |
1409 for entry in listing: |
1413 _RemoteFsCache[ |
1410 _RemoteFsCache[FileSystemUtilities.remoteFileName(entry["path"])] = ( |
1414 FileSystemUtilities.remoteFileName(entry["path"]) |
1411 entry |
1415 ] = entry |
1412 ) |
1416 print(f"Remote Cache Size: {len(_RemoteFsCache)} entries") |
1413 print(f"Remote Cache Size: {len(_RemoteFsCache)} entries") |
1417 except OSError as err: |
1414 except OSError as err: |
1418 print("error in 'populateFsCache()':", str(err)) |
1415 print("Error in 'populateFsCache()':", str(err)) # noqa: M801 |
1419 |
1416 |
1420 def removeFromFsCache(self, directory): |
1417 def removeFromFsCache(self, directory): |
1421 """ |
1418 """ |
1422 Public method to remove a given directory from the remote file system cache. |
1419 Public method to remove a given directory from the remote file system cache. |
1423 |
1420 |