diff -r 0f4017309f35 -r b6f5e27daeb5 src/eric7/Project/Project.py --- a/src/eric7/Project/Project.py Fri Feb 23 16:50:50 2024 +0100 +++ b/src/eric7/Project/Project.py Fri Feb 23 16:52:01 2024 +0100 @@ -2035,7 +2035,6 @@ @param startdir start directory for the selection dialog @type str """ - # TODO: adapt to remote server from .AddFileDialog import AddFileDialog if not startdir: @@ -2045,17 +2044,37 @@ if dlg.exec() == QDialog.DialogCode.Accepted: fnames, target, isSource = dlg.getData() if target != "": + isRemote = FileSystemUtilities.isRemoteFileName(target) for fn in fnames: - targetfile = os.path.join(target, os.path.basename(fn)) - if not FileSystemUtilities.samepath(os.path.dirname(fn), target): + targetfile = ( + self.__remotefsInterface.join( + target, self.__remotefsInterface.basename(fn) + ) + if isRemote + else os.path.join(target, os.path.basename(fn)) + ) + if not FileSystemUtilities.samepath( + self.__remotefsInterface.dirname(fn) + if isRemote + else os.path.dirname(fn), + target + ): try: - if not os.path.isdir(target): - os.makedirs(target) - - if os.path.exists(targetfile): + if isRemote: + if not self.__remotefsInterface.isdir(target): + self.__remotefsInterface.makedirs(target) + else: + if not os.path.isdir(target): + os.makedirs(target) + + if ( + not isRemote and os.path.exists(targetfile) + ) or ( + isRemote and self.__remotefsInterface.exists(targetfile) + ): res = EricMessageBox.yesNo( self.ui, - self.tr("Add file"), + self.tr("Add File"), self.tr( "<p>The file <b>{0}</b> already" " exists.</p><p>Overwrite it?</p>" @@ -2065,11 +2084,14 @@ if not res: return # don't overwrite - shutil.copy(fn, target) + if isRemote: + self.__remotefsInterface.shutilCopy(fn, target) + else: + shutil.copy(fn, target) except OSError as why: EricMessageBox.critical( self.ui, - self.tr("Add file"), + self.tr("Add File"), self.tr( "<p>The selected file <b>{0}</b> could" " not be added to <b>{1}</b>.</p>" @@ -2111,15 +2133,20 @@ ignorePatterns.append(pattern) files = [] + isRemote = FileSystemUtilities.isRemoteFileName(target) for pattern in patterns: - sstring = "{0}{1}{2}".format(source, os.sep, pattern) - files.extend(glob.glob(sstring)) + if isRemote: + sstring = self.__remotefsInterface.join(source, pattern) + files.extend(self.__remotefsInterface.glob(sstring)) + else: + sstring = os.path.join(source, pattern) + files.extend(glob.glob(sstring)) if len(files) == 0: if not quiet: EricMessageBox.information( self.ui, - self.tr("Add directory"), + self.tr("Add Directory"), self.tr( "<p>The source directory doesn't contain" " any files belonging to the selected category.</p>" @@ -2127,15 +2154,20 @@ ) return - if not FileSystemUtilities.samepath(target, source) and not os.path.isdir( - target + if not FileSystemUtilities.samepath(target, source) and not ( + (not isRemote and os.path.isdir(target)) or ( + isRemote and self.__remotefsInterface.isdir(target) + ) ): try: - os.makedirs(target) + if isRemote: + self.__remotefsInterface.makedirs(target) + else: + os.makedirs(target) except OSError as why: EricMessageBox.critical( self.ui, - self.tr("Add directory"), + self.tr("Add Directory"), self.tr( "<p>The target directory <b>{0}</b> could not be" " created.</p><p>Reason: {1}</p>" @@ -2148,13 +2180,23 @@ if fnmatch.fnmatch(file, pattern): continue - targetfile = os.path.join(target, os.path.basename(file)) + targetfile = ( + self.__remotefsInterface.join( + target, self.__remotefsInterface.basename(file) + ) + if isRemote + else os.path.join(target, os.path.basename(file)) + ) if not FileSystemUtilities.samepath(target, source): try: - if os.path.exists(targetfile): + if ( + not isRemote and os.path.exists(targetfile) + ) or ( + isRemote and self.__remotefsInterface.exists(targetfile) + ): res = EricMessageBox.yesNo( self.ui, - self.tr("Add directory"), + self.tr("Add Directory"), self.tr( "<p>The file <b>{0}</b> already exists.</p>" "<p>Overwrite it?</p>" @@ -2165,7 +2207,10 @@ continue # don't overwrite, carry on with next file - shutil.copy(file, target) + if isRemote: + self.__remotefsInterface.shutilCopy(file,target ) + else: + shutil.copy(file, target) except OSError: continue self.appendFile(targetfile) @@ -2202,16 +2247,28 @@ if filetype == "__IGNORE__" ] - # now recurse into subdirectories - with os.scandir(source) as dirEntriesIterator: - for dirEntry in dirEntriesIterator: - if dirEntry.is_dir() and not any( - fnmatch.fnmatch(dirEntry.name, ignore_pattern) + # now recurs into subdirectories + if FileSystemUtilities.isRemoteFileName(target): + for entry in self.__remotefsInterface.listdir(source)[2]: + if entry["is_dir"] and not any( + fnmatch.fnmatch(entry["name"], ignore_pattern) for ignore_pattern in ignore_patterns ): self.__addRecursiveDirectory( - filetype, dirEntry.path, os.path.join(target, dirEntry.name) + filetype, + entry["path"], + self.__remotefsInterface.join(target, entry["name"]), ) + else: + with os.scandir(source) as dirEntriesIterator: + for dirEntry in dirEntriesIterator: + if dirEntry.is_dir() and not any( + fnmatch.fnmatch(dirEntry.name, ignore_pattern) + for ignore_pattern in ignore_patterns + ): + self.__addRecursiveDirectory( + filetype, dirEntry.path, os.path.join(target, dirEntry.name) + ) @pyqtSlot() def addDirectory(self, fileTypeFilter=None, startdir=None):