[Checkins] SVN: Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/ use named utilities for profiles
Godefroid Chapelle
gotcha at bubblenet.be
Wed Mar 2 11:41:13 EST 2011
Log message for revision 120680:
use named utilities for profiles
Changed:
U Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/interfaces.py
U Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/registry.py
U Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_registry.py
U Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_tool.py
U Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_zcml.py
U Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/zcml.py
-=-
Modified: Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/interfaces.py
===================================================================
--- Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/interfaces.py 2011-03-02 16:39:20 UTC (rev 120679)
+++ Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/interfaces.py 2011-03-02 16:41:13 UTC (rev 120680)
@@ -20,7 +20,7 @@
from zope.schema import Text
from zope.schema import TextLine
-# Please note that these values may change. Always import
+# Please note that these values may change. Always import
# the values from here instead of using the values directly.
BASE, EXTENSION = 1, 2
SKIPPED_FILES = ('CVS', '.svn', '_svn', '_darcs')
@@ -70,7 +70,7 @@
def listNotes():
""" Return notes recorded by this context.
-
+
o Result a sequence of (component, message) tuples
"""
@@ -417,7 +417,7 @@
relative (None for absolute paths).
'type' -- either BASE or EXTENSION
-
+
o 'for_', if passed, should be the interface specifying the "site
type" for which the profile is relevant, e.g.
Products.CMFCore.interfaces.ISiteRoot or
@@ -428,7 +428,7 @@
def listProfiles( for_=None ):
""" Return a list of IDs for registered profiles.
-
+
o 'for_', if passed, should be the interface specifying the "site
type" for which the profile is relevant, e.g.
Products.CMFCore.interfaces.ISiteRoot or
@@ -441,7 +441,7 @@
""" Return a list of mappings describing registered profiles.
o See 'getProfileInfo' for a description of the mappings' keys.
-
+
o 'for_', if passed, should be the interface specifying the "site
type" for which the profile is relevant, e.g.
Products.CMFCore.interfaces.ISiteRoot or
@@ -464,7 +464,7 @@
o If 'product' is passed, then 'path' should be interpreted as
relative to the corresponding product directory.
-
+
o 'for_', if passed, should be the interface specifying the "site
type" for which the profile is relevant, e.g.
Products.CMFCore.interfaces.ISiteRoot or
@@ -750,7 +750,7 @@
"""
def __call__():
""" Return a string, suitable for looking up an IContentFactory.
-
+
o The string should allow finding a factory for our context's
container which would create an "empty" instance of the same
type as our context.
@@ -806,7 +806,7 @@
def PUT(REQUEST, RESPONSE):
""" Parse file content and update the object.
- o 'REQUEST' will have a 'get' method, which will have the
+ o 'REQUEST' will have a 'get' method, which will have the
content object in its "BODY" key. It will also have 'get_header'
method, whose headers (e.g., "Content-Type") may affect the
processing of the body.
@@ -847,3 +847,7 @@
Objects providing any of the returned interfaces should be ignored by
the export and import handlers.
"""
+
+class IProfile(Interface):
+ """ Named profile.
+ """
Modified: Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/registry.py
===================================================================
--- Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/registry.py 2011-03-02 16:39:20 UTC (rev 120679)
+++ Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/registry.py 2011-03-02 16:41:13 UTC (rev 120680)
@@ -23,12 +23,14 @@
from App.class_init import InitializeClass
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from zope.interface import implements
+from zope.component import getGlobalSiteManager
from Products.GenericSetup.interfaces import BASE
from Products.GenericSetup.interfaces import IImportStepRegistry
from Products.GenericSetup.interfaces import IExportStepRegistry
from Products.GenericSetup.interfaces import IToolsetRegistry
from Products.GenericSetup.interfaces import IProfileRegistry
+from Products.GenericSetup.interfaces import IProfile
from Products.GenericSetup.permissions import ManagePortal
from Products.GenericSetup.metadata import ProfileMetadata
from Products.GenericSetup.utils import _xmldir
@@ -41,6 +43,7 @@
# XML parser
#
+
class _HandlerBase(ContentHandler):
_MARKER = object()
@@ -662,7 +665,10 @@
""" See IProfileRegistry.
"""
- result = self._profile_info[ profile_id ]
+ sm = getGlobalSiteManager()
+ result = sm.queryUtility(IProfile, name=profile_id)
+ if result is None:
+ raise KeyError, profile_id
if for_ is not None:
if not issubclass( for_, result['for'] ):
raise KeyError, profile_id
@@ -674,7 +680,8 @@
""" See IProfileRegistry.
"""
result = []
- for profile_id in self._profile_ids:
+ sm = getGlobalSiteManager()
+ for profile_id, profile_info in sm.getUtilitiesFor(IProfile):
info = self.getProfileInfo( profile_id )
if for_ is None or issubclass( for_, info['for'] ):
result.append( profile_id )
@@ -702,12 +709,11 @@
):
""" See IProfileRegistry.
"""
- profile_id = '%s:%s' % (product or 'other', name)
- if self._profile_info.get( profile_id ) is not None:
+ profile_id = self._computeProfileId(name, product)
+ sm = getGlobalSiteManager()
+ if sm.queryUtility(provided=IProfile, name=profile_id) is not None:
raise KeyError, 'Duplicate profile ID: %s' % profile_id
- self._profile_ids.append( profile_id )
-
info = { 'id' : profile_id
, 'title' : title
, 'description' : description
@@ -722,13 +728,26 @@
# metadata.xml description trumps ZCML description... awkward
info.update( metadata )
- self._profile_info[ profile_id ] = info
+ sm.registerUtility(info, provided=IProfile, name=profile_id)
+ def _computeProfileId(self, name, product):
+ profile_id = '%s:%s' % (product or 'other', name)
+ return profile_id
+
+ security.declareProtected( ManagePortal, 'unregisterProfile' )
+ def unregisterProfile( self, name, product=None):
+ profile_id = self._computeProfileId(name, product)
+ sm = getGlobalSiteManager()
+ sm.unregisterUtility(provided=IProfile, name=profile_id)
+
security.declarePrivate( 'clear' )
def clear( self ):
+ sm = getGlobalSiteManager()
+ profile_ids = [profile_id for profile_id, profile_info
+ in sm.getUtilitiesFor(IProfile)]
+ for profile_id in profile_ids:
+ sm.unregisterUtility(provided=IProfile, name=profile_id)
- self._profile_info = {}
- self._profile_ids = []
InitializeClass( ProfileRegistry )
Modified: Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_registry.py
===================================================================
--- Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_registry.py 2011-03-02 16:39:20 UTC (rev 120679)
+++ Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_registry.py 2011-03-02 16:41:13 UTC (rev 120680)
@@ -1014,6 +1014,8 @@
, ConformsToIProfileRegistry
):
+
+
def _getTargetClass( self ):
from Products.GenericSetup.registry import ProfileRegistry
@@ -1045,7 +1047,7 @@
, PRODUCT
, PROFILE_TYPE
)
-
+
self.assertEqual( len( registry.listProfiles() ), 1 )
self.assertEqual( len( registry.listProfileInfo() ), 1 )
Modified: Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_tool.py
===================================================================
--- Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_tool.py 2011-03-02 16:39:20 UTC (rev 120679)
+++ Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_tool.py 2011-03-02 16:41:13 UTC (rev 120680)
@@ -79,8 +79,6 @@
_PROFILE_PATH2 = '/tmp/STT_test2'
def afterSetUp(self):
- self._profile_registry_info = profile_registry._profile_info
- self._profile_registry_ids = profile_registry._profile_ids
profile_registry.clear()
global _before_import_events
global _after_import_events
@@ -90,8 +88,6 @@
provideHandler(handleProfileImportedEvent)
def beforeTearDown(self):
- profile_registry._profile_info = self._profile_registry_info
- profile_registry._profile_ids = self._profile_registry_ids
base_registry.unregisterHandler(handleBeforeProfileImportEvent)
base_registry.unregisterHandler(handleProfileImportedEvent)
FilesystemTestBase.beforeTearDown(self)
@@ -929,8 +925,6 @@
path = os.path.join(directory, 'versioned_profile')
# register profile
- orig_profile_reg = (profile_registry._profile_info.copy(),
- profile_registry._profile_ids[:])
profile_registry.registerProfile(profile_id,
'Dummy Profile',
'This is a dummy profile',
@@ -965,8 +959,7 @@
_upgrade_registry._registry = orig_upgrade_registry
# reset profile registry
- (profile_registry._profile_info,
- profile_registry._profile_ids) = orig_profile_reg
+ profile_registry.unregisterProfile(profile_id, product_name)
def test_manage_doUpgrades_no_profile_id_or_updates(self):
site = self._makeSite()
@@ -1059,16 +1052,16 @@
self.assertEqual(len(tool.listProfileInfo(for_=IAnotherSite)), 0)
-_DEFAULT_STEP_REGISTRIES_EXPORT_XML = """\
+_DEFAULT_STEP_REGISTRIES_EXPORT_XML = ("""\
<?xml version="1.0"?>
<export-steps>
<export-step id="step_registries"
handler="Products.GenericSetup.tool.exportStepRegistries"
title="Export import / export steps.">
-
+""" + " " + """
</export-step>
</export-steps>
-"""
+""")
_EXTRAS_STEP_REGISTRIES_EXPORT_XML = """\
<?xml version="1.0"?>
@@ -1088,14 +1081,14 @@
</export-steps>
"""
-_DEFAULT_STEP_REGISTRIES_IMPORT_XML = """\
+_DEFAULT_STEP_REGISTRIES_IMPORT_XML = ("""\
<?xml version="1.0"?>
<import-steps>
<import-step id="foo" handler="foo.bar" title="foo">
-
+""" + " " + """
</import-step>
</import-steps>
-"""
+""")
_EXTRAS_STEP_REGISTRIES_IMPORT_XML = """\
<?xml version="1.0"?>
Modified: Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_zcml.py
===================================================================
--- Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_zcml.py 2011-03-02 16:39:20 UTC (rev 120679)
+++ Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/tests/test_zcml.py 2011-03-02 16:41:13 UTC (rev 120680)
@@ -65,9 +65,7 @@
>>> from Products.GenericSetup.registry import _profile_registry
>>> profile_id = 'Products.GenericSetup:default'
- >>> profile_id in _profile_registry._profile_ids
- True
- >>> info = _profile_registry._profile_info[profile_id]
+ >>> info = _profile_registry.getProfileInfo(profile_id)
>>> info['id']
u'Products.GenericSetup:default'
>>> info['title']
@@ -88,10 +86,6 @@
>>> from zope.testing.cleanup import cleanUp
>>> cleanUp()
- >>> profile_id in _profile_registry._profile_ids
- False
- >>> profile_id in _profile_registry._profile_info
- False
"""
def test_registerProfile():
@@ -117,9 +111,7 @@
>>> from Products.GenericSetup.registry import _profile_registry
>>> profile_id = 'Products.GenericSetup:default'
- >>> profile_id in _profile_registry._profile_ids
- True
- >>> info = _profile_registry._profile_info[profile_id]
+ >>> info = _profile_registry.getProfileInfo(profile_id)
>>> info['id']
u'Products.GenericSetup:default'
>>> info['title']
@@ -140,10 +132,6 @@
>>> from zope.testing.cleanup import cleanUp
>>> cleanUp()
- >>> profile_id in _profile_registry._profile_ids
- False
- >>> profile_id in _profile_registry._profile_info
- False
"""
def test_registerUpgradeStep(self):
@@ -325,7 +313,7 @@
True
>>> step3['step'].purge
True
-
+
First one listed should be second in the registry due to sortkey:
>>> steps = profile_steps[1]
Modified: Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/zcml.py
===================================================================
--- Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/zcml.py 2011-03-02 16:39:20 UTC (rev 120679)
+++ Products.GenericSetup/branches/gotcha-registries-use-utilities/Products/GenericSetup/zcml.py 2011-03-02 16:41:13 UTC (rev 120680)
@@ -68,7 +68,6 @@
required=False)
-_profile_regs = []
def registerProfile(_context, name=u'default', title=None, description=None,
directory=None, provides=BASE, for_=None):
""" Add a new profile to the registry.
@@ -83,8 +82,6 @@
if description is None:
description = u''
- _profile_regs.append('%s:%s' % (product, name))
-
_context.action(
discriminator=('registerProfile', product, name),
callable=_profile_registry.registerProfile,
@@ -381,18 +378,6 @@
#### cleanup
def cleanUpProfiles():
- global _profile_regs
- for profile_id in _profile_regs:
- try:
- del _profile_registry._profile_info[profile_id]
- except KeyError:
- pass
- try:
- _profile_registry._profile_ids.remove(profile_id)
- except ValueError:
- pass
-
- _profile_regs = []
_upgrade_registry.clear()
More information about the checkins
mailing list