Commit 16597a21 authored by Christophe Dumez's avatar Christophe Dumez

Improved revert but revert added files still needs improvements

Fixed a bug in extension detection for files like "tree.xml.xml"


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6996 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0c24defa
...@@ -471,10 +471,11 @@ class SubversionTool(UniqueObject, Folder): ...@@ -471,10 +471,11 @@ class SubversionTool(UniqueObject, Folder):
if edit_path.strip() == '': if edit_path.strip() == '':
# not in zodb # not in zodb
return '#' return '#'
# remove file extension
tmp = re.search('\\.[\w]+$', edit_path) tmp = re.search('\\.[\w]+$', edit_path)
if tmp: if tmp:
extension = tmp.string[tmp.start():tmp.end()].strip() extension = tmp.string[tmp.start():tmp.end()].strip()
edit_path = edit_path.replace(extension, '') edit_path = edit_path[:-len(extension)]
edit_path = bt.REQUEST["BASE2"] + '/' + edit_path + '/manage_main' edit_path = bt.REQUEST["BASE2"] + '/' + edit_path + '/manage_main'
return edit_path return edit_path
...@@ -719,36 +720,63 @@ class SubversionTool(UniqueObject, Folder): ...@@ -719,36 +720,63 @@ class SubversionTool(UniqueObject, Folder):
"""Revert local changes in a file or a directory. """Revert local changes in a file or a directory.
""" """
client = self._getClient() client = self._getClient()
if not isinstance(path, list) :
path = [path]
if bt is not None: if bt is not None:
path = [self.relativeToAbsolute(x, bt) for x in path]
client.revert(path, recurse)
security.declareProtected('Import/Export objects', 'revertZODB')
# path can be absolute or relative
def revertZODB(self, bt, added_files=None, other_files=None, recurse=False):
"""Revert local changes in a file or a directory
in ZODB and on hard drive
"""
client = self._getClient()
object_to_update = {} object_to_update = {}
if isinstance(path, list) : if not added_files :
for p in path: added_files = []
if not other_files :
other_files = []
if not isinstance(added_files, list) :
added_files=[added_files]
if not isinstance(other_files, list) :
other_files=[other_files]
# Reinstall removed or modified files
for p in other_files :
path_list = p.split(os.sep) path_list = p.split(os.sep)
if 'bt' not in path_list: if 'bt' not in path_list:
if len(path_list) > 2 : if len(path_list) > 2 :
tmp=os.sep.join(path_list[2:]) tmp = os.sep.join(path_list[2:])
# Remove file extension
tmp2 = re.search('\\.[\w]+$', tmp) tmp2 = re.search('\\.[\w]+$', tmp)
if tmp2: if tmp2:
extension = tmp2.string[tmp2.start():tmp2.end()].strip() extension = tmp2.string[tmp2.start():tmp2.end()].strip()
tmp = tmp.replace(extension, '') tmp=tmp[:-len(extension)]
object_to_update[tmp] = 'install' object_to_update[tmp] = 'install'
path = [self.relativeToAbsolute(x, bt) for x in path]
else: # remove added files
path_list = path.split(os.sep) for p in added_files :
path_list = p.split(os.sep)
if 'bt' not in path_list: if 'bt' not in path_list:
if len(path_list) > 2 : if len(path_list) > 2 :
tmp=os.sep.join(path_list[2:]) tmp = os.sep.join(path_list[2:])
# Remove file extension
tmp2 = re.search('\\.[\w]+$', tmp) tmp2 = re.search('\\.[\w]+$', tmp)
if tmp2: if tmp2:
extension = tmp2.string[tmp2.start():tmp2.end()].strip() extension = tmp2.string[tmp2.start():tmp2.end()].strip()
tmp = tmp.replace(extension, '') tmp=tmp[:-len(extension)]
object_to_update[tmp] = 'install' object_to_update[tmp] = 'remove'
path = self.relativeToAbsolute(path, bt)
client.revert(path, recurse) #revert changes
if bt is not None: added_files.extend(other_files)
to_revert = [self.relativeToAbsolute(x, bt) for x in added_files]
if len(to_revert) != 0 :
client.revert(to_revert, recurse)
# Partially reinstall installed bt
installed_bt = bt.portal_templates.getInstalledBusinessTemplate( bt.getTitle()) installed_bt = bt.portal_templates.getInstalledBusinessTemplate( bt.getTitle())
installed_bt.reinstall(object_to_update=object_to_update, force=0) installed_bt.reinstall(object_to_update=object_to_update, force=0)
bt.build()
security.declareProtected('Import/Export objects', 'resolved') security.declareProtected('Import/Export objects', 'resolved')
# path can be absolute or relative # path can be absolute or relative
......
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