Skip to content

Commit

Permalink
[Plugin Manager] Maximum major, minor and bugfix version is 99.99.99.…
Browse files Browse the repository at this point in the history
… Be consistent with this constraint.
  • Loading branch information
borysiasty committed Jun 10, 2013
1 parent 3361d85 commit f54d979
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 36 deletions.
2 changes: 1 addition & 1 deletion python/pyplugin_installer/installer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def pluginMetadata(fct):
qgisMinimumVersion = pluginMetadata("qgisMinimumVersion").strip()
if not qgisMinimumVersion: qgisMinimumVersion = "0"
qgisMaximumVersion = pluginMetadata("qgisMaximumVersion").strip()
if not qgisMaximumVersion: qgisMaximumVersion = qgisMinimumVersion[0] + ".999"
if not qgisMaximumVersion: qgisMaximumVersion = qgisMinimumVersion[0] + ".99"
#if compatible, add the plugin to the list
if not isCompatible(QGis.QGIS_VERSION, qgisMinimumVersion, qgisMaximumVersion):
error = "incompatible"
Expand Down
33 changes: 11 additions & 22 deletions python/pyplugin_installer/version_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,9 @@ def compareVersions(a,b):
b = normalizeVersion(b)
if a == b:
return 0
# convert the strings to the lists
# convert the strings to lists
v1 = chopString(a)
v2 = chopString(b)

# !! ensure the version contains at least 3 segments. Fill to "x.y.z with "999" segments if needed.
# 999 must me unicode because of isnumeric method used.
if len(v1) == 2:
v1 += [u"999"]
elif len(v1) == 1:
v1 += [u"999",u"999"]
if len(v2) == 2:
v2 += [u"999"]
elif len(v2) == 1:
v2 += [u"999",u"999"]

# set the shorter string as a base
l = len(v1)
if l > len(v2):
Expand All @@ -159,9 +147,10 @@ def compareVersions(a,b):





## COMPARE CURRENT QGIS VERSION WITH qgisMinimumVersion AND qgisMaximumVersion """
"""
COMPARE CURRENT QGIS VERSION WITH qgisMinimumVersion AND qgisMaximumVersion
ALLOWED FORMATS ARE: major.minor OR major.minor.bugfix, where each segment must be 0..99
"""

def splitVersion(s):
""" split string into 2 or 3 numerical segments """
Expand All @@ -171,7 +160,7 @@ def splitVersion(s):
for c in l:
if not c.isnumeric():
return None
if int(c)>999:
if int(c)>99:
return None
if len(l) not in [2,3]:
return None
Expand All @@ -188,7 +177,7 @@ def isCompatible(curVer, minVer, maxVer=None):
return False

if not maxVer:
maxVer = [minVer[0], "999", "999"]
maxVer = [minVer[0], "99", "99"]

if len(minVer)<3:
minVer += ["0"]
Expand All @@ -197,10 +186,10 @@ def isCompatible(curVer, minVer, maxVer=None):
curVer += ["0"]

if len(maxVer)<3:
maxVer += ["999"]
maxVer += ["99"]

minVer = "%03d%03d%03d" % ( int(minVer[0]), int(minVer[1]), int(minVer[2]) )
maxVer = "%03d%03d%03d" % ( int(maxVer[0]), int(maxVer[1]), int(maxVer[2]) )
curVer = "%03d%03d%03d" % ( int(curVer[0]), int(curVer[1]), int(curVer[2]) )
minVer = "%02d%02d%02d" % ( int(minVer[0]), int(minVer[1]), int(minVer[2]) )
maxVer = "%02d%02d%02d" % ( int(maxVer[0]), int(maxVer[1]), int(maxVer[2]) )
curVer = "%02d%02d%02d" % ( int(curVer[0]), int(curVer[1]), int(curVer[2]) )

return ( minVer <= curVer and maxVer >= curVer)
24 changes: 12 additions & 12 deletions src/app/qgspluginregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion, QString maxVersion
}

// Parse qgisMaxVersion. Must be in form x.y.z or just x.y
int maxVerMajor, maxVerMinor, maxVerBugfix = 999;
int maxVerMajor, maxVerMinor, maxVerBugfix = 99;
if ( maxVersion.isEmpty() || maxVersion == "__error__" )
{
maxVerMajor = minVerMajor;
maxVerMinor = 999;
maxVerMinor = 99;
}
else
{
Expand Down Expand Up @@ -252,16 +252,16 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion, QString maxVersion
int qgisMinor = qgisVersionParts.at( 1 ).toInt();
int qgisBugfix = qgisVersionParts.at( 2 ).toInt();

// build strings with trailing zeroes
QString minVer = QString( "%1%2%3" ).arg( minVerMajor, 3, 10, QChar( '0' ) )
.arg( minVerMinor, 3, 10, QChar( '0' ) )
.arg( minVerBugfix, 3, 10, QChar( '0' ) );
QString maxVer = QString( "%1%2%3" ).arg( maxVerMajor, 3, 10, QChar( '0' ) )
.arg( maxVerMinor, 3, 10, QChar( '0' ) )
.arg( maxVerBugfix, 3, 10, QChar( '0' ) );
QString curVer = QString( "%1%2%3" ).arg( qgisMajor, 3, 10, QChar( '0' ) )
.arg( qgisMinor, 3, 10, QChar( '0' ) )
.arg( qgisBugfix, 3, 10, QChar( '0' ) );
// build XxYyZz strings with trailing zeroes if needed
QString minVer = QString( "%1%2%3" ).arg( minVerMajor, 2, 10, QChar( '0' ) )
.arg( minVerMinor, 2, 10, QChar( '0' ) )
.arg( minVerBugfix, 2, 10, QChar( '0' ) );
QString maxVer = QString( "%1%2%3" ).arg( maxVerMajor, 2, 10, QChar( '0' ) )
.arg( maxVerMinor, 2, 10, QChar( '0' ) )
.arg( maxVerBugfix, 2, 10, QChar( '0' ) );
QString curVer = QString( "%1%2%3" ).arg( qgisMajor, 2, 10, QChar( '0' ) )
.arg( qgisMinor, 2, 10, QChar( '0' ) )
.arg( qgisBugfix, 2, 10, QChar( '0' ) );

// compare
return ( minVer <= curVer && maxVer >= curVer);
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgspluginregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class QgsPluginRegistry
bool checkPythonPlugin( QString packageName );

//! Check current QGIS version against requested minimal and optionally maximal QGIS version
//! if maxVersion not specified, the default value is assumed: floor(minVersion) + 0.999.999
//! if maxVersion not specified, the default value is assumed: floor(minVersion) + 0.99.99
bool checkQgisVersion( QString minVersion, QString maxVersion = "" );

private:
Expand Down

0 comments on commit f54d979

Please sign in to comment.