351 with contextlib.suppress(OSError): |
354 with contextlib.suppress(OSError): |
352 entries = self.direntries( |
355 entries = self.direntries( |
353 dirname, pattern=basename, recursive=recursive, filesonly=True |
356 dirname, pattern=basename, recursive=recursive, filesonly=True |
354 ) |
357 ) |
355 result = ( |
358 result = ( |
356 entries |
359 [FileSystemUtilities.remoteFileName(e) for e in entries] |
357 if includeHidden |
360 if includeHidden |
358 else [e for e in entries if not e.startswith(".")] |
361 else [ |
|
362 FileSystemUtilities.remoteFileName(e) |
|
363 for e in entries |
|
364 if not e.startswith(".") |
|
365 ] |
359 ) |
366 ) |
360 |
367 |
361 return result |
368 return result |
362 |
369 |
363 def stat(self, filename, stNames): |
370 def stat(self, filename, stNames): |
767 loop.exec() |
774 loop.exec() |
768 return ok, error |
775 return ok, error |
769 |
776 |
770 else: |
777 else: |
771 return False, "Not connected to an 'eric-ide' server." |
778 return False, "Not connected to an 'eric-ide' server." |
|
779 |
|
780 def expanduser(self, name): |
|
781 """ |
|
782 Public method to expand an initial '~' or '~user' component. |
|
783 |
|
784 @param name path name to be expanded |
|
785 @type str |
|
786 @return expanded path name |
|
787 @rtype str |
|
788 """ |
|
789 loop = QEventLoop() |
|
790 ok = False |
|
791 expandedName = name |
|
792 |
|
793 def callback(reply, params): |
|
794 """ |
|
795 Function to handle the server reply |
|
796 |
|
797 @param reply name of the server reply |
|
798 @type str |
|
799 @param params dictionary containing the reply data |
|
800 @type dict |
|
801 """ |
|
802 nonlocal ok, expandedName |
|
803 |
|
804 if reply == "ExpandUser": |
|
805 ok = params["ok"] |
|
806 expandedName = params["name"] |
|
807 loop.quit() |
|
808 |
|
809 if self.__serverInterface.isServerConnected(): |
|
810 self.__serverInterface.sendJson( |
|
811 category=EricRequestCategory.FileSystem, |
|
812 request="ExpandUser", |
|
813 params={"name": FileSystemUtilities.plainFileName(name)}, |
|
814 callback=callback, |
|
815 ) |
|
816 |
|
817 loop.exec() |
|
818 if FileSystemUtilities.isRemoteFileName(name): |
|
819 return FileSystemUtilities.remoteFileName(expandedName) |
|
820 else: |
|
821 return expandedName |
772 |
822 |
773 ####################################################################### |
823 ####################################################################### |
774 ## Methods for splitting or joining remote path names. |
824 ## Methods for splitting or joining remote path names. |
775 ## |
825 ## |
776 ## These are simplified variants of the os.path functions. If the |
826 ## These are simplified variants of the os.path functions. If the |
1098 text, origEncoding, forcedEncoding=forcedEncoding |
1148 text, origEncoding, forcedEncoding=forcedEncoding |
1099 ) |
1149 ) |
1100 self.writeFile(filename, data, withBackup=withBackup) |
1150 self.writeFile(filename, data, withBackup=withBackup) |
1101 |
1151 |
1102 return encoding |
1152 return encoding |
|
1153 |
|
1154 ####################################################################### |
|
1155 ## Methods implementing some 'shutil' like functionality. |
|
1156 ####################################################################### |
|
1157 |
|
1158 def shutilCopy(self, srcName, dstName): |
|
1159 loop = QEventLoop() |
|
1160 ok = False |
|
1161 error = "" |
|
1162 dst = "" |
|
1163 |
|
1164 def callback(reply, params): |
|
1165 """ |
|
1166 Function to handle the server reply |
|
1167 |
|
1168 @param reply name of the server reply |
|
1169 @type str |
|
1170 @param params dictionary containing the reply data |
|
1171 @type dict |
|
1172 """ |
|
1173 nonlocal ok, error, dst |
|
1174 |
|
1175 if reply == "ShutilCopy": |
|
1176 ok = params["ok"] |
|
1177 if ok: |
|
1178 dst = params["dst"] |
|
1179 else: |
|
1180 error = params["error"] |
|
1181 loop.quit() |
|
1182 |
|
1183 if not self.__serverInterface.isServerConnected(): |
|
1184 raise OSError("Not connected to an 'eric-ide' server.") |
|
1185 |
|
1186 else: |
|
1187 self.__serverInterface.sendJson( |
|
1188 category=EricRequestCategory.FileSystem, |
|
1189 request="ShutilCopy", |
|
1190 params={ |
|
1191 "src_name": FileSystemUtilities.plainFileName(srcName), |
|
1192 "dst_name": FileSystemUtilities.plainFileName(dstName), |
|
1193 }, |
|
1194 callback=callback, |
|
1195 ) |
|
1196 |
|
1197 loop.exec() |
|
1198 if not ok: |
|
1199 raise OSError(error) |
|
1200 |
|
1201 return dst |