[Zope-CMF] Re: Checking which version of the CMF is running

Tres Seaver tseaver at palladion.com
Fri Oct 13 11:29:23 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Charlie Clark wrote:
> Dear all,
> 
> I noticed recently that Formulator does not work with CMF v2 because
> FSForm.py imports from CMFCore.CMFPermissions so I thought I'd fix this
> and thought it might be useful. Easier said than done as there does not
> seem to be a standard way to find out which version of CMF is installed
> which is presumably why the Plone installer devotes a few lines to it.
> 
> I've come up with the following:
> 
> # Use existing Zope tools to check for the CMFVersion
> import App.Product
> import OFS.Application
> import os.path
> 
> CMFVERSION = None
> 
> for priority, product_name, index, product_dir in
> OFS.Application.get_products():
>     if product_name == "CMFCore":
>         class Dummy(object):
>             """Dummy object for a dummy product install"""
>             def _setObject(self, name, product):
>                 pass
> 
>         A = Dummy()
>         A.Control_Panel = Dummy()
>         A.Control_Panel.Products = Dummy()
> 
>         package_dir=os.path.join(product_dir, product_name)
>         OFS.Application.import_product(product_dir, product_name)
>         productObject = App.Product.initializeProduct(
>                 None, product_name, package_dir, A)
>         version = productObject.version
>         version = version.split("-")
>         major = int(version[-1][0])
>         if major >= 2:
>             CMFVERSION = 2
> 
> I hope this isn't too weird! I think it is flexible enough to be used
> with other Zope Products if required but does beg the question:
> shouldn't there be an easier way to do this? Should there be a standard
> method of getting a Product's version in Zope.app? I assume there are
> other Products that have similar dependencies, although I am not sure if
> the problem is in FSForm itself which does some pretty thoughtless
> importing.

That should work.  However, I think I would rather do "capability
checks" than "version checks", e.g.::

  try:
      from Products.CMFCore.permissions import AddPortalContent
  except ImportError:  # BBB, CMF < 1.5
      from Products.CMFCore.CMFCorePermissions import AddPortalContent



Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFL7DS+gerLs4ltQ4RAvPsAKDHONqZC9hxG/rpacrm+2ovVSHPmwCg02ag
rkbAw4DcXrMsqiqXnj4doDo=
=Lw4q
-----END PGP SIGNATURE-----



More information about the Zope-CMF mailing list