Commit 43e0d26e authored by Yoshinori Okuji's avatar Yoshinori Okuji

Fix file descriptor leaks.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13793 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 77e8b072
......@@ -390,7 +390,9 @@ def readLocalPropertySheet(class_id):
path = os.path.join(instance_home, "PropertySheet")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
text = f.read()
finally:
f.close()
return text
......@@ -403,7 +405,10 @@ def writeLocalPropertySheet(class_id, text, create=1, instance_home=None):
if os.path.exists(path):
raise IOError, 'the file %s is already present' % path
f = open(path, 'w')
try:
f.write(text)
finally:
f.close()
def importLocalPropertySheet(class_id, path = None):
from Products.ERP5Type import PropertySheet
......@@ -413,10 +418,13 @@ def importLocalPropertySheet(class_id, path = None):
path = os.path.join(instance_home, "PropertySheet")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
module = imp.load_source(class_id, path, f)
setattr(PropertySheet, class_id, getattr(module, class_id))
# Register base categories
registerBaseCategories(getattr(module, class_id))
finally:
f.close()
base_category_dict = {}
def registerBaseCategories(property_sheet):
......@@ -434,8 +442,11 @@ def importLocalInterface(class_id, path = None):
path = os.path.join(instance_home, "Interface")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
module = imp.load_source(class_id, path, f)
setattr(Products.ERP5Type.Interface, class_id, getattr(module, class_id))
finally:
f.close()
def importLocalConstraint(class_id, path = None):
import Products.ERP5Type.Interface
......@@ -444,8 +455,11 @@ def importLocalConstraint(class_id, path = None):
path = os.path.join(instance_home, "Constraint")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
module = imp.load_source(class_id, path, f)
setattr(Products.ERP5Type.Constraint, class_id, getattr(module, class_id))
finally:
f.close()
def getLocalExtensionList():
if not getConfiguration:
......@@ -499,7 +513,9 @@ def readLocalExtension(class_id):
path = os.path.join(instance_home, "Extensions")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
text = f.read()
finally:
f.close()
return text
......@@ -516,7 +532,9 @@ def readLocalTest(class_id):
path = os.path.join(instance_home, "tests")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
text = f.read()
finally:
f.close()
return text
......@@ -525,7 +543,9 @@ def readLocalConstraint(class_id):
path = os.path.join(instance_home, "Constraint")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
text = f.read()
finally:
f.close()
return text
......@@ -538,7 +558,10 @@ def writeLocalExtension(class_id, text, create=1, instance_home=None):
if os.path.exists(path):
raise IOError, 'the file %s is already present' % path
f = open(path, 'w')
try:
f.write(text)
finally:
f.close()
def writeLocalTest(class_id, text, create=1, instance_home=None):
if instance_home is None:
......@@ -549,7 +572,10 @@ def writeLocalTest(class_id, text, create=1, instance_home=None):
if os.path.exists(path):
raise IOError, 'the file %s is already present' % path
f = open(path, 'w')
try:
f.write(text)
finally:
f.close()
def writeLocalConstraint(class_id, text, create=1, instance_home=None):
if instance_home is None:
......@@ -560,7 +586,10 @@ def writeLocalConstraint(class_id, text, create=1, instance_home=None):
if os.path.exists(path):
raise IOError, 'the file %s is already present' % path
f = open(path, 'w')
try:
f.write(text)
finally:
f.close()
def removeLocalConstraint(class_id):
instance_home = getConfiguration().instancehome
......@@ -594,7 +623,9 @@ def readLocalDocument(class_id):
path = os.path.join(instance_home, "Document")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
try:
text = f.read()
finally:
f.close()
return text
......@@ -607,7 +638,10 @@ def writeLocalDocument(class_id, text, create=1, instance_home=None):
if os.path.exists(path):
raise IOError, 'the file %s is already present' % path
f = open(path, 'w')
try:
f.write(text)
finally:
f.close()
def setDefaultClassProperties(property_holder):
"""Initialize default properties for ERP5Type Documents.
......@@ -679,6 +713,7 @@ def importLocalDocument(class_id, document_path = None):
# Import Document Class and Initialize it
f = open(path)
try:
document_module = imp.load_source(
'Products.ERP5Type.Document.%s' % class_id, path, f)
document_class = getattr(document_module, class_id)
......@@ -693,6 +728,7 @@ def importLocalDocument(class_id, document_path = None):
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment