Commit 77e8b072 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Do not use VTM but the standard TM for fineed control.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13792 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8acdd618
...@@ -37,7 +37,7 @@ from Acquisition import Implicit ...@@ -37,7 +37,7 @@ from Acquisition import Implicit
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, DTMLFile from Globals import InitializeClass, DTMLFile
from App.config import getConfiguration from App.config import getConfiguration
from Products.ERP5Type.TM import VTM as TM from Shared.DC.ZRDB.TM import TM
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
...@@ -74,13 +74,49 @@ LOCAL_DIRECTORY_LIST = ('Document', 'Extensions', 'Constraint', 'tests', 'Proper ...@@ -74,13 +74,49 @@ LOCAL_DIRECTORY_LIST = ('Document', 'Extensions', 'Constraint', 'tests', 'Proper
if allowClassTool(): if allowClassTool():
class ClassTool(TM, BaseTool): class TemporaryInstanceHome(TM):
_finalize = None
path = None
def __init__(self):
pass
def getPath(self):
return self.path
def _begin(self):
self.path = tempfile.mkdtemp()
try:
for name in LOCAL_DIRECTORY_LIST:
os.mkdir(os.path.join(self.path, name))
except:
shutil.rmtree(self.path)
raise
def _finish(self):
instance_home = getConfiguration().instancehome
for name in LOCAL_DIRECTORY_LIST:
source_dir = os.path.join(self.path, name)
destination_dir = os.path.join(instance_home, name)
for fname in os.listdir(source_dir):
source_file = os.path.join(source_dir, fname)
destination_file = os.path.join(destination_dir, fname)
try:
os.remove(destination_file)
except OSError:
pass
shutil.move(source_file, destination_file)
shutil.rmtree(self.path, 1)
def _abort(self):
shutil.rmtree(self.path, 1)
class ClassTool(BaseTool):
""" """
This is the full-featured version of ClassTool. This is the full-featured version of ClassTool.
""" """
id = 'portal_classes' id = 'portal_classes'
meta_type = 'ERP5 Class Tool' meta_type = 'ERP5 Class Tool'
_use_TM = _transactions = 1
# Declarative Security # Declarative Security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -339,9 +375,9 @@ class %s(XMLObject): ...@@ -339,9 +375,9 @@ class %s(XMLObject):
# #
############################################################################## ##############################################################################
class PropertySheetTemplate: class %s:
\"\"\" \"\"\"
PropertySheetTemplate properties for all ERP5 objects %s properties for all ERP5 objects
\"\"\" \"\"\"
_properties = ( _properties = (
...@@ -352,7 +388,7 @@ class PropertySheetTemplate: ...@@ -352,7 +388,7 @@ class PropertySheetTemplate:
) )
""" % COPYRIGHT """ % (COPYRIGHT, class_id, class_id)
self.writeLocalPropertySheet(class_id, text) self.writeLocalPropertySheet(class_id, text)
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Created' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editPropertySheetForm?class_id=%s&message=PropertySheet+Created' % (self.absolute_url(), class_id))
...@@ -588,7 +624,7 @@ class Test(ERP5TypeTestCase): ...@@ -588,7 +624,7 @@ class Test(ERP5TypeTestCase):
from Products.ERP5Type.Constraint import Constraint from Products.ERP5Type.Constraint import Constraint
class ConstraintTemplate(Constraint): class %s(Constraint):
\"\"\" \"\"\"
Explain here what this constraint checker does Explain here what this constraint checker does
\"\"\" \"\"\"
...@@ -605,7 +641,7 @@ class ConstraintTemplate(Constraint): ...@@ -605,7 +641,7 @@ class ConstraintTemplate(Constraint):
# Do the job here # Do the job here
return errors return errors
""" % COPYRIGHT """ % (COPYRIGHT, class_id)
self.writeLocalConstraint(class_id, text) self.writeLocalConstraint(class_id, text)
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Created' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Created' % (self.absolute_url(), class_id))
...@@ -848,84 +884,40 @@ def initialize( context ): ...@@ -848,84 +884,40 @@ def initialize( context ):
dochelper.setStaticPropertyList(property_list) dochelper.setStaticPropertyList(property_list)
return dochelper return dochelper
# Transaction Management def _createTemporaryInstanceHome(self):
def createTemporaryInstanceHome(self): if getattr(self, '_v_instance_home', None) is None:
""" self._v_instance_home = TemporaryInstanceHome()
""" self._v_instance_home._register()
self._register()
# Make a new instance home
if not getattr(self, '_v_instance_home', None):
self._v_instance_home = tempfile.mkdtemp()
instance_home = self._v_instance_home
for name in LOCAL_DIRECTORY_LIST:
os.mkdir(os.sep.join((instance_home, name)))
def deleteTemporaryInstanceHome(self):
"""
"""
# Delete the whole instance home
if getattr(self, '_v_instance_home', None):
tmp_instance_home = self._v_instance_home
for name in LOCAL_DIRECTORY_LIST:
source_dir = os.sep.join((tmp_instance_home, name))
for fname in os.listdir(source_dir):
source_file = os.sep.join((source_dir,fname))
os.remove(source_file)
os.rmdir(source_dir)
os.rmdir(tmp_instance_home)
self._v_instance_home = None
def renameTemporaryInstanceHome(self):
"""
"""
# Delete temporary instance home
tmp_instance_home = self._v_instance_home
instance_home = getConfiguration().instancehome
for name in LOCAL_DIRECTORY_LIST:
source_dir = os.sep.join((tmp_instance_home, name))
destination_dir = os.sep.join((instance_home, name))
for fname in os.listdir(source_dir):
source_file = os.sep.join((source_dir,fname))
destination_file = os.sep.join((destination_dir,fname))
try:
os.remove(destination_file)
except OSError:
pass
shutil.move(source_file, destination_file)
self.deleteTemporaryInstanceHome()
security.declareProtected( Permissions.ManageExtensions, 'writeLocalPropertySheet' ) security.declareProtected( Permissions.ManageExtensions, 'writeLocalPropertySheet' )
def writeLocalPropertySheet(self, class_id, text, create=1): def writeLocalPropertySheet(self, class_id, text, create=1):
self.createTemporaryInstanceHome() self._createTemporaryInstanceHome()
writeLocalPropertySheet(class_id, text, create=create, instance_home=self._v_instance_home) writeLocalPropertySheet(class_id, text, create=create,
instance_home=self._v_instance_home.getPath())
security.declareProtected( Permissions.ManageExtensions, 'writeLocalExtension' ) security.declareProtected( Permissions.ManageExtensions, 'writeLocalExtension' )
def writeLocalExtension(self, class_id, text, create=1): def writeLocalExtension(self, class_id, text, create=1):
self.createTemporaryInstanceHome() self._createTemporaryInstanceHome()
writeLocalExtension(class_id, text, create=create, instance_home=self._v_instance_home) writeLocalExtension(class_id, text, create=create,
instance_home=self._v_instance_home.getPath())
security.declareProtected( Permissions.ManageExtensions, 'writeLocalTest' ) security.declareProtected( Permissions.ManageExtensions, 'writeLocalTest' )
def writeLocalTest(self, class_id, text, create=1): def writeLocalTest(self, class_id, text, create=1):
self.createTemporaryInstanceHome() self._createTemporaryInstanceHome()
writeLocalTest(class_id, text, create=create, instance_home=self._v_instance_home) writeLocalTest(class_id, text, create=create,
instance_home=self._v_instance_home.getPath())
security.declareProtected( Permissions.ManageExtensions, 'writeLocalDocument' ) security.declareProtected( Permissions.ManageExtensions, 'writeLocalDocument' )
def writeLocalDocument(self, class_id, text, create=1): def writeLocalDocument(self, class_id, text, create=1):
self.createTemporaryInstanceHome() self._createTemporaryInstanceHome()
writeLocalDocument(class_id, text, create=create, instance_home=self._v_instance_home) writeLocalDocument(class_id, text, create=create,
instance_home=self._v_instance_home.getPath())
security.declareProtected( Permissions.ManageExtensions, 'writeLocalConstraint' ) security.declareProtected( Permissions.ManageExtensions, 'writeLocalConstraint' )
def writeLocalConstraint(self, class_id, text, create=1): def writeLocalConstraint(self, class_id, text, create=1):
self.createTemporaryInstanceHome() self._createTemporaryInstanceHome()
writeLocalConstraint(class_id, text, create=create, instance_home=self._v_instance_home) writeLocalConstraint(class_id, text, create=create,
instance_home=self._v_instance_home.getPath())
def _finish(self):
# Move all temp files we created
self.renameTemporaryInstanceHome()
def _abort(self):
# Delete all temp files we created
self.deleteTemporaryInstanceHome()
else: else:
......
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