Exemplo n.º 1
0
    def remove(self, auto_confirm=False):
        """Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True)."""
        if not self._can_uninstall():
            return
        if not self.paths:
            logger.info("Can't uninstall '%s'. No files were found to uninstall.", self.dist.project_name)
            return
        logger.info("Uninstalling %s-%s:", self.dist.project_name, self.dist.version)

        with indent_log():
            paths = sorted(self.compact(self.paths))

            if auto_confirm:
                response = "y"
            else:
                for path in paths:
                    logger.info(path)
                response = ask("Proceed (y/n)? ", ("y", "n"))
            if self._refuse:
                logger.info("Not removing or modifying (outside of prefix):")
                for path in self.compact(self._refuse):
                    logger.info(path)
            if response == "y":
                self.save_dir = tempfile.mkdtemp(suffix="-uninstall", prefix="pip-")
                for path in 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-%s", self.dist.project_name, self.dist.version)
Exemplo n.º 2
0
    def _allowed_to_proceed(self, verbose):
        """Display which files would be deleted and prompt for confirmation
        """

        def _display(msg, paths):
            if not paths:
                return

            logger.info(msg)
            with indent_log():
                for path in sorted(compact(paths)):
                    logger.info(path)

        if not verbose:
            will_remove, will_skip = compress_for_output_listing(self.paths)
        else:
            # In verbose mode, display all the files that are going to be
            # deleted.
            will_remove = list(self.paths)
            will_skip = set()

        _display('Would remove:', will_remove)
        _display('Would not remove (might be manually added):', will_skip)
        _display('Would not remove (outside of prefix):', self._refuse)

        return ask('Proceed (y/n)? ', ('y', 'n')) == 'y'
Exemplo n.º 3
0
    def _allowed_to_proceed(self, verbose):
        """Display which files would be deleted and prompt for confirmation
        """

        def _display(msg, paths):
            if not paths:
                return

            logger.info(msg)
            with indent_log():
                for path in sorted(self.compact(paths)):
                    logger.info(path)

        # In verbose mode, display all the files that are going to be deleted.
        will_remove = list(self.paths)
        will_skip = set()

        if not verbose:
            # In non-verbose mode...
            # Display only the folders that have packages inside them and files
            # that are not within those folders. Any files in above folders
            # that would not be deleted would be displayed in a separate
            # skipped list.

            folders = set()
            files = set()
            for path in will_remove:
                if path.endswith(".pyc"):
                    continue
                if path.endswith("__init__.py") or ".dist-info" in path:
                    folders.add(os.path.dirname(path))
                files.add(path)

            folders = self.compact(folders)

            # This walks the tree using os.walk to not miss extra folders
            # that might get added.
            for folder in folders:
                for dirpath, _, dirfiles in os.walk(folder):
                    for fname in dirfiles:
                        if fname.endswith(".pyc"):
                            continue

                        file_ = os.path.join(dirpath, fname)
                        if os.path.isfile(file_) and file_ not in files:
                            # We are skipping this file. Add it to the set.
                            will_skip.add(file_)

            will_remove = files | {
                os.path.join(folder, "*") for folder in folders
            }

        _display('Would remove:', will_remove)
        _display('Would not remove (might be manually added):', will_skip)
        _display('Would not remove (outside of prefix):', self._refuse)

        return ask('Proceed (y/n)? ', ('y', 'n')) == 'y'
Exemplo n.º 4
0
    def _allowed_to_proceed(self, verbose):
        """Display which files would be deleted and prompt for confirmation
        """
        def _display(msg, paths):
            if not paths:
                return

            logger.info(msg)
            with indent_log():
                for path in sorted(self.compact(paths)):
                    logger.info(path)

        # In verbose mode, display all the files that are going to be deleted.
        will_remove = list(self.paths)
        will_skip = set()

        if not verbose:
            # In non-verbose mode...
            # Display only the folders that have packages inside them and files
            # that are not within those folders. Any files in above folders
            # that would not be deleted would be displayed in a separate
            # skipped list.

            folders = set()
            files = set()
            for path in will_remove:
                if path.endswith(".pyc"):
                    continue
                if path.endswith("__init__.py") or ".dist-info" in path:
                    folders.add(os.path.dirname(path))
                files.add(path)

            folders = self.compact(folders)

            # This walks the tree using os.walk to not miss extra folders
            # that might get added.
            for folder in folders:
                for dirpath, _, dirfiles in os.walk(folder):
                    for fname in dirfiles:
                        if fname.endswith(".pyc"):
                            continue

                        file_ = os.path.join(dirpath, fname)
                        if os.path.isfile(file_) and file_ not in files:
                            # We are skipping this file. Add it to the set.
                            will_skip.add(file_)

            will_remove = files | {
                os.path.join(folder, "*")
                for folder in folders
            }

        _display('Would remove:', will_remove)
        _display('Would not remove (might be manually added):', will_skip)
        _display('Would not remove (outside of prefix):', self._refuse)

        return ask('Proceed (y/n)? ', ('y', 'n')) == 'y'
Exemplo n.º 5
0
def install(version, target):

    if not target:
        abort('Task argument "target" is required.')

    current_dir = os.path.dirname(__file__)
    project_path = current_dir
    pkg_version = setuptools_get_version(project_path)
    pkg_name = setuptools_get_name(project_path)

    if not version:
        version = pkg_version

    print 'Installing package {0}, version {1} to target {2}.'.format(*map(yellow, [pkg_name, version, target]))
    if env.confirm:
        response = ask('Proceed (y/n)? ', ('y', 'n'))
    else:
        response = 'y'

    if response == 'y':

        # From filesystem
        #source_package = '~/install/PatZilla/PatZilla-{version}.tar.gz'.format(version=version)

        # From PyPI
        source_package = 'patzilla=={version}'.format(version=version)
        source_config = './patzilla/config/production.ini.tpl'

        target_path = os.path.join(INSTALLATION_PATH, 'sites', target)
        dir_ensure(target_path, recursive=True)

        venv_path = target_path + '/.venv27'

        #if not file_is_file(source_package):
        #    abort('Source package does not exist: ' + source_package)

        if not file_is_dir(target_path):
            abort('Target path does not exist: ' + target_path)

        if not file_is_dir(venv_path):
            run('virtualenv --no-site-packages "{0}"'.format(venv_path))
            #setup_package('which', venv_path)
            # TODO: put these packages to a more convenient location

        setup_package(source_package, venv_path)

        upload_config(source_config, target_path)

        restart_service(target)

    else:
        print yellow('Skipped package install due to user request.')
Exemplo n.º 6
0
    def remove(self, auto_confirm=False):
        """Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True)."""
        if not self._can_uninstall():
            return
        if not self.paths:
            logger.info(
                "Can't uninstall '%s'. No files were found to uninstall.",
                self.dist.project_name,
            )
            return
        logger.info(
            'Uninstalling %s-%s:',
            self.dist.project_name, self.dist.version
        )

        with indent_log():
            paths = sorted(self.compact(self.paths))

            if auto_confirm:
                response = 'y'
            else:
                for path in paths:
                    logger.info(path)
                response = ask('Proceed (y/n)? ', ('y', 'n'))
            if self._refuse:
                logger.info('Not removing or modifying (outside of prefix):')
                for path in self.compact(self._refuse):
                    logger.info(path)
            if response == 'y':
                self.save_dir = tempfile.mkdtemp(suffix='-uninstall',
                                                 prefix='pip-')
                for path in 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-%s',
                    self.dist.project_name, self.dist.version
                )