Example #1
0
def _next_incompatible_version(version):
    """
    Find the next non-compatible version.

    This is for use with the ~= compatible syntax. It will provide
    the first version that this version must be less than in order
    to be compatible.

    :param str version: PEP 440 compliant version number
    :return: The first version after this version that is not compatible
    :rtype: str
    """
    normalized = NormalizedVersion(version)
    parse_tuple = normalized.parse(version)
    version_tuple = parse_tuple[1]

    *unchanged, increment, dropped = version_tuple
    incremented = increment + 1

    version = unchanged
    version.append(incremented)
    # versions have a minimum length of 2
    if len(version) == 1:
        version.append(0)
    return '.'.join(map(str, version))
Example #2
0
def check_caterpillar_requirement(warn: bool = True) -> bool:
    try:
        raw_version = (
            subprocess.check_output(
                ["caterpillar", "--version"], stderr=subprocess.DEVNULL
            )
            .decode("utf-8")
            .strip()
        )
    except FileNotFoundError:
        if warn:
            sys.stderr.write(
                "\n[ERROR] caterpillar(1) not found; see https://github.com/zmwangx/caterpillar\n"
            )
        return False
    except subprocess.CalledProcessError:
        if warn:
            sys.stderr.write("\n[ERROR] caterpillar --version failed\n")
        return False
    try:
        version = NormalizedVersion(pep440ify(raw_version))
    except UnsupportedVersionError:
        if warn:
            sys.stderr.write(
                "\n[WARNING] failed to recognize caterpillar version %s; "
                "upgrade to at least v%s if you run into problems\n"
                % (repr(raw_version), MINIMUM_CATERPILLAR_VERSION)
            )
        # Fingers crossed
        return True
    if version < NormalizedVersion(MINIMUM_CATERPILLAR_VERSION):
        if warn:
            sys.stderr.write(
                "\n[ERROR] caterpillar version %s is too low; "
                "please upgrade to at least v%s\n"
                % (raw_version, MINIMUM_CATERPILLAR_VERSION)
            )
        return False
    return True
Example #3
0
 def maybe_version(self, v):
     try:
         return NormalizedVersion(v)
     except UnsupportedVersionError:
         return NormalizedVersion("0")
Example #4
0
def check_update_or_print_whats_new(force: bool = False) -> None:
    last_check_date, last_check_version = load_last_check_info()
    write_last_check_info()

    # Only print what's new when the program has checked for updates in
    # the past, and the version that last checked for updates is older
    # than the current running version, and the current running version
    # is not a dev version. Filters out new installations.
    print_whats_new = True
    if not last_check_date:
        print_whats_new = False
    if "dev" in __version__:
        print_whats_new = False
    try:
        if NormalizedVersion(last_check_version) >= NormalizedVersion(__version__):
            print_whats_new = False
    except UnsupportedVersionError:
        pass

    if print_whats_new:
        sys.stderr.write("WHAT'S NEW IN KVM48 v%s:\n\n" % __version__)
        sys.stderr.write(WHATS_NEW)
        sys.stderr.write(
            "\nPress any key to continue (the program will auto-resume in 15 seconds)...\n\n"
        )
        read_keypress_with_timeout(15)

    if not force and datetime.date.today() == last_check_date:
        return
    sys.stderr.write("Checking for updates for KVM48...\n")
    try:
        r = requests.get(
            "https://v.tcl.sh/pypi/KVM48/new_version",
            params=dict(current_version=__version__),
            timeout=5,
        )
        resp = r.json()
        new_version = resp.get("new_version")
        prerelease = resp.get("is_prerelease")
        if new_version is not None:
            sys.stderr.write(
                textwrap.dedent(
                    """\
                    KVM48 {new_version} is available. You are running version {current_version}. You can upgrade with command

                        {pip_upgrade_command}

                    Press any key to continue (the program will auto-resume in 5 seconds)...

                    """.format(
                        new_version=new_version,
                        current_version=__version__,
                        pip_upgrade_command=pip_upgrade_command(prerelease=prerelease),
                    )
                )
            )
            read_keypress_with_timeout(5)
        else:
            sys.stderr.write("KVM48 is up-to-date.\n")
    except Exception:
        pass
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': ':memory:',
    },
}

INSTALLED_APPS = (
    'test_extras',
    'test_app',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

# Django 1.7's built-in migrations framework supersedes South
# See http://south.readthedocs.org/en/latest/releasenotes/1.0.html#library-migration-path
_current_version = NormalizedVersion(django.get_version())
_south_replaced_in_version = NormalizedVersion('1.7')
_south_supported_in_current_version = _current_version < _south_replaced_in_version
if _south_supported_in_current_version:
    # south must go before test_extras so that text_extras's test management command overrides south's
    INSTALLED_APPS = ('south', ) + INSTALLED_APPS

SECRET_KEY = 'stub-value-for-django'