Commit 80994259 authored by Vincent Pelletier's avatar Vincent Pelletier

Folder,Extensions: get rid of exportAll, ImportAll and ImportExportSkins.

These are very outdated stuff (pre-Business Templates), they do not scale
and (except ImportExportSkins) try to write to a paths which should not
exist.
parent ea32ff15
import os
# We first should look to the import folder
import_path = '/var/lib/zope/import'
allowed_portal = ('portal_catalog','portal_categories','portal_types')
def PortalRoot_importAll(self, REQUEST=None):
"""
this allows to import many zexp files by the same time
"""
context=self
file_list = os.listdir(import_path)
folder_list = []
portal_list = []
# First we should retrieve the list of path
for file_name in file_list:
if file_name.find('___')>0 and file_name.find('.zexp')>0:
base_id = file_name[:file_name.find('___')]
if base_id not in folder_list and base_id not in portal_list:
folder_list.append(base_id)
elif file_name.find('.zexp')>0:
short_name = file_name[:-len('.zexp')]
if short_name in allowed_portal:
portal_list.append(short_name)
# We should at the beginning delete portals
for portal_id in portal_list:
context._delObject(portal_id)
get_transaction().commit()
for portal_id in portal_list:
context.manage_importObject("%s.zexp" % portal_id,set_owner=0)
get_transaction().commit()
# Then import all objects...
for folder_id in folder_list:
folder = self._getOb(folder_id)
for file_name in file_list:
if file_name.find('.zexp')>0 and file_name.find(folder_id)==0:
try:
folder.manage_importObject(file_name,set_owner=0)
except:
pass
get_transaction().commit()
# Import Export Skins
# XXX Warning XXX
# The file /usr/lib/zope/lib/python/Shared/DC/ZRDB/DA.py
# have to be patched with a manage_FTPget wich contains
# a section <dtml-comment></dtml-comment>
import os
from App.config import getConfiguration
fs_skin_ids = ('fs_erp5_core', 'fs_erp5_trade', 'fs_erp5_accounting', 'fs_erp5_crm')
fs_skin_spec = ('ERP5 Filesystem Formulator Form',
'ERP5 Filesystem PDF Template',
'Filesystem Formulator Form',
'Filesystem Page Template',
'Filesystem Script (Python)',
'Filesystem Z SQL Method')
fs_skin_dir = os.path.join(getConfiguration().instancehome, 'Products')
zodb_skin_ids = ('erp5_core', 'erp5_trade', 'erp5_accounting', 'erp5_crm')
zodb_skin_spec = ('ERP5 Form', 'ERP5 PDF Template', 'Page Template', 'Script', 'Script (Python)','Z SQL Method')
def importSkins(self, REQUEST=None, fs_skin_ids=fs_skin_ids, fs_skin_spec=fs_skin_spec, \
zodb_skin_ids=zodb_skin_ids, zodb_skin_spec=zodb_skin_spec, \
fs_skin_dir=fs_skin_dir):
context = self
result = '\n@@@ Beginning @@@\n'
i = 0
for fs_skin_id in fs_skin_ids:
zodb_skin_id = zodb_skin_ids[i]
i += 1
result += "\n@@@ Working in fs_skin_id %s @@@\n" % fs_skin_id
for spec in fs_skin_spec:
for o in context.portal_skins[fs_skin_id].objectValues(spec):
result += "Working on object : %s\n" % o.id
try:
# First convert the skin to text
text = o.manage_FTPget()
except:
result += "| error on %s" % o.id
text = None
raise # yo
# Then create a new object
try:
new_o = context.portal_skins[zodb_skin_id][o.id]
except:
folder = context.portal_skins[zodb_skin_id]
if spec == 'ERP5 Filesystem Formulator Form':
folder.manage_addProduct['ERP5Form'].addERP5Form(id = o.id)
elif spec == 'ERP5 Filesystem PDF Template':
folder.manage_addProduct['ERP5Form'].addPDFTemplate(id = o.id)
elif spec == 'Filesystem Z SQL Method':
# We have to do many things since there's not a good manage_FTPput
# for ZSQLMethods, this code is based on the one from
# Products.CMFCore.FSSQLMethod, method _readFile
folder.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod(id = o.id,\
title='', connection_id='', arguments='', template='')
elif spec == 'Filesystem Formulator Form':
folder.manage_addProduct['ERP5Form'].addERP5Form(id = o.id)
elif spec == 'Filesystem Page Template':
folder.manage_addProduct['PageTemplates'].manage_addPageTemplate(id = o.id)
elif spec == 'Filesystem Script (Python)':
folder.manage_addProduct['PythonScripts'].manage_addPythonScript(id = o.id)
try:
new_o = context.portal_skins[zodb_skin_id][o.id]
except:
new_o = None
if new_o is not None:
REQUEST['BODY'] = text
if spec == 'Filesystem Z SQL Method': # XXX We must do specific things for
# ZSQLMethods, have to be removed when
# manage_FTPput for ZSQLMethod will be rewritten
start = text.rfind('<dtml-comment>')
end = text.rfind('</dtml-comment>')
block = text[start+14:end]
parameters = {}
for line in block.split('\n'):
pair = line.split(':',1)
if len(pair)!=2:
continue
parameters[pair[0].strip().lower()]=pair[1].strip()
# check for required and optional parameters
max_rows = parameters.get('max_rows',1000)
max_cache = parameters.get('max_cache',100)
cache_time = parameters.get('cache_time',0)
class_name = parameters.get('class_name','')
class_file = parameters.get('class_file','')
title = parameters.get('title','')
connection_id = parameters.get('connection_id','')
arguments = parameters.get('arguments','')
start = text.rfind('<params>')
end = text.rfind('</params>')
arguments = text[start+8:end]
#connection_id='MySQL'
template = text[end+9:]
while template.find('\n')==0:
template=template.replace('\n','',1)
# For Debug
#result += "\n\nid: %s mr: %s mc: %s ct: %s cn: %s \
# cf: %s t: %s ci: %s a: %s t: %s params: %s\n\n\n" % \
# (new_o.id,max_rows,max_cache,cache_time,class_name,class_file,title,
# connection_id,arguments,template,str(parameters))
try:
new_o.manage_edit(title=title,connection_id=connection_id,\
arguments=arguments, template=template)
new_o.manage_advanced(max_rows, max_cache, cache_time, class_name, class_file)
except:
result += "\nXXX unable to update this zsql method : %s" % new_o.id
else:
try:
new_o.manage_FTPput(REQUEST, REQUEST.RESPONSE)
except:
result += "| error2 on %s" % o.id
#return new_o.id
result += "\n%s" % o.id
# And update it with the text
#new_o.updateFromText(text)
return result
def exportSkins(self, REQUEST=None, fs_skin_ids=fs_skin_ids, fs_skin_spec=fs_skin_spec, \
zodb_skin_ids=zodb_skin_ids, zodb_skin_spec=zodb_skin_spec, \
fs_skin_dir=fs_skin_dir):
context = self
result = ''
i = 0
for zodb_skin_id in zodb_skin_ids:
fs_skin_id = fs_skin_ids[i]
fs_skin_path = context.portal_skins[fs_skin_id].getDirPath()
i += 1
for spec in zodb_skin_spec:
for o in context.portal_skins[zodb_skin_id].objectValues(spec):
# First convert the skin to text
text = o.manage_FTPget()
# Determine extension
if spec == 'ERP5 Form':
fs_ext = '.form'
elif spec == 'ERP5 PDF Template':
fs_ext = '.pdft'
elif spec == 'Script':
fs_ext = '.py'
elif spec == 'Script (Python)':
fs_ext = '.py'
elif spec == 'Z SQL Method':
fs_ext = '.zsql'
elif spec == 'Page Template':
fs_ext = '.pt'
else:
fs_ext = '.unknown'
# Then create a new file
fs_file_id = "%s/%s/%s%s" % (fs_skin_dir, fs_skin_path, o.id, fs_ext)
# And update it with the text
f = open(fs_file_id,'w')
f.write(text)
f.close()
tmp_fs_skin_ids = ('erp5_tmp',)
tmp_zodb_skin_ids = ('local_tmp',)
def importTemporarySkins(self, REQUEST=None):
return importSkins(self, REQUEST=REQUEST, fs_skin_ids=tmp_fs_skin_ids, zodb_skin_ids=tmp_zodb_skin_ids)
def exportTemporarySkins(self, REQUEST=None):
return exportSkins(self, REQUEST=REQUEST, fs_skin_ids=tmp_fs_skin_ids, zodb_skin_ids=tmp_zodb_skin_ids)
for folder in context.objectValues(("ERP5 Folder",)):
print "#### Exporting the folder %s ####" % folder.id
folder.exportAll(dir='/var/lib/zope/')
print "#### Exporting the folder %s ####" % 'portal_catalog'
context.manage_exportObject(id='portal_catalog')
print "#### Exporting the folder %s ####" % 'portal_categories'
context.manage_exportObject(id='portal_categories')
print "#### Exporting the folder %s ####" % 'portal_types'
context.manage_exportObject(id='portal_types')
print "work done"
return printed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_exportAll</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -1112,19 +1112,6 @@ class Folder(OFSFolder2, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -1112,19 +1112,6 @@ class Folder(OFSFolder2, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
# Implementation # Implementation
hasContent = hasObject hasContent = hasObject
security.declareProtected( Permissions.ModifyPortalContent, 'exportAll' )
def exportAll(self,dir=None):
"""
Allows to export all object inside a particular folder, one by one
"""
folder_id = self.getId()
if dir != None:
for id in self.objectIds():
f = os.path.join(dir, '%s___%s.zexp' % (folder_id,id))
ob = self._getOb(id)
ob._p_jar.exportFile(ob._p_oid,f)
transaction.commit()
security.declareProtected( Permissions.ModifyPortalContent, 'recursiveApply') security.declareProtected( Permissions.ModifyPortalContent, 'recursiveApply')
def recursiveApply(self, filter=dummyFilter, method=None, def recursiveApply(self, filter=dummyFilter, method=None,
test_after=dummyTestAfter, include=1, REQUEST=None, **kw): test_after=dummyTestAfter, include=1, REQUEST=None, **kw):
......
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