In QGIS, certain processing algorithms change between revision (in my case the merge function between version 2.14.1 and 2.14.7).
How can I access this information from PyQGIS, in order to make a plugin work on both versions?
Global variables can be used to find out QGIS version. A list of all global variables can be obtained via
QgsExpressionContextUtils.globalScope().variableNames()
[u'qgis_version_no', u'user_account_name', u'qgis_platform', u'qgis_os_name', u'qgis_release_name', u'fw_path', u'qgis_version', u'user_full_name']
and the value of a certain variable, say qgis_version
by
QgsExpressionContextUtils.globalScope().variable('qgis_version')
u'2.14.12-Essen'
In some cases it might be helpful to obtain plugin versions as well.
In order to get a list of available plugins, on the python console type
qgis.utils.available_plugins
The version of a distinct plugin can be found out with
qgis.utils.pluginMetadata('thePluginName', 'version')
In case of changed algorithms from one to another version, one has to keep track on it by
>>> import processing
>>> processing.alglist()
D-Infinity Avalanche Runout-------------------------->taudem:dinfinityavalancherunout
D-Infinity Concentration Limited Accumulation-------->taudem:dinfinityconcentrationlimitedaccumulation
D-Infinity Contributing Area------------------------->taudem:dinfinitycontributingarea
D-Infinity Decaying Accumulation--------------------->taudem:dinfinitydecayingaccumulation
[...]
Then e.g. in case of changed names, one could create a dictionary like
alg_dict = {u'2.14.12-Essen':'qgis:algname_old', u'2.14.15-Essen':'qgis:algname_new'}
if applies.
And with the above answer, you could execute your algorithm depending on the version like
>>> import processing
>>> version = QgsExpressionContextUtils.globalScope().variable('qgis_version')
>>> processing.runalg(alg_dict[version], parameter1, parameter2, ...)