[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ - The components handler now ensures there is a valid component
Jens Vagelpohl
jens at dataflake.org
Thu Dec 31 06:54:35 EST 2009
Log message for revision 107441:
- The components handler now ensures there is a valid component
registry (not the global registry) before importing or exporting.
Changed:
U Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
U Products.GenericSetup/trunk/Products/GenericSetup/components.py
U Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py
U Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py
-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2009-12-31 11:31:31 UTC (rev 107440)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2009-12-31 11:54:35 UTC (rev 107441)
@@ -4,6 +4,9 @@
1.5.0 (unreleased)
------------------
+- The components handler now ensures there is a valid component
+ registry (not the global registry) before importing or exporting.
+
- Make sure the Import ZMI tab does not blow up if no base profile
has been selected, and make it a little more user-friendly.
Modified: Products.GenericSetup/trunk/Products/GenericSetup/components.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/components.py 2009-12-31 11:31:31 UTC (rev 107440)
+++ Products.GenericSetup/trunk/Products/GenericSetup/components.py 2009-12-31 11:54:35 UTC (rev 107441)
@@ -21,7 +21,9 @@
from zope.component import getUtilitiesFor
from zope.component import getSiteManager
from zope.component import queryMultiAdapter
+from zope.component.interfaces import ComponentLookupError
from zope.component.interfaces import IComponentRegistry
+from zope.location.interfaces import IPossibleSite
from Acquisition import aq_base
from Acquisition import aq_parent
@@ -504,7 +506,16 @@
def importComponentRegistry(context):
"""Import local components.
"""
- sm = getSiteManager(context.getSite())
+ site = context.getSite()
+ sm = None
+ if IPossibleSite.providedBy(site):
+ # All object managers are an IPossibleSite, but this
+ # defines the getSiteManager method to be available
+ try:
+ sm = site.getSiteManager()
+ except ComponentLookupError:
+ sm = None
+
if sm is None or not IComponentRegistry.providedBy(sm):
logger = context.getLogger('componentregistry')
logger.info("Can not register components, as no registry was found.")
@@ -522,7 +533,16 @@
def exportComponentRegistry(context):
"""Export local components.
"""
- sm = getSiteManager(context.getSite())
+ site = context.getSite()
+ sm = None
+ if IPossibleSite.providedBy(site):
+ # All object managers are an IPossibleSite, but this
+ # defines the getSiteManager method to be available
+ try:
+ sm = site.getSiteManager()
+ except ComponentLookupError:
+ sm = None
+
if sm is None or not IComponentRegistry.providedBy(sm):
logger = context.getLogger('componentregistry')
logger.debug("Nothing to export.")
Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py 2009-12-31 11:31:31 UTC (rev 107440)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_components.py 2009-12-31 11:54:35 UTC (rev 107441)
@@ -68,6 +68,9 @@
components = PersistentComponents('++etc++site')
components.__bases__ = (base,)
components.__parent__ = aq_base(context)
+ # Make sure calls to getSiteManager on me return myself
+ # necessary because OFS.ObjectManager.getSiteManager expects _components
+ components._components = components
context.setSiteManager(components)
class IDummyInterface(Interface):
Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py 2009-12-31 11:31:31 UTC (rev 107440)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py 2009-12-31 11:54:35 UTC (rev 107441)
@@ -671,8 +671,7 @@
)
fileish = StringIO( result[ 'tarball' ] )
- self._verifyTarballContents( fileish, [ 'componentregistry.xml'
- , 'import_steps.xml'
+ self._verifyTarballContents( fileish, [ 'import_steps.xml'
, 'export_steps.xml'
, 'rolemap.xml'
, 'toolset.xml'
@@ -718,8 +717,7 @@
fileish = StringIO( result[ 'tarball' ] )
- self._verifyTarballContents( fileish, [ 'componentregistry.xml'
- , 'import_steps.xml'
+ self._verifyTarballContents( fileish, [ 'import_steps.xml'
, 'export_steps.xml'
, 'properties.ini'
, 'rolemap.xml'
@@ -736,8 +734,7 @@
_EXPECTED = [('import_steps.xml', _DEFAULT_STEP_REGISTRIES_IMPORT_XML),
('export_steps.xml', _DEFAULT_STEP_REGISTRIES_EXPORT_XML),
('rolemap.xml', 'dummy'),
- ('toolset.xml', 'dummy'),
- ('componentregistry.xml', 'dummy')]
+ ('toolset.xml', 'dummy')]
site = self._makeSite()
site.setup_tool = self._makeOne('setup_tool')
More information about the checkins
mailing list