Esempio n. 1
0
    def rename_location(self,
                        location: Location,
                        parent: Optional[QWidget] = None) -> None:
        if location.has_payload():
            self._show_rename_error_has_payload(location, parent)
        else:
            srcpath = location.get_stdio_name()
            srcbasename = os.path.basename(srcpath)
            srcdir = os.path.dirname(srcpath)

            dialog = RenameDialog(parent)
            dialog.set_basename(srcbasename)
            dialog.exec()

            if dialog.result() == QDialog.Accepted:
                oldpath = srcpath
                newpath = os.path.join(srcdir, dialog.get_new_basename())

                if oldpath == newpath:
                    logger.debug(
                        "FilesystemOperations.rename_location: source and destination are the same, "
                        "skipping: \"%s\" to \"%s\"", oldpath, newpath)
                elif os.path.exists(newpath):
                    self._show_rename_error_file_exists(location, parent)
                else:
                    try:
                        self._rename(oldpath, newpath)
                    except OSError as err:
                        self._show_rename_error_os_error(
                            location, err, traceback.format_exc(), parent)
Esempio n. 2
0
    def rename_location(self, location: Location, parent: Optional[QWidget] = None) -> None:
        if location.has_payload():
            self._show_rename_error_has_payload(location, parent)
        else:
            srcpath = location.get_stdio_name()
            srcbasename = os.path.basename(srcpath)
            srcdir = os.path.dirname(srcpath)

            dialog = RenameDialog(parent)
            dialog.set_basename(srcbasename)
            dialog.exec()

            if dialog.result() == QDialog.Accepted:
                oldpath = srcpath
                newpath = os.path.join(srcdir, dialog.get_new_basename())

                if oldpath == newpath:
                    logger.debug("FilesystemOperations.rename_location: source and destination are the same, "
                                 "skipping: \"%s\" to \"%s\"", oldpath, newpath)
                elif os.path.exists(newpath):
                    self._show_rename_error_file_exists(location, parent)
                else:
                    try:
                        self._rename(oldpath, newpath)
                    except OSError as err:
                        self._show_rename_error_os_error(location, err, traceback.format_exc(), parent)
Esempio n. 3
0
 def get_stdio_name(self, location: Location) -> str:
     if not location.has_payload():
         return location.get_path()
     else:
         if location._payloads[-1].path:
             parent = location.parent()
             outdir = self._archive_manager.get_extractor_content_dir(parent)
             return os.path.join(outdir, location._payloads[-1].path)
         else:
             outdir = self._archive_manager.get_extractor_content_dir(location)
             return outdir
Esempio n. 4
0
    def opendir(self, location: Location) -> Union['DirectoryWatcher', 'ArchiveDirectoryWatcher']:
        """Create a watcher object for the given directory. The caller is
        responsible for .close()`ing it."""

        if not location.has_payload():
            directory_watcher = DirectoryWatcher(self, location)
            return directory_watcher
        else:
            directory_watcher = DirectoryWatcher(self, location)
            extractor = self._archive_manager.extract(location, directory_watcher, self)
            if extractor is None:
                return directory_watcher
            else:
                return ArchiveDirectoryWatcher(directory_watcher, extractor)
Esempio n. 5
0
    def get_fileinfo(self, location: Location) -> FileInfo:
        if not location.has_payload():
            fi = FileInfo.from_path(location.get_path())
            fi._location = location
            return fi
        else:
            parent = location.parent()
            assert parent.has_payload()

            outdir = self._archive_manager.get_extractor_content_dir(parent)
            path = os.path.join(outdir, location._payloads[-1].path)

            fi = FileInfo.from_path(path)
            fi._location = location
            return fi