[Erp5-report] r39922 jm - /erp5/trunk/products/ERP5Type/Utils.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Nov 4 18:20:51 CET 2010
Author: jm
Date: Thu Nov 4 18:20:49 2010
New Revision: 39922
URL: http://svn.erp5.org?rev=39922&view=rev
Log:
Forgot changes to products/ERP5Type/Utils.py in r39918
Modified:
erp5/trunk/products/ERP5Type/Utils.py
Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=39922&r1=39921&r2=39922&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Thu Nov 4 18:20:49 2010
@@ -589,23 +589,31 @@ def registerBaseCategories(property_shee
base_category_dict[bc] = 1
def importLocalInterface(module_id, path = None, is_erp5_type=False):
- if path is None:
- instance_home = getConfiguration().instancehome
- path = os.path.join(instance_home, "interfaces")
- path = os.path.join(path, "%s.py" % module_id)
- f = open(path)
- try:
- class_id = "I" + convertToUpperCase(module_id)
- if not is_erp5_type:
+ def provides(class_id):
+ # Create interface getter
+ accessor_name = 'provides' + class_id
+ setattr(BaseClass, accessor_name, lambda self: self.provides(class_id))
+ BaseClass.security.declarePublic(accessor_name)
+ class_id = "I" + convertToUpperCase(module_id)
+ if is_erp5_type:
+ provides(class_id)
+ else:
+ if path is None:
+ instance_home = getConfiguration().instancehome
+ path = os.path.join(instance_home, "interfaces")
+ path = os.path.join(path, "%s.py" % module_id)
+ f = open(path)
+ try:
module = imp.load_source(class_id, path, f)
- import Products.ERP5Type.interfaces
- setattr(Products.ERP5Type.interfaces, class_id, getattr(module, class_id))
- finally:
- f.close()
- # Create interface getter
- accessor_name = 'provides' + class_id
- setattr(BaseClass, accessor_name, lambda self: self.provides(class_id))
- BaseClass.security.declarePublic(accessor_name)
+ finally:
+ f.close()
+ from zope.interface import Interface
+ from Products.ERP5Type import interfaces
+ InterfaceClass = type(Interface)
+ for k, v in module.__dict__.iteritems():
+ if type(v) is InterfaceClass and v is not Interface:
+ setattr(interfaces, k, v)
+ provides(class_id)
def importLocalConstraint(class_id, path = None):
import Products.ERP5Type.Constraint
@@ -935,8 +943,16 @@ def importLocalDocument(class_id, path=N
module_path = "erp5.document"
class_path = "%s.%s" % (module_path, class_id)
module = imp.load_source(class_path, path)
+ klass = getattr(module, class_id, None)
+ # Tolerate that Document doesn't define any class, which can be useful
+ # if we only want to monkey patch.
+ # XXX A new 'Patch' folder should be introduced instead. Each module would
+ # define 2 methods: 'patch' and 'unpatch' (for proper upgrading).
+ if klass is None:
+ assert hasattr(module, 'patch')
+ return
import erp5.document
- setattr(erp5.document, class_id, getattr(module, class_id))
+ setattr(erp5.document, class_id, klass)
document_class_registry[class_id] = class_path
### Migration
More information about the Erp5-report
mailing list