[Erp5-report] r36101 jm - /erp5/trunk/products/ERP5Type/Utils.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Jun 8 15:41:46 CEST 2010
Author: jm
Date: Tue Jun 8 15:41:45 2010
New Revision: 36101
URL: http://svn.erp5.org?rev=36101&view=rev
Log:
Make load of local Document modules safer
Modules from local Document folders may override existing module.
If such local module can't be imported, the original module should be restored.
This is useful during upgrades.
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=36101&r1=36100&r2=36101&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Tue Jun 8 15:41:45 2010
@@ -920,15 +920,23 @@
path = document_path
path = os.path.join(path, "%s.py" % class_id)
+ module_path = 'Products.ERP5Type.Document.' + class_id
+ document_module = sys.modules.get(module_path)
# Import Document Class and Initialize it
f = open(path)
try:
- document_module = imp.load_source(
- 'Products.ERP5Type.Document.%s' % class_id, path, f)
+ document_module = imp.load_source(module_path, path, f)
document_class = getattr(document_module, class_id)
document_constructor = DocumentConstructor(document_class)
document_constructor_name = "add%s" % class_id
document_constructor.__name__ = document_constructor_name
+ except Exception:
+ f.close()
+ if document_module is not None:
+ sys.modules[module_path] = document_module
+ raise
+ else:
+ f.close()
setattr(Products.ERP5Type.Document, class_id, document_module)
setattr(Products.ERP5Type.Document, document_constructor_name,
document_constructor)
@@ -936,8 +944,6 @@
ModuleSecurityInfo('Products.ERP5Type.Document').declareProtected(
Permissions.AddPortalContent, document_constructor_name,)
InitializeClass(document_class)
- finally:
- f.close()
# Temp documents are created as standard classes with a different constructor
# which patches some methods are the instance level to prevent reindexing
More information about the Erp5-report
mailing list