Example #1
0
    def remove(self, auto_confirm=False, verbose=False):
        """Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True)."""

        if not self.paths:
            logger.info(
                "Can't uninstall '%s'. No files were found to uninstall.",
                self.dist.project_name,
            )
            return

        dist_name_version = (self.dist.project_name + "-" + self.dist.version)
        logger.info('Uninstalling %s:', dist_name_version)

        with indent_log():
            if auto_confirm or self._allowed_to_proceed(verbose):
                self.save_dir.create()

                for path in sorted(compact(self.paths)):
                    new_path = self._stash(path)
                    logger.debug('Removing file or directory %s', path)
                    self._moved_paths.append(path)
                    renames(path, new_path)
                for pth in self.pth.values():
                    pth.remove()

                logger.info('Successfully uninstalled %s', dist_name_version)
    def remove(self, auto_confirm=False, verbose=False):
        """Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True)."""

        if not self.paths:
            logger.info(
                "Can't uninstall '%s'. No files were found to uninstall.",
                self.dist.project_name,
            )
            return

        dist_name_version = (
            self.dist.project_name + "-" + self.dist.version
        )
        logger.info('Uninstalling %s:', dist_name_version)

        with indent_log():
            if auto_confirm or self._allowed_to_proceed(verbose):
                for path in sorted(compact(compress_for_rename(self.paths))):
                    new_path = self._stash(path)
                    logger.debug('Removing file or directory %s', path)
                    self._moved_paths.append((path, new_path))
                    renames(path, new_path)
                for pth in self.pth.values():
                    pth.remove()

                logger.info('Successfully uninstalled %s', dist_name_version)
Example #3
0
    def remove(self, auto_confirm=False, verbose=False):
        """Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True)."""

        if not self.paths:
            logger.info(
                "Can't uninstall '%s'. No files were found to uninstall.",
                self.dist.project_name,
            )
            return

        dist_name_version = (self.dist.project_name + "-" + self.dist.version)
        logger.info('Uninstalling %s:', dist_name_version)

        with indent_log():
            if auto_confirm or self._allowed_to_proceed(verbose):
                for path in sorted(compact(compress_for_rename(self.paths))):
                    new_path = self._stash(path)
                    logger.debug('Removing file or directory %s', path)
                    self._moved_paths.append((path, new_path))
                    if os.path.isdir(path) and os.path.isdir(new_path):
                        # If we're moving a directory, we need to
                        # remove the destination first or else it will be
                        # moved to inside the existing directory.
                        # We just created new_path ourselves, so it will
                        # be removable.
                        os.rmdir(new_path)
                    renames(path, new_path)
                for pth in self.pth.values():
                    pth.remove()

                logger.info('Successfully uninstalled %s', dist_name_version)
Example #4
0
    def remove(self, auto_confirm=False, verbose=False):
        """Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True)."""

        if not self.paths:
            logger.info(
                "Can't uninstall '%s'. No files were found to uninstall.",
                self.dist.project_name,
            )
            return

        dist_name_version = (
            self.dist.project_name + "-" + self.dist.version
        )
        logger.info('Uninstalling %s:', dist_name_version)

        with indent_log():
            if auto_confirm or self._allowed_to_proceed(verbose):
                for path in sorted(compact(compress_for_rename(self.paths))):
                    new_path = self._stash(path)
                    logger.debug('Removing file or directory %s', path)
                    self._moved_paths.append((path, new_path))
                    if os.path.isdir(path) and os.path.isdir(new_path):
                        # If we're moving a directory, we need to
                        # remove the destination first or else it will be
                        # moved to inside the existing directory.
                        # We just created new_path ourselves, so it will
                        # be removable.
                        os.rmdir(new_path)
                    renames(path, new_path)
                for pth in self.pth.values():
                    pth.remove()

                logger.info('Successfully uninstalled %s', dist_name_version)
 def rollback(self):
     """Rollback the changes previously made by remove()."""
     if self.save_dir.path is None:
         logger.error("Can't roll back %s; was not uninstalled",
                      self.dist.project_name)
         return False
     logger.info("Rolling back uninstall of %s", self.dist.project_name)
     for path in self._moved_paths:
         tmp_path = self._stash(path)
         logger.debug("Replacing %s", path)
         renames(tmp_path, path)
     for pth in self.pth.values():
         pth.rollback()
 def rollback(self):
     """Rollback the changes previously made by remove()."""
     if not self._save_dirs:
         logger.error(
             "Can't roll back %s; was not uninstalled",
             self.dist.project_name,
         )
         return False
     logger.info('Rolling back uninstall of %s', self.dist.project_name)
     for path, tmp_path in self._moved_paths:
         logger.debug('Replacing %s', path)
         renames(tmp_path, path)
     for pth in self.pth.values():
         pth.rollback()
Example #7
0
 def rollback(self):
     """Rollback the changes previously made by remove()."""
     if not self._save_dirs:
         logger.error(
             "Can't roll back %s; was not uninstalled",
             self.dist.project_name,
         )
         return False
     logger.info('Rolling back uninstall of %s', self.dist.project_name)
     for path, tmp_path in self._moved_paths:
         logger.debug('Replacing %s', path)
         renames(tmp_path, path)
     for pth in self.pth.values():
         pth.rollback()
Example #8
0
    def rollback(self):
        """Undoes the uninstall by moving stashed files back."""
        for p in self._moves:
            logging.info("Moving to %s\n from %s", *p)

        for new_path, path in self._moves:
            try:
                logger.debug('Replacing %s from %s', new_path, path)
                if os.path.isfile(new_path):
                    os.unlink(new_path)
                elif os.path.isdir(new_path):
                    rmtree(new_path)
                renames(path, new_path)
            except OSError as ex:
                logger.error("Failed to restore %s", new_path)
                logger.debug("Exception: %s", ex)

        self.commit()
Example #9
0
    def stash(self, path):
        """Stashes the directory or file and returns its new location.
        """
        if os.path.isdir(path):
            new_path = self._get_directory_stash(path)
        else:
            new_path = self._get_file_stash(path)

        self._moves.append((path, new_path))
        if os.path.isdir(path) and os.path.isdir(new_path):
            # If we're moving a directory, we need to
            # remove the destination first or else it will be
            # moved to inside the existing directory.
            # We just created new_path ourselves, so it will
            # be removable.
            os.rmdir(new_path)
        renames(path, new_path)
        return new_path
    def rollback(self):
        # type: () -> None
        """Undoes the uninstall by moving stashed files back."""
        for p in self._moves:
            logging.info("Moving to %s\n from %s", *p)

        for new_path, path in self._moves:
            try:
                logger.debug('Replacing %s from %s', new_path, path)
                if os.path.isfile(new_path):
                    os.unlink(new_path)
                elif os.path.isdir(new_path):
                    rmtree(new_path)
                renames(path, new_path)
            except OSError as ex:
                logger.error("Failed to restore %s", new_path)
                logger.debug("Exception: %s", ex)

        self.commit()
    def stash(self, path):
        # type: (str) -> str
        """Stashes the directory or file and returns its new location.
        """
        if os.path.isdir(path):
            new_path = self._get_directory_stash(path)
        else:
            new_path = self._get_file_stash(path)

        self._moves.append((path, new_path))
        if os.path.isdir(path) and os.path.isdir(new_path):
            # If we're moving a directory, we need to
            # remove the destination first or else it will be
            # moved to inside the existing directory.
            # We just created new_path ourselves, so it will
            # be removable.
            os.rmdir(new_path)
        renames(path, new_path)
        return new_path
Example #12
0
    def stash(self, path: str) -> str:
        """Stashes the directory or file and returns its new location.
        Handle symlinks as files to avoid modifying the symlink targets.
        """
        path_is_dir = os.path.isdir(path) and not os.path.islink(path)
        if path_is_dir:
            new_path = self._get_directory_stash(path)
        else:
            new_path = self._get_file_stash(path)

        self._moves.append((path, new_path))
        if (path_is_dir and os.path.isdir(new_path)):
            # If we're moving a directory, we need to
            # remove the destination first or else it will be
            # moved to inside the existing directory.
            # We just created new_path ourselves, so it will
            # be removable.
            os.rmdir(new_path)
        renames(path, new_path)
        return new_path