Commit 457115ac authored by Julien Muchembled's avatar Julien Muchembled

ERP5Subversion: fix cleanup of temporary directories

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40065 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 33a5f5c6
...@@ -36,11 +36,30 @@ import sys ...@@ -36,11 +36,30 @@ import sys
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from MethodObject import Method from MethodObject import Method
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from tempfile import mktemp from tempfile import mkdtemp
import shutil import shutil
class getTransactionalDirectory(str):
"""Returns a temporary directory that is automatically deleted when
transaction ends
"""
def __new__(cls, tv_key):
tv = getTransactionalVariable()
try:
return str(tv[tv_key])
except KeyError:
path = mkdtemp()
tv[tv_key] = str.__new__(cls, path)
return path
def __del__(self):
shutil.rmtree(str(self))
class SubversionError(Exception): class SubversionError(Exception):
"""The base exception class for the Subversion interface. """The base exception class for the Subversion interface.
""" """
...@@ -284,25 +303,14 @@ try: ...@@ -284,25 +303,14 @@ try:
status_list.reverse() status_list.reverse()
return status_list return status_list
def removeAllInList(self, path_list):
"""Remove all files and folders in list
"""
for file_path in path_list:
shutil.rmtree(file_path)
def diff(self, path, revision1, revision2): def diff(self, path, revision1, revision2):
tmp = mktemp() tmp_path = getTransactionalDirectory('SubversionClient.diff:tmp_dir')
os.makedirs(tmp) if revision1 and revision2:
if not revision1 or not revision2: return self.client.diff(tmp_path, url_or_path=path, recurse=False,
diff = self.client.diff(tmp_path=tmp, url_or_path=path, recurse=False) revision1=pysvn.Revision(pysvn.opt_revision_kind.number,revision1),
revision2=pysvn.Revision(pysvn.opt_revision_kind.number,revision2))
else: else:
diff = self.client.diff(tmp_path=tmp, url_or_path=path, \ return self.client.diff(tmp_path, url_or_path=path, recurse=False)
recurse=False, revision1 = pysvn.Revision(pysvn.opt_revision_kind\
.number,revision1), revision2=pysvn.Revision(pysvn\
.opt_revision_kind.number,revision2))
# clean up temp dir
self.activate().removeAllInList([tmp, ])
return diff
def revert(self, path, recurse=False): def revert(self, path, recurse=False):
try: try:
......
...@@ -40,7 +40,7 @@ import os, re ...@@ -40,7 +40,7 @@ import os, re
from DateTime import DateTime from DateTime import DateTime
from cPickle import dumps, loads from cPickle import dumps, loads
from App.config import getConfiguration from App.config import getConfiguration
from tempfile import gettempdir, mktemp from tempfile import gettempdir, mkdtemp
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
import shutil import shutil
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
...@@ -869,7 +869,7 @@ class SubversionTool(BaseTool): ...@@ -869,7 +869,7 @@ class SubversionTool(BaseTool):
# add new file to the tree # add new file to the tree
parent.sub_files.append(File(filename, str(status))) parent.sub_files.append(File(filename, str(status)))
return something_modified and root return something_modified and root
def extractBT(self, business_template): def extractBT(self, business_template):
""" """
Extract business template to hard drive Extract business template to hard drive
...@@ -881,7 +881,7 @@ class SubversionTool(BaseTool): ...@@ -881,7 +881,7 @@ class SubversionTool(BaseTool):
business_template.build() business_template.build()
svn_path = self._getWorkingPath(self.getSubversionPath(business_template) \ svn_path = self._getWorkingPath(self.getSubversionPath(business_template) \
+ os.sep) + os.sep)
path = mktemp() + os.sep path = mkdtemp()
try: try:
# XXX: Big hack to make export work as expected. # XXX: Big hack to make export work as expected.
transaction.commit() transaction.commit()
...@@ -891,13 +891,9 @@ class SubversionTool(BaseTool): ...@@ -891,13 +891,9 @@ class SubversionTool(BaseTool):
# add new files and copy # add new files and copy
self.addNewFiles(svn_path, path) self.addNewFiles(svn_path, path)
self.goToWorkingCopy(business_template) self.goToWorkingCopy(business_template)
except (pysvn.ClientError, NotFound, AttributeError, \ finally:
Error), error:
# Clean up # Clean up
shutil.rmtree(path) shutil.rmtree(path)
raise error
# Clean up
self.activate().removeAllInList([path, ])
def importBT(self, business_template): def importBT(self, business_template):
""" """
......
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