예제 #1
0
    def _collect_actions_existing_dest(self, source, dest):
        """
        _collect_actions() helper to collect required actions to perform a stow
        command when the destination already exists
        """
        if utils.is_same_file(dest, source):
            if dest.is_symlink() or self.is_unfolding:
                self._are_same_file(source, dest)
            else:
                self.errors.add(
                    error.SourceIsSameAsDest(self.subcmd, dest.parent))

        elif dest.is_dir() and source.is_dir:
            self._are_directories(source, dest)
        else:
            self.errors.add(
                error.ConflictsWithExistingFile(self.subcmd, source, dest))
예제 #2
0
파일: ignore.py 프로젝트: thieryl/dploy
    def should_ignore(self, source):
        """
        check if a source should be ignored, based on the ignore patterns in
        self.patterns

        This checks if the ignore patterns match either the file exactly or
        its parents
        """
        for pattern in self.patterns:
            try:
                files = sorted(source.parent.glob(pattern))
            except IndexError:  # the glob result was empty
                continue

            for file in files:
                if utils.is_same_file(file, source) or source in file.parents:
                    return True
        return False
예제 #3
0
파일: ignore.py 프로젝트: arecarn/dploy
    def should_ignore(self, source):
        """
        check if a source should be ignored, based on the ignore patterns in
        self.patterns

        This checks if the ignore patterns match either the file exactly or
        its parents
        """
        for pattern in self.patterns:
            try:
                files = sorted(source.parent.glob(pattern))
            except IndexError:  # the glob result was empty
                continue

            for file in files:
                if utils.is_same_file(file, source) or source in file.parents:
                    return True
        return False
예제 #4
0
    def _collect_folding_actions(self):
        """
        find candidates for folding i.e. when a directory contains symlinks to
        files that all share the same parent directory
        """
        for parent in self.actions.get_unlink_target_parents():
            items = utils.get_directory_contents(parent)
            other_links_parents = []
            other_links = []
            source_parent = None
            is_normal_files_detected = False

            for item in items:
                if item not in self.actions.get_unlink_targets():
                    does_item_exist = False
                    try:
                        does_item_exist = item.exists()
                    except PermissionError:
                        self.errors.add(
                            error.PermissionDenied(self.subcmd, item))
                        return

                    if does_item_exist and item.is_symlink():
                        source_parent = item.resolve().parent
                        other_links_parents.append(item.resolve().parent)
                        other_links.append(item)
                    else:
                        is_normal_files_detected = True
                        break

            if not is_normal_files_detected:
                other_links_parent_count = len(Counter(other_links_parents))

                if other_links_parent_count == 1:
                    assert source_parent is not None
                    if utils.is_same_files(
                            utils.get_directory_contents(source_parent),
                            other_links):
                        self._fold(source_parent, parent)

                elif (other_links_parent_count == 0
                      and not utils.is_same_file(parent, self.dest_input)):
                    self.actions.add(
                        actions.RemoveDirectory(self.subcmd, parent))
예제 #5
0
파일: linkcmd.py 프로젝트: arecarn/dploy
    def _collect_actions(self, source, dest):
        """
        Concrete method to collect required actions to perform a link
        sub-command
        """

        if dest.exists():
            if utils.is_same_file(dest, source):
                self.actions.add(
                    actions.AlreadyLinked(self.subcmd, source, dest))
            else:
                self.errors.add(
                    error.ConflictsWithExistingFile(self.subcmd, source, dest))
        elif dest.is_symlink():
            self.errors.add(
                error.ConflictsWithExistingLink(self.subcmd, source, dest))

        elif not dest.parent.exists():
            self.errors.add(
                error.NoSuchDirectoryToSubcmdInto(self.subcmd, dest.parent))

        else:
            self.actions.add(actions.SymbolicLink(self.subcmd, source, dest))
예제 #6
0
파일: linkcmd.py 프로젝트: thieryl/dploy
    def _collect_actions(self, source, dest):
        """
        Concrete method to collect required actions to perform a link
        sub-command
        """

        if dest.exists():
            if utils.is_same_file(dest, source):
                self.actions.add(
                    actions.AlreadyLinked(self.subcmd, source, dest))
            else:
                self.errors.add(
                    error.ConflictsWithExistingFile(self.subcmd, source, dest))
        elif dest.is_symlink():
            self.errors.add(
                error.ConflictsWithExistingLink(self.subcmd, source, dest))

        elif not dest.parent.exists():
            self.errors.add(
                error.NoSuchDirectoryToSubcmdInto(self.subcmd, dest.parent))

        else:
            self.actions.add(actions.SymbolicLink(self.subcmd, source, dest))