예제 #1
0
    def _change_name(self, path, new_name):
        """

        :param CIPath path:
        """
        # print(">>>", "_change_name:", path, new_name)
        dest = path.with_name(new_name)

        if self._fs.exists(dest) and not path == dest:
            dlg = FileExistsDialog(dest, path.is_dir)
            if dlg.exec_():
                new_dest = dlg.new_dest  # could be same as old dest

                for case in [lambda om: om & dlg.overwrite]:
                    if case(OverwriteMode.IGNORE):
                        return
                    if case(OverwriteMode.REPLACE):
                        return self._replace(path, new_dest)

                    if case(OverwriteMode.MERGE):
                        return self._begin_merge(path, new_dest)

                return self._dorename(path, new_dest.name)
        else:
            return self._dorename(path, new_name)
예제 #2
0
    def _change_name(self, path, new_name):
        """

        :param CIPath path:
        """
        # print(">>>", "_change_name:", path, new_name)
        dest=path.with_name(new_name)

        if self._fs.exists(dest) and not path==dest:
            dlg = FileExistsDialog(dest, path.is_dir)
            if dlg.exec_():
                new_dest = dlg.new_dest  # could be same as old dest

                for case in [lambda om: om & dlg.overwrite]:
                    if case(OverwriteMode.IGNORE):
                        return
                    if case(OverwriteMode.REPLACE):
                        return self._replace(path, new_dest)

                    if case(OverwriteMode.MERGE):
                        return self._begin_merge(path, new_dest)

                return self._dorename(path, new_dest.name)
        else:
            return self._dorename(path, new_name)
예제 #3
0
    def _prepare_move(self, src_path, dest_path,
                      merging=False, use_mode=OverwriteMode.PROMPT):
        """
        Catch a potential name conflict here and begin merge macro if necessary.
        :param src_path:
        :param dest_path:
        """
        # print(">>>", "_prepare_move:", src_path, dest_path, merging, use_mode)

        if self._fs.exists(dest_path):
            dest_path = self._fs.get_path(dest_path) # get the CIPath version

            if merging:
                if dest_path.is_dir and src_path.is_dir:
                    # skip matching dirs while merging; their contents are
                    # coming up in the list and will be handled appropriately
                    raise exceptions.MergeSkipDir
                elif dest_path.has_children and not src_path.is_dir:
                    print("dest_path.has_children and not src_path.is_dir")
                    # trying to overwrite non-empty dir with file--no can do
                    dlg = FileExistsDialog(dest_path, False,
                                           in_merge_op=merging)
                    if dlg.exec_():
                        # rename should be only option
                        assert dlg.overwrite == OverwriteMode.PROMPT
                        self._move_item(src_path, dlg.new_dest)
                    else:
                        raise exceptions.CancelMerge
                    return None

                elif use_mode:
                    # dest is file/empty dir, src is whatever,
                    # use mode is something besides PROMPT
                    if use_mode & OverwriteMode.REPLACE:
                        # print("use mode & REPLACE")
                        self._replace(src_path, dest_path)
                    # elif use_mode & OverwriteMode.IGNORE:
                    #     print("use_mode & IGNORE")

                    return None

            # if we're not merging, or we are merging and overwrite==PROMPT
            dlg = FileExistsDialog(dest_path, src_path.is_dir, in_merge_op=merging)
            if dlg.exec_():
                new_dest = dlg.new_dest # could be same as old dest
                self.do_op[dlg.overwrite](self, src_path, new_dest)
                if merging and dlg.apply_to_all:
                    return dlg.overwrite
        else:
            # dest doesn't exist, this is a basic move
            self._move_item(src_path, dest_path)

        # redundant...but explicit.
        return None
예제 #4
0
    def _prepare_move(self,
                      src_path,
                      dest_path,
                      merging=False,
                      use_mode=OverwriteMode.PROMPT):
        """
        Catch a potential name conflict here and begin merge macro if necessary.
        :param src_path:
        :param dest_path:
        """
        # print(">>>", "_prepare_move:", src_path, dest_path, merging, use_mode)

        if self._fs.exists(dest_path):
            dest_path = self._fs.get_path(dest_path)  # get the CIPath version

            if merging:
                if dest_path.is_dir and src_path.is_dir:
                    # skip matching dirs while merging; their contents are
                    # coming up in the list and will be handled appropriately
                    raise exceptions.MergeSkipDir
                elif dest_path.has_children and not src_path.is_dir:
                    print("dest_path.has_children and not src_path.is_dir")
                    # trying to overwrite non-empty dir with file--no can do
                    dlg = FileExistsDialog(dest_path,
                                           False,
                                           in_merge_op=merging)
                    if dlg.exec_():
                        # rename should be only option
                        assert dlg.overwrite == OverwriteMode.PROMPT
                        self._move_item(src_path, dlg.new_dest)
                    else:
                        raise exceptions.CancelMerge
                    return None

                elif use_mode:
                    # dest is file/empty dir, src is whatever,
                    # use mode is something besides PROMPT
                    if use_mode & OverwriteMode.REPLACE:
                        # print("use mode & REPLACE")
                        self._replace(src_path, dest_path)
                    # elif use_mode & OverwriteMode.IGNORE:
                    #     print("use_mode & IGNORE")

                    return None

            # if we're not merging, or we are merging and overwrite==PROMPT
            dlg = FileExistsDialog(dest_path,
                                   src_path.is_dir,
                                   in_merge_op=merging)
            if dlg.exec_():
                new_dest = dlg.new_dest  # could be same as old dest
                self.do_op[dlg.overwrite](self, src_path, new_dest)
                if merging and dlg.apply_to_all:
                    return dlg.overwrite
        else:
            # dest doesn't exist, this is a basic move
            self._move_item(src_path, dest_path)

        # redundant...but explicit.
        return None