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
from Products.ERP5Type.Utils import convertToUpperCase
from MethodObject import Method
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from AccessControl import ClassSecurityInfo
from Products.PythonScripts.Utility import allow_class
from tempfile import mktemp
from tempfile import mkdtemp
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):
"""The base exception class for the Subversion interface.
"""
......@@ -284,25 +303,14 @@ try:
status_list.reverse()
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):
tmp = mktemp()
os.makedirs(tmp)
if not revision1 or not revision2:
diff = self.client.diff(tmp_path=tmp, url_or_path=path, recurse=False)
tmp_path = getTransactionalDirectory('SubversionClient.diff:tmp_dir')
if revision1 and revision2:
return self.client.diff(tmp_path, 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:
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))
# clean up temp dir
self.activate().removeAllInList([tmp, ])
return diff
return self.client.diff(tmp_path, url_or_path=path, recurse=False)
def revert(self, path, recurse=False):
try:
......
......@@ -40,7 +40,7 @@ import os, re
from DateTime import DateTime
from cPickle import dumps, loads
from App.config import getConfiguration
from tempfile import gettempdir, mktemp
from tempfile import gettempdir, mkdtemp
from Products.CMFCore.utils import getToolByName
import shutil
from xml.sax.saxutils import escape
......@@ -869,7 +869,7 @@ class SubversionTool(BaseTool):
# add new file to the tree
parent.sub_files.append(File(filename, str(status)))
return something_modified and root
def extractBT(self, business_template):
"""
Extract business template to hard drive
......@@ -881,7 +881,7 @@ class SubversionTool(BaseTool):
business_template.build()
svn_path = self._getWorkingPath(self.getSubversionPath(business_template) \
+ os.sep)
path = mktemp() + os.sep
path = mkdtemp()
try:
# XXX: Big hack to make export work as expected.
transaction.commit()
......@@ -891,13 +891,9 @@ class SubversionTool(BaseTool):
# add new files and copy
self.addNewFiles(svn_path, path)
self.goToWorkingCopy(business_template)
except (pysvn.ClientError, NotFound, AttributeError, \
Error), error:
finally:
# Clean up
shutil.rmtree(path)
raise error
# Clean up
self.activate().removeAllInList([path, ])
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