How can I test which version of Plone I have running?
In a product it is often useful, or even required, to do different things depending on which version of Plone the product is installed under. These simple methods will allow you to find out what version you are running, and test against that information.
Use the 'portal_migration' tool. It provides two methods that are particularly useful:
-
getInstanceVersion (returns a string with the instance version, like '2.5.4' or '3.0.2')
-
getInstanceVersionTuple (returns a tuple, like (2, 5, 4, 'final', 0)
With this information you can write a simple test or set a variable for your code like so:
from Products.CMFCore.utils import getToolByName
def isPlone3OrBetter(self):
migrationTool = getToolByName(self, 'portal_migration')
return migrationTool.getInstanceVersionTuple[0] >= 3
this can be used in an install script for a product to 'do the right thing' based on what version of plone is running.
