[Erp5-report] r41366 nicolas.dumazet - in /erp5/trunk/products: ERP5/ ERP5Type/ ERP5Type/Tool/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Dec 13 04:02:16 CET 2010
Author: nicolas.dumazet
Date: Mon Dec 13 04:02:15 2010
New Revision: 41366
URL: http://svn.erp5.org?rev=41366&view=rev
Log:
simplify code by using exceptions instead of boolean return values
Modified:
erp5/trunk/products/ERP5/ERP5Site.py
erp5/trunk/products/ERP5Type/Base.py
erp5/trunk/products/ERP5Type/Tool/BaseTool.py
erp5/trunk/products/ERP5Type/Tool/TypesTool.py
Modified: erp5/trunk/products/ERP5/ERP5Site.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/ERP5Site.py?rev=41366&r1=41365&r2=41366&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/ERP5Site.py [utf8] (original)
+++ erp5/trunk/products/ERP5/ERP5Site.py [utf8] Mon Dec 13 04:02:15 2010
@@ -42,7 +42,7 @@ import ERP5Defaults
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
-from zLOG import LOG, INFO, WARNING
+from zLOG import LOG, INFO, WARNING, ERROR
from string import join
import os
import warnings
@@ -1391,22 +1391,20 @@ class ERP5Site(FolderMixIn, CMFSite, Cac
security.declareProtected(Permissions.ManagePortal, 'migrateToPortalTypeClass')
def migrateToPortalTypeClass(self):
- """Migrate site to portal type classes"""
- # XXX do we want to call this automatically? Where? (note that it's likely
- # to fail as portal types are usually not perfectly configured, and it
- # requires user action to fix issues)
- # TODO better errors than the warnings in LOG + AssertionError
- assert self._migrateToPortalTypeClass()
-
- def _migrateToPortalTypeClass(self):
"""Compatibility code that allows migrating a site to portal type classes.
We consider that a Site is migrated if its Types Tool is migrated
(it will always be migrated last)"""
+ # XXX do we want to call this automatically? Where? (note that it's likely
+ # to fail as portal types are usually not perfectly configured, and it
+ # requires user action to fix issues)
if self.portal_types.__class__.__module__ == 'erp5.portal_type':
# nothing to do
- return True
+ return
+ # note that the site itself is not migrated (ERP5Site is not a portal type)
+ # only the tools and top level modules are.
+ # Normally, PersistentMigrationMixin should take care of the rest.
id_list = self.objectIds()
# make sure that Types Tool is migrated last
@@ -1415,17 +1413,8 @@ class ERP5Site(FolderMixIn, CMFSite, Cac
for id in id_list:
method = getattr(self[id], '_migrateToPortalTypeClass', None)
if method is None:
- print id
continue
- if not method():
- LOG('ERP5Site', WARNING, 'Site did not migrate to portal type classes')
- return False
-
- # note that the site itself is not migrated (ERP5Site is not a portal type)
- # only the tools and top level modules are.
- # Normally, PersistentMigrationMixin should take care of the rest.
-
- return True
+ method()
Globals.InitializeClass(ERP5Site)
Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=41366&r1=41365&r2=41366&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Base.py [utf8] Mon Dec 13 04:02:15 2010
@@ -3864,8 +3864,6 @@ class Base( CopyContainer,
assert klass != newklass
self.__class__ = newklass
- return True
-
security.declareProtected(Permissions.DeletePortalContent,
'migratePortalType')
def migratePortalType(self, portal_type):
Modified: erp5/trunk/products/ERP5Type/Tool/BaseTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/BaseTool.py?rev=41366&r1=41365&r2=41366&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/BaseTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/BaseTool.py [utf8] Mon Dec 13 04:02:15 2010
@@ -78,16 +78,17 @@ class BaseTool (UniqueObject, Folder):
def _migrateToPortalTypeClass(self):
portal_type = self.getPortalType()
# Tools are causing problems: they used to have no type_class, or wrong
- # type_class. First check that everything is alright before trying
+ # type_class, or sometimes have no type definitions at all.
+ # Check that everything is alright before trying
# to migrate the tool:
types_tool = self.getPortalObject().portal_types
type_definition = getattr(types_tool, portal_type, None)
if type_definition is None:
- LOG('TypesTool', WARNING,
- "No portal type was found for Tool '%s'"
+ from Products.ERP5.Document.Document import NotConvertedError
+ raise NotConvertedError(
+ "No portal type definition was found for Tool '%s'"
" (class %s, portal_type '%s')"
% (self.getRelativeUrl(), self.__class__.__name__, portal_type))
- return False
type_class = type_definition.getTypeClass()
if type_class in ('Folder', None):
@@ -97,10 +98,10 @@ class BaseTool (UniqueObject, Folder):
if document_class_name in document_class_registry:
type_definition.setTypeClass(document_class_name)
else:
- LOG('TypesTool', WARNING,
+ from Products.ERP5.Document.Document import NotConvertedError
+ raise NotConvertedError(
'No document class could be found for portal type %s'
% portal_type)
- return False
return super(BaseTool, self)._migrateToPortalTypeClass()
Modified: erp5/trunk/products/ERP5Type/Tool/TypesTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Tool/TypesTool.py?rev=41366&r1=41365&r2=41366&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Tool/TypesTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Tool/TypesTool.py [utf8] Mon Dec 13 04:02:15 2010
@@ -328,11 +328,7 @@ class TypesTool(TypeProvider):
def _migrateToPortalTypeClass(self):
for type_definition in self.contentValues():
- if not type_definition._migrateToPortalTypeClass():
- LOG('TypesTool', WARNING,
- 'Type definition %s was not migrated'
- % type_definition.getRelativeUrl())
- return False
+ type_definition._migrateToPortalTypeClass()
return super(TypesTool, self)._migrateToPortalTypeClass()
# Compatibility code to access old "ERP5 Role Information" objects.
More information about the Erp5-report
mailing list