[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ ProfileRegistry can also use GlobalRegistryStorage (as pointed by yuppie);
Godefroid Chapelle
gotcha at bubblenet.be
Fri Mar 11 05:39:30 EST 2011
Log message for revision 120859:
ProfileRegistry can also use GlobalRegistryStorage (as pointed by yuppie);
UpgradeRegistry as well
get rid of cleanups
Changed:
U Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py
U Products.GenericSetup/trunk/Products/GenericSetup/registry.py
U Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py
U Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py
U Products.GenericSetup/trunk/Products/GenericSetup/zcml.py
-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py 2011-03-11 09:47:54 UTC (rev 120858)
+++ Products.GenericSetup/trunk/Products/GenericSetup/interfaces.py 2011-03-11 10:39:30 UTC (rev 120859)
@@ -857,3 +857,7 @@
class IExportStep(Interface):
""" Named export step.
"""
+
+class IUpgradeSteps(Interface):
+ """ Named upgrade steps.
+ """
Modified: Products.GenericSetup/trunk/Products/GenericSetup/registry.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/registry.py 2011-03-11 09:47:54 UTC (rev 120858)
+++ Products.GenericSetup/trunk/Products/GenericSetup/registry.py 2011-03-11 10:39:30 UTC (rev 120859)
@@ -258,7 +258,7 @@
def clear(self):
for key in self.keys():
- self.unregister(key)
+ del self[key]
class BaseStepRegistry( Implicit ):
@@ -691,7 +691,7 @@
security.setDefaultAccess( 'allow' )
def __init__( self ):
-
+ self._registered = GlobalRegistryStorage(IProfile)
self.clear()
security.declareProtected( ManagePortal, 'getProfileInfo' )
@@ -699,8 +699,7 @@
""" See IProfileRegistry.
"""
- sm = getGlobalSiteManager()
- result = sm.queryUtility(IProfile, name=profile_id)
+ result = self._registered.get(profile_id)
if result is None:
raise KeyError, profile_id
if for_ is not None:
@@ -714,8 +713,7 @@
""" See IProfileRegistry.
"""
result = []
- sm = getGlobalSiteManager()
- for profile_id, profile_info in sm.getUtilitiesFor(IProfile):
+ for profile_id in self._registered.keys():
info = self.getProfileInfo( profile_id )
if for_ is None or issubclass( for_, info['for'] ):
result.append( profile_id )
@@ -744,8 +742,7 @@
""" See IProfileRegistry.
"""
profile_id = self._computeProfileId(name, product)
- sm = getGlobalSiteManager()
- if sm.queryUtility(provided=IProfile, name=profile_id) is not None:
+ if self._registered.get(profile_id) is not None:
raise KeyError, 'Duplicate profile ID: %s' % profile_id
info = { 'id' : profile_id
@@ -762,7 +759,7 @@
# metadata.xml description trumps ZCML description... awkward
info.update( metadata )
- sm.registerUtility(info, provided=IProfile, name=profile_id)
+ self._registered[profile_id] = info
def _computeProfileId(self, name, product):
profile_id = '%s:%s' % (product or 'other', name)
@@ -771,16 +768,11 @@
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)
+ del self._registered[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._registered.clear()
InitializeClass( ProfileRegistry )
Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py 2011-03-11 09:47:54 UTC (rev 120858)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py 2011-03-11 10:39:30 UTC (rev 120859)
@@ -985,8 +985,9 @@
tool.manage_doUpgrades()
self.assertEqual(tool._profile_upgrade_versions, {})
finally:
- _upgrade_registry._registry.clear()
- _upgrade_registry._registry.update(old)
+ _upgrade_registry.clear()
+ for key in old:
+ _upgrade_registry._registry[key] = old[key]
def test_listExportSteps(self):
site = self._makeSite()
Modified: Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py 2011-03-11 09:47:54 UTC (rev 120858)
+++ Products.GenericSetup/trunk/Products/GenericSetup/upgrade.py 2011-03-11 10:39:30 UTC (rev 120859)
@@ -19,7 +19,8 @@
from BTrees.OOBTree import OOBTree
-from Products.GenericSetup.registry import _profile_registry
+from Products.GenericSetup.interfaces import IUpgradeSteps
+from Products.GenericSetup.registry import GlobalRegistryStorage
def normalize_version(version):
@@ -40,7 +41,7 @@
- id -> [ (id1, step1), (id2, step2) ] for nested steps
"""
def __init__(self):
- self._registry = OOBTree()
+ self._registry = GlobalRegistryStorage(IUpgradeSteps)
def __getitem__(self, key):
return self._registry.get(key)
@@ -56,7 +57,7 @@
None if there are no steps registered for a profile matching
that id.
"""
- profile_steps = self._registry.get(profile_id, None)
+ profile_steps = self._registry.get(profile_id)
if profile_steps is None:
self._registry[profile_id] = OOBTree()
profile_steps = self._registry.get(profile_id)
@@ -66,7 +67,7 @@
"""Returns the specified upgrade step for the specified
profile, or None if it doesn't exist.
"""
- profile_steps = self._registry.get(profile_id, None)
+ profile_steps = self._registry.get(profile_id)
if profile_steps is not None:
step = profile_steps.get(step_id, None)
if step is None:
Modified: Products.GenericSetup/trunk/Products/GenericSetup/zcml.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/zcml.py 2011-03-11 09:47:54 UTC (rev 120858)
+++ Products.GenericSetup/trunk/Products/GenericSetup/zcml.py 2011-03-11 10:39:30 UTC (rev 120859)
@@ -23,7 +23,6 @@
from Products.GenericSetup.registry import _import_step_registry
from Products.GenericSetup.registry import _export_step_registry
from Products.GenericSetup.registry import _profile_registry
-from Products.GenericSetup.upgrade import _upgrade_registry
#### genericsetup:registerProfile
@@ -366,22 +365,3 @@
def __call__(self):
return ()
-
-
-#### cleanup
-
-def cleanUpProfiles():
- _upgrade_registry.clear()
-
-
-def cleanUpImportSteps():
- pass
-
-def cleanUpExportSteps():
- pass
-
-from zope.testing.cleanup import addCleanUp
-addCleanUp(cleanUpProfiles)
-addCleanUp(cleanUpImportSteps)
-addCleanUp(cleanUpExportSteps)
-del addCleanUp
More information about the checkins
mailing list