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
> 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.::

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

- --
Tres Seaver          +1 202-558-7113          [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to