Example #1
0
 def test_from_pyqt(self, qt_version, chromium_version):
     expected = version.WebEngineVersions(
         webengine=utils.parse_version(qt_version),
         chromium=chromium_version,
         source='PyQt',
     )
     assert version.WebEngineVersions.from_pyqt(qt_version) == expected
Example #2
0
    def on_version_success(self, newest):
        """Called when the version was obtained from self._pypi_client.

        Args:
            newest: The newest version as a string.
        """
        new_version = utils.parse_version(newest)
        cur_version = utils.parse_version(qutebrowser.__version__)
        lines = ['The report has been sent successfully. Thanks!']
        if new_version > cur_version:
            lines.append("<b>Note:</b> The newest available version is v{}, "
                         "but you're currently running v{} - please "
                         "update!".format(newest, qutebrowser.__version__))
        text = '<br/><br/>'.join(lines)
        msgbox.information(self, "Report successfully sent!", text,
                           on_finished=self.finish, plain_text=False)
Example #3
0
    def from_ua(cls, ua: websettings.UserAgent) -> 'WebEngineVersions':
        """Get the versions parsed from a user agent.

        This is the most reliable and "default" way to get this information (at least
        until QtWebEngine adds an API for it). However, it needs a fully initialized
        QtWebEngine, and we sometimes need this information before that is available.
        """
        assert ua.qt_version is not None, ua
        return cls(
            webengine=utils.parse_version(ua.qt_version),
            chromium=ua.upstream_browser_version,
            source='UA',
        )
Example #4
0
def distribution() -> Optional[DistributionInfo]:
    """Get some information about the running Linux distribution.

    Returns:
        A DistributionInfo object, or None if no info could be determined.
            parsed: A Distribution enum member
            version: A Version object, or None
            pretty: Always a string (might be "Unknown")
    """
    filename = os.environ.get('QUTE_FAKE_OS_RELEASE', '/etc/os-release')
    info = {}
    try:
        with open(filename, 'r', encoding='utf-8') as f:
            for line in f:
                line = line.strip()
                if (not line) or line.startswith('#') or '=' not in line:
                    continue
                k, v = line.split("=", maxsplit=1)
                info[k] = v.strip('"')
    except (OSError, UnicodeDecodeError):
        return None

    pretty = info.get('PRETTY_NAME', None)
    if pretty in ['Linux', None]:  # Funtoo has PRETTY_NAME=Linux
        pretty = info.get('NAME', 'Unknown')
    assert pretty is not None

    if 'VERSION_ID' in info:
        version_id = info['VERSION_ID']
        dist_version: Optional[utils.VersionNumber] = utils.parse_version(
            version_id)
    else:
        dist_version = None

    dist_id = info.get('ID', None)
    id_mappings = {
        'funtoo': 'gentoo',  # does not have ID_LIKE=gentoo
        'org.kde.Platform': 'kde_flatpak',
    }

    parsed = Distribution.unknown
    if dist_id is not None:
        try:
            parsed = Distribution[id_mappings.get(dist_id, dist_id)]
        except KeyError:
            pass

    return DistributionInfo(parsed=parsed,
                            version=dist_version,
                            pretty=pretty,
                            id=dist_id)
Example #5
0
    def _set_changed_attributes(self) -> None:
        """Set qt_version_changed/qutebrowser_version_changed attributes.

        We handle this here, so we can avoid setting qt_version_changed if
        the config is brand new, but can still set it when qt_version wasn't
        there before...
        """
        if 'general' not in self:
            return

        old_qt_version = self['general'].get('qt_version', None)
        self.qt_version_changed = old_qt_version != qVersion()

        old_qutebrowser_version = self['general'].get('version', None)
        if old_qutebrowser_version is None:
            # https://github.com/python/typeshed/issues/2093
            return  # type: ignore[unreachable]

        old_version = utils.parse_version(old_qutebrowser_version)
        new_version = utils.parse_version(qutebrowser.__version__)

        if old_version.isNull():
            log.init.warning(
                f"Unable to parse old version {old_qutebrowser_version}")
            return

        assert not new_version.isNull(), qutebrowser.__version__

        if old_version == new_version:
            self.qutebrowser_version_changed = VersionChange.equal
        elif new_version < old_version:
            self.qutebrowser_version_changed = VersionChange.downgrade
        elif old_version.segments()[:2] == new_version.segments()[:2]:
            self.qutebrowser_version_changed = VersionChange.patch
        elif old_version.majorVersion() == new_version.majorVersion():
            self.qutebrowser_version_changed = VersionChange.minor
        else:
            self.qutebrowser_version_changed = VersionChange.major
Example #6
0
def version_check(version: str,
                  exact: bool = False,
                  compiled: bool = True) -> bool:
    """Check if the Qt runtime version is the version supplied or newer.

    Args:
        version: The version to check against.
        exact: if given, check with == instead of >=
        compiled: Set to False to not check the compiled version.
    """
    if compiled and exact:
        raise ValueError("Can't use compiled=True with exact=True!")

    parsed = utils.parse_version(version)
    op = operator.eq if exact else operator.ge
    result = op(utils.parse_version(qVersion()), parsed)
    if compiled and result:
        # qVersion() ==/>= parsed, now check if QT_VERSION_STR ==/>= parsed.
        result = op(utils.parse_version(QT_VERSION_STR), parsed)
    if compiled and result:
        # Finally, check PYQT_VERSION_STR as well.
        result = op(utils.parse_version(PYQT_VERSION_STR), parsed)
    return result
Example #7
0
def distribution() -> Optional[DistributionInfo]:
    """Get some information about the running Linux distribution.

    Returns:
        A DistributionInfo object, or None if no info could be determined.
            parsed: A Distribution enum member
            version: A Version object, or None
            pretty: Always a string (might be "Unknown")
    """
    info = _parse_os_release()
    if info is None:
        return None

    pretty = info.get('PRETTY_NAME', None)
    if pretty in ['Linux', None]:  # Funtoo has PRETTY_NAME=Linux
        pretty = info.get('NAME', 'Unknown')
    assert pretty is not None

    dist_version: Optional[utils.VersionNumber] = None
    for version_key in ['VERSION', 'VERSION_ID']:
        if version_key in info:
            dist_version = utils.parse_version(info[version_key])
            break

    dist_id = info.get('ID', None)
    id_mappings = {
        'funtoo': 'gentoo',  # does not have ID_LIKE=gentoo
        'artix': 'arch',
        'org.kde.Platform': 'kde_flatpak',
    }

    ids = []
    if dist_id is not None:
        ids.append(id_mappings.get(dist_id, dist_id))
    if 'ID_LIKE' in info:
        ids.extend(info['ID_LIKE'].split())

    parsed = Distribution.unknown
    for cur_id in ids:
        try:
            parsed = Distribution[cur_id]
        except KeyError:
            pass
        else:
            break

    return DistributionInfo(parsed=parsed,
                            version=dist_version,
                            pretty=pretty,
                            id=dist_id)
Example #8
0
    def from_elf(cls, versions: elf.Versions) -> 'WebEngineVersions':
        """Get the versions based on an ELF file.

        This only works on Linux, and even there, depends on various assumption on how
        QtWebEngine is built (e.g. that the version string is in the .rodata section).

        On Windows/macOS, we instead rely on from_pyqt, but especially on Linux, people
        sometimes mix and match Qt/QtWebEngine versions, so this is a more reliable
        (though hackish) way to get a more accurate result.
        """
        return cls(
            webengine=utils.parse_version(versions.webengine),
            chromium=versions.chromium,
            source='ELF',
        )
Example #9
0
    def from_pyqt(
            cls,
            pyqt_webengine_version: str,
            source: str = 'PyQt',
    ) -> 'WebEngineVersions':
        """Get the versions based on the PyQtWebEngine version.

        This is the "last resort" if we don't want to fully initialize QtWebEngine (so
        from_ua isn't possible) and we're not on Linux (or ELF parsing failed).

        Here, we assume that the PyQtWebEngine version is the same as the QtWebEngine
        version, and infer the Chromium version from that. This assumption isn't
        generally true, but good enough for some scenarios, especially the prebuilt
        Windows/macOS releases.

        Note that we only can get the PyQtWebEngine version with PyQt 5.13 or newer.
        With Qt 5.12, we instead rely on qVersion().
        """
        return cls(
            webengine=utils.parse_version(pyqt_webengine_version),
            chromium=cls._infer_chromium_version(pyqt_webengine_version),
            source=source,
        )
Example #10
0
     version.DistributionInfo(id='arch',
                              parsed=version.Distribution.arch,
                              version=None,
                              pretty='Arch Linux')),
    # Ubuntu 14.04
    ("""
    NAME="Ubuntu"
    VERSION="14.04.5 LTS, Trusty Tahr"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 14.04.5 LTS"
    VERSION_ID="14.04"
 """,
     version.DistributionInfo(id='ubuntu',
                              parsed=version.Distribution.ubuntu,
                              version=utils.parse_version('14.4'),
                              pretty='Ubuntu 14.04.5 LTS')),
    # Ubuntu 17.04
    ("""
    NAME="Ubuntu"
    VERSION="17.04 (Zesty Zapus)"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 17.04"
    VERSION_ID="17.04"
 """,
     version.DistributionInfo(id='ubuntu',
                              parsed=version.Distribution.ubuntu,
                              version=utils.parse_version('17.4'),
                              pretty='Ubuntu 17.04')),
    # Debian Jessie
Example #11
0
def is_new_qtwebkit() -> bool:
    """Check if the given version is a new QtWebKit."""
    assert qWebKitVersion is not None
    return (utils.parse_version(qWebKitVersion()) >
            utils.parse_version('538.1'))