Commit d84f6daa authored by Yoshinori Okuji's avatar Yoshinori Okuji

Support removing skins.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1731 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent dd1f5157
...@@ -3,6 +3,7 @@ import re ...@@ -3,6 +3,7 @@ import re
import os import os
import sys import sys
import csv import csv
from Products.CMFCore.utils import expandpath
from zLOG import LOG from zLOG import LOG
...@@ -160,7 +161,7 @@ def checkSkinNames(self, REQUEST=None, csv=0, all=0): ...@@ -160,7 +161,7 @@ def checkSkinNames(self, REQUEST=None, csv=0, all=0):
msg += '</body></html>' msg += '</body></html>'
return msg return msg
def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): def fixSkinNames(self, REQUEST=None, file=None, dry_run=0):
""" """
Fix bad skin names. Fix bad skin names.
...@@ -204,6 +205,7 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -204,6 +205,7 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
#if self.portal_skins[folder][name].meta_type != meta_type: #if self.portal_skins[folder][name].meta_type != meta_type:
# raise RuntimeError, '%s/%s has a different meta type' % (folder, name) # raise RuntimeError, '%s/%s has a different meta type' % (folder, name)
info = NamingInformation() info = NamingInformation()
info.meta_type = meta_type
info.folder = folder info.folder = folder
info.name = name info.name = name
info.new_name = new_name info.new_name = new_name
...@@ -222,7 +224,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -222,7 +224,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
text = skin.manage_FTPget() text = skin.manage_FTPget()
except: except:
type, value, traceback = sys.exc_info() type, value, traceback = sys.exc_info()
msg += 'WARNING: the skin %s could not be retrieved because of the exception %s: %s\n' % (path, str(type), str(value)) line = 'WARNING: the skin %s could not be retrieved because of the exception %s: %s\n' % (path, str(type), str(value))
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
else: else:
name_list = [] name_list = []
for info in info_list: for info in info_list:
...@@ -230,8 +234,17 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -230,8 +234,17 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
text = info.regexp.sub(info.new_name, text) text = info.regexp.sub(info.new_name, text)
name_list.append(info.name) name_list.append(info.name)
if len(name_list) > 0: if len(name_list) > 0:
msg += '%s is modified for %s\n' % ('portal_skins/' + path, ', '.join(name_list)) line = '%s is modified for %s' % ('portal_skins/' + path, ', '.join(name_list))
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
if skin.meta_type in fs_skin_spec:
f = open(expandpath(skin.getObjectFSPath()), 'w')
try:
f.write(text)
finally:
f.close()
else:
REQUEST['BODY'] = text REQUEST['BODY'] = text
skin.manage_FTPput(REQUEST, REQUEST.RESPONSE) skin.manage_FTPput(REQUEST, REQUEST.RESPONSE)
...@@ -241,7 +254,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -241,7 +254,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
text = t.immediate_view text = t.immediate_view
for info in info_list: for info in info_list:
if info.name == text: if info.name == text:
msg += 'Initial view name of %s is modified for %s\n' % ('portal_types/' + t.id, text) line = 'Initial view name of %s is modified for %s' % ('portal_types/' + t.id, text)
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
t.immediate_view = info.new_name t.immediate_view = info.new_name
break break
...@@ -250,7 +265,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -250,7 +265,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
if text is not None: if text is not None:
for info in info_list: for info in info_list:
if info.name == text: if info.name == text:
msg += 'Constructor path of %s is modified for %s\n' % ('portal_types/' + t.id, text) line = 'Constructor path of %s is modified for %s' % ('portal_types/' + t.id, text)
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
t.constructor_path = info.new_name t.constructor_path = info.new_name
break break
...@@ -260,7 +277,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -260,7 +277,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
for info in info_list: for info in info_list:
if info.regexp.search(text) is not None: if info.regexp.search(text) is not None:
text = info.regexp.sub(info.new_name, text) text = info.regexp.sub(info.new_name, text)
msg += 'Action %s of %s is modified for %s\n' % (action.getId(), 'portal_types/' + t.id, info.name) line = 'Action %s of %s is modified for %s' % (action.getId(), 'portal_types/' + t.id, info.name)
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
action.action.text = text action.action.text = text
break break
...@@ -281,7 +300,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -281,7 +300,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
break break
skin_id_list.append(skin_id) skin_id_list.append(skin_id)
if len(name_list) > 0: if len(name_list) > 0:
msg += 'Skins of %s is modified for %s\n' % ('portal_templates/' + template.getId(), ', '.join(name_list)) line = 'Skins of %s is modified for %s' % ('portal_templates/' + template.getId(), ', '.join(name_list))
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
template.setTemplateSkinIdList(skin_id_list) template.setTemplateSkinIdList(skin_id_list)
# Paths. # Paths.
...@@ -295,7 +316,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -295,7 +316,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
break break
path_list.append(path) path_list.append(path)
if len(name_list) > 0: if len(name_list) > 0:
msg += 'Paths of %s is modified for %s\n' % ('portal_templates/' + template.getId(), ', '.join(name_list)) line = 'Paths of %s is modified for %s' % ('portal_templates/' + template.getId(), ', '.join(name_list))
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
template.setTemplatePathList(path_list) template.setTemplatePathList(path_list)
...@@ -308,7 +331,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -308,7 +331,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
for info in info_list: for info in info_list:
if info.regexp.search(text) is not None: if info.regexp.search(text) is not None:
text = info.regexp.sub(info.new_name, text) text = info.regexp.sub(info.new_name, text)
msg += 'Transition %s of %s is modified for %s\n' % (id, 'portal_workflow/' + wf.id, info.name) line = 'Transition %s of %s is modified for %s' % (id, 'portal_workflow/' + wf.id, info.name)
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
transition.actbox_url = text transition.actbox_url = text
break break
...@@ -319,7 +344,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -319,7 +344,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
for info in info_list: for info in info_list:
if info.regexp.search(text) is not None: if info.regexp.search(text) is not None:
text = info.regexp.sub(info.new_name, text) text = info.regexp.sub(info.new_name, text)
msg += 'Worklist %s of %s is modified for %s\n' % (id, 'portal_workflow/' + wf.id, info.name) line = 'Worklist %s of %s is modified for %s' % (id, 'portal_workflow/' + wf.id, info.name)
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
worklist.actbox_url = text worklist.actbox_url = text
break break
...@@ -333,7 +360,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -333,7 +360,9 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
text = info.regexp.sub(info.new_name, text) text = info.regexp.sub(info.new_name, text)
name_list.append(info.name) name_list.append(info.name)
if len(name_list) > 0: if len(name_list) > 0:
msg += 'Script %s of %s is modified for %s\n' % (id, 'portal_workflow/' + wf.id, ', '.join(name_list)) line = 'Script %s of %s is modified for %s' % (id, 'portal_workflow/' + wf.id, ', '.join(name_list))
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
if not dry_run: if not dry_run:
REQUEST['BODY'] = text REQUEST['BODY'] = text
script.manage_FTPput(REQUEST, REQUEST.RESPONSE) script.manage_FTPput(REQUEST, REQUEST.RESPONSE)
...@@ -342,6 +371,15 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -342,6 +371,15 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
if not dry_run: if not dry_run:
for info in info_list: for info in info_list:
try: try:
if info.meta_type in fs_skin_spec:
skin = self.portal_skins[info.folder][info.name]
old_path = expandpath(skin.getObjectFSPath())
new_path = info.regexp.sub(info.new_name, old_path)
if info.removed:
os.remove(old_path)
else:
os.rename(old_path, new_path)
else:
folder = self.portal_skins[info.folder] folder = self.portal_skins[info.folder]
if info.removed: if info.removed:
folder.manage_delObjects([info.name]) folder.manage_delObjects([info.name])
...@@ -350,10 +388,12 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1): ...@@ -350,10 +388,12 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=1):
except: except:
type, value, traceback = sys.exc_info() type, value, traceback = sys.exc_info()
if info.removed: if info.removed:
msg += 'WARNING: the skin %s could not be removed because of the exception %s: %s\n' % (info.name, str(type), str(value)) line = 'WARNING: the skin %s could not be removed because of the exception %s: %s\n' % (info.name, str(type), str(value))
LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
else: else:
msg += 'WARNING: the skin %s could not be renamed to %s because of the exception %s: %s\n' % (info.name, info.new_name, str(type), str(value)) line = 'WARNING: the skin %s could not be renamed to %s because of the exception %s: %s\n' % (info.name, info.new_name, str(type), str(value))
for line in msg.split('\n'):
LOG('fixSkinNames', 0, line) LOG('fixSkinNames', 0, line)
msg += '%s\n' % line
return msg return msg
\ No newline at end of file
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