Commit 9d9f83c7 authored by Georgios Dagkakis's avatar Georgios Dagkakis

BusinessTemplates: Allow export of files like Python Script, Web Page, Web...

BusinessTemplates: Allow export of files like Python Script, Web Page, Web Script etc. separately from the xml
parent 307e4b74
This diff is collapsed.
......@@ -62,7 +62,7 @@ from zLOG import LOG, INFO, WARNING
from base64 import decodestring
import subprocess
import time
from distutils.dir_util import copy_tree
WIN = os.name == 'nt'
......@@ -461,6 +461,72 @@ class TemplateTool (BaseTool):
"""
return self.getFilteredDiff(diff).toHTML()
def _cleanUpTemplateFolder(self, folder_path):
for file_object in os.listdir(folder_path):
file_object_path = os.path.join(folder_path, file_object)
if os.path.isfile(file_object_path):
os.unlink(file_object_path)
else:
shutil.rmtree(file_object_path)
def _importAndReExportBusinessTemplate(self, template_path):
"""
Imports the template that is in the template_path and exports it to the
same path.
We want to clean this directory, i.e. remove all files before
the export. Because this is called as activity though, it could cause
the following problem:
- Activity imports the template
- Activity removes all files from template_path
- Activity fails in export.
Then the folder contents will be changed, so when retrying the
activity may succeed without the user understanding that files were
erased. For this reason export is done in 3 steps:
- First to a temporary directory
- If there was no error delete contents of template_path
- Copy the contents of the temporary directory to the template_path
"""
import_template = self.download(url=template_path)
export_dir = mkdtemp()
try:
import_template.export(path=export_dir, local=True)
self._cleanUpTemplateFolder(template_path)
copy_tree(export_dir, template_path)
except:
raise
finally:
shutil.rmtree(export_dir)
security.declareProtected( 'Import/Export objects', 'importAndReExportBusinessTemplatesFromPath' )
def importAndReExportBusinessTemplatesFromPath(self, repository_list, REQUEST=None, **kw):
"""
Migrate business templates to new format where files like .py or .html
are exported seprately than the xml.
"""
repository_list = filter(bool, repository_list)
if REQUEST is None:
REQUEST = getattr(self, 'REQUEST', None)
if len(repository_list) == 0 and REQUEST:
ret_url = self.absolute_url()
REQUEST.RESPONSE.redirect("%s?portal_status_message=%s"
% (ret_url, 'No repository was defined'))
for repository in repository_list:
repository = repository.rstrip('\n')
repository = repository.rstrip('\r')
for business_template_id in os.listdir(repository):
template_path = os.path.join(repository, business_template_id)
if os.path.isfile(template_path):
LOG(business_template_id,0,'is file, so it is skipped')
else:
if not os.path.exists((os.path.join(template_path, 'bt'))):
LOG(business_template_id,0,'has no bt sub-folder, so it is skipped')
else:
self.activate(activity='SQLQueue')._importAndReExportBusinessTemplate(template_path)
security.declareProtected(Permissions.ManagePortal, 'getFilteredDiff')
def getFilteredDiff(self, diff):
"""
......
......@@ -7546,10 +7546,6 @@ class TestDocumentTemplateItem(BusinessTemplateMixin):
self.assertNotEqual(wf_history_dict.get('actor'), None)
self.assertNotEqual(wf_history_dict.get('comment'), None)
def stepRemoveZodbDocument(self, sequence=None, **kw):
self.getPortalObject().portal_components.deleteContent(
sequence['document_id'])
def stepCheckZodbDocumentExistsAndValidated(self, sequence=None, **kw):
component = getattr(self.getPortalObject().portal_components,
sequence['document_id'], None)
......
This diff is collapsed.
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