Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Plugin installer] Make QGIS x.99 only compatible with plugins for th…
…e next major release. Introduce 'pyQgisVersion' that usually sticks to QGIS_VERSION, but bumps up to the next release for all the .99 versions
  • Loading branch information
borysiasty committed Dec 18, 2017
1 parent 7c01b7e commit b433866
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
20 changes: 7 additions & 13 deletions python/pyplugin_installer/installer_data.py
Expand Up @@ -32,6 +32,7 @@
import sys
import os
import codecs
import re
try:
import configparser
except ImportError:
Expand All @@ -41,10 +42,10 @@
except ImportError:
from imp import reload
import qgis.utils
from qgis.core import Qgis, QgsNetworkAccessManager, QgsApplication
from qgis.core import QgsNetworkAccessManager, QgsApplication
from qgis.gui import QgsMessageBar
from qgis.utils import iface, plugin_paths
from .version_compare import compareVersions, normalizeVersion, isCompatible
from .version_compare import pyQgisVersion, compareVersions, normalizeVersion, isCompatible


"""
Expand Down Expand Up @@ -212,12 +213,8 @@ def allUnavailable(self):
# ----------------------------------------- #
def urlParams(self):
""" return GET parameters to be added to every request """
# v = str(Qgis.QGIS_VERSION_INT)
# TODO: make this proper again after 3.0 release, by uncommenting
# the line below and removing the other return line:
# return "?qgis=%d.%d" % (int(v[0]), int(v[1:3]))
# TODO: Do the same for lines 469-472
return "?qgis=3.0"
# Strip down the point release segment from the version string
return "?qgis=%s" % re.sub('\.\d*$', '', pyQgisVersion())

# ----------------------------------------- #
def setRepositoryData(self, reposName, key, value):
Expand Down Expand Up @@ -466,10 +463,7 @@ def xmlDownloaded(self):
qgisMaximumVersion = qgisMinimumVersion[0] + ".99"
# if compatible, add the plugin to the list
if not pluginNodes.item(i).firstChildElement("disabled").text().strip().upper() in ["TRUE", "YES"]:
# TODO: make this proper again after 3.0 release, by uncommenting the line below and removing the next line
# TODO: Do the same for lines 215-220
# if isCompatible(Qgis.QGIS_VERSION, qgisMinimumVersion, qgisMaximumVersion):
if isCompatible("3.0", qgisMinimumVersion, qgisMaximumVersion):
if isCompatible(pyQgisVersion(), qgisMinimumVersion, qgisMaximumVersion):
# add the plugin to the cache
plugins.addFromRepository(plugin)
self.mRepositories[reposName]["state"] = 2
Expand Down Expand Up @@ -618,7 +612,7 @@ def pluginMetadata(fct):
if not qgisMaximumVersion:
qgisMaximumVersion = qgisMinimumVersion[0] + ".99"
# if compatible, add the plugin to the list
if not isCompatible(Qgis.QGIS_VERSION, qgisMinimumVersion, qgisMaximumVersion):
if not isCompatible(pyQgisVersion(), qgisMinimumVersion, qgisMaximumVersion):
error = "incompatible"
errorDetails = "%s - %s" % (qgisMinimumVersion, qgisMaximumVersion)
elif not os.path.exists(metadataFile):
Expand Down
13 changes: 13 additions & 0 deletions python/pyplugin_installer/version_compare.py
Expand Up @@ -47,6 +47,7 @@
"""
from builtins import str
from builtins import range
from qgis.core import Qgis

import re

Expand Down Expand Up @@ -199,3 +200,15 @@ def isCompatible(curVer, minVer, maxVer):
curVer = "%04d%04d%04d" % (int(curVer[0]), int(curVer[1]), int(curVer[2]))

return (minVer <= curVer and maxVer >= curVer)


def pyQgisVersion():
""" Return current QGIS version number as X.Y.Z for testing plugin compatibility.
If Y = 99, bump up to (X+1.0.0), so e.g. 2.99 becomes 3.0.0
This way QGIS X.99 is only compatible with plugins for the upcoming major release.
"""
x, y, z = re.findall('^(\d*).(\d*).(\d*)', Qgis.QGIS_VERSION)[0]
if y == '99':
x = str(int(x) + 1)
y = z = '0'
return '%s.%s.%s' % (x, y, z)

0 comments on commit b433866

Please sign in to comment.