SILENT KILLERPanel

Current Path: > > usr > lib > python2.7 > site-packages > pip > utils


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //usr/lib/python2.7/site-packages/pip/utils

NameTypeSizeLast ModifiedActions
__init__.py File 27187 bytes April 21 2022 18:08:21.
__init__.pyc File 27725 bytes April 21 2022 18:08:35.
__init__.pyo File 27666 bytes April 21 2022 18:08:36.
appdirs.py File 8811 bytes April 21 2022 18:08:21.
appdirs.pyc File 8607 bytes April 21 2022 18:08:35.
appdirs.pyo File 8607 bytes April 21 2022 18:08:35.
build.py File 1312 bytes April 21 2022 18:08:21.
build.pyc File 1719 bytes April 21 2022 18:08:35.
build.pyo File 1719 bytes April 21 2022 18:08:35.
deprecation.py File 2232 bytes April 21 2022 18:08:21.
deprecation.pyc File 2317 bytes April 21 2022 18:08:35.
deprecation.pyo File 2317 bytes April 21 2022 18:08:35.
encoding.py File 971 bytes April 21 2022 18:08:21.
encoding.pyc File 1282 bytes April 21 2022 18:08:35.
encoding.pyo File 1282 bytes April 21 2022 18:08:35.
filesystem.py File 899 bytes April 21 2022 18:08:21.
filesystem.pyc File 780 bytes April 21 2022 18:08:35.
filesystem.pyo File 780 bytes April 21 2022 18:08:35.
glibc.py File 2939 bytes April 21 2022 18:08:21.
glibc.pyc File 1826 bytes April 21 2022 18:08:35.
glibc.pyo File 1826 bytes April 21 2022 18:08:35.
hashes.py File 2866 bytes April 21 2022 18:08:21.
hashes.pyc File 3961 bytes April 21 2022 18:08:35.
hashes.pyo File 3961 bytes April 21 2022 18:08:35.
logging.py File 3327 bytes April 21 2022 18:08:21.
logging.pyc File 4842 bytes April 21 2022 18:08:35.
logging.pyo File 4842 bytes April 21 2022 18:08:35.
outdated.py File 5989 bytes April 21 2022 18:08:21.
outdated.pyc File 5680 bytes April 21 2022 18:08:35.
outdated.pyo File 5680 bytes April 21 2022 18:08:35.
packaging.py File 2080 bytes April 21 2022 18:08:21.
packaging.pyc File 2461 bytes April 21 2022 18:08:35.
packaging.pyo File 2461 bytes April 21 2022 18:08:35.
setuptools_build.py File 278 bytes April 21 2022 18:08:21.
setuptools_build.pyc File 347 bytes April 21 2022 18:08:35.
setuptools_build.pyo File 347 bytes April 21 2022 18:08:35.
ui.py File 11597 bytes April 21 2022 18:08:21.
ui.pyc File 11683 bytes April 21 2022 18:08:35.
ui.pyo File 11613 bytes April 21 2022 18:08:36.

Reading File: //usr/lib/python2.7/site-packages/pip/utils/outdated.py

from __future__ import absolute_import

import datetime
import json
import logging
import os.path
import sys

from pip._vendor import lockfile
from pip._vendor.packaging import version as packaging_version

from pip.compat import total_seconds, WINDOWS
from pip.models import PyPI
from pip.locations import USER_CACHE_DIR, running_under_virtualenv
from pip.utils import ensure_dir, get_installed_version
from pip.utils.filesystem import check_path_owner


SELFCHECK_DATE_FMT = "%Y-%m-%dT%H:%M:%SZ"


logger = logging.getLogger(__name__)


class VirtualenvSelfCheckState(object):
    def __init__(self):
        self.statefile_path = os.path.join(sys.prefix, "pip-selfcheck.json")

        # Load the existing state
        try:
            with open(self.statefile_path) as statefile:
                self.state = json.load(statefile)
        except (IOError, ValueError):
            self.state = {}

    def save(self, pypi_version, current_time):
        # Attempt to write out our version check file
        with open(self.statefile_path, "w") as statefile:
            json.dump(
                {
                    "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
                    "pypi_version": pypi_version,
                },
                statefile,
                sort_keys=True,
                separators=(",", ":")
            )


class GlobalSelfCheckState(object):
    def __init__(self):
        self.statefile_path = os.path.join(USER_CACHE_DIR, "selfcheck.json")

        # Load the existing state
        try:
            with open(self.statefile_path) as statefile:
                self.state = json.load(statefile)[sys.prefix]
        except (IOError, ValueError, KeyError):
            self.state = {}

    def save(self, pypi_version, current_time):
        # Check to make sure that we own the directory
        if not check_path_owner(os.path.dirname(self.statefile_path)):
            return

        # Now that we've ensured the directory is owned by this user, we'll go
        # ahead and make sure that all our directories are created.
        ensure_dir(os.path.dirname(self.statefile_path))

        # Attempt to write out our version check file
        with lockfile.LockFile(self.statefile_path):
            if os.path.exists(self.statefile_path):
                with open(self.statefile_path) as statefile:
                    state = json.load(statefile)
            else:
                state = {}

            state[sys.prefix] = {
                "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
                "pypi_version": pypi_version,
            }

            with open(self.statefile_path, "w") as statefile:
                json.dump(state, statefile, sort_keys=True,
                          separators=(",", ":"))


def load_selfcheck_statefile():
    if running_under_virtualenv():
        return VirtualenvSelfCheckState()
    else:
        return GlobalSelfCheckState()


def pip_installed_by_pip():
    """Checks whether pip was installed by pip

    This is used not to display the upgrade message when pip is in fact
    installed by system package manager, such as dnf on Fedora.
    """
    import pkg_resources
    try:
        dist = pkg_resources.get_distribution('pip')
        return (dist.has_metadata('INSTALLER') and
                'pip' in dist.get_metadata_lines('INSTALLER'))
    except pkg_resources.DistributionNotFound:
        return False


def pip_version_check(session):
    """Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
    """
    installed_version = get_installed_version("pip")
    if installed_version is None:
        return

    pip_version = packaging_version.parse(installed_version)
    pypi_version = None

    try:
        state = load_selfcheck_statefile()

        current_time = datetime.datetime.utcnow()
        # Determine if we need to refresh the state
        if "last_check" in state.state and "pypi_version" in state.state:
            last_check = datetime.datetime.strptime(
                state.state["last_check"],
                SELFCHECK_DATE_FMT
            )
            if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
                pypi_version = state.state["pypi_version"]

        # Refresh the version if we need to or just see if we need to warn
        if pypi_version is None:
            resp = session.get(
                PyPI.pip_json_url,
                headers={"Accept": "application/json"},
            )
            resp.raise_for_status()
            pypi_version = [
                v for v in sorted(
                    list(resp.json()["releases"]),
                    key=packaging_version.parse,
                )
                if not packaging_version.parse(v).is_prerelease
            ][-1]

            # save that we've performed a check
            state.save(pypi_version, current_time)

        remote_version = packaging_version.parse(pypi_version)

        # Determine if our pypi_version is older
        if (pip_version < remote_version and
                pip_version.base_version != remote_version.base_version and
                pip_installed_by_pip()):
            # Advise "python -m pip" on Windows to avoid issues
            # with overwriting pip.exe.
            if WINDOWS:
                pip_cmd = "python -m pip"
            else:
                pip_cmd = "pip"
            logger.warning(
                "You are using pip version %s, however version %s is "
                "available.\nYou should consider upgrading via the "
                "'%s install --upgrade pip' command.",
                pip_version, pypi_version, pip_cmd
            )

    except Exception:
        logger.debug(
            "There was an error checking the latest version of pip",
            exc_info=True,
        )

SILENT KILLER Tool