Commit 44b917d0 authored by Aurel's avatar Aurel

remove some comments and not used functions

improve some code
make it compatible with windows


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4070 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9a7315a5
...@@ -136,10 +136,10 @@ class TemplateTool (BaseTool): ...@@ -136,10 +136,10 @@ class TemplateTool (BaseTool):
""" """
Export BT in tarball format Export BT in tarball format
""" """
path = './'+business_template.getTitle() path = business_template.getTitle()
export_string = business_template.export(path=path) export_string = business_template.export(path=path)
if RESPONSE is not None: if RESPONSE is not None:
RESPONSE.setHeader('Content-type','tar/x-gzip') # must be tar/x-gzip RESPONSE.setHeader('Content-type','tar/x-gzip')
RESPONSE.setHeader('Content-Disposition', RESPONSE.setHeader('Content-Disposition',
'inline;filename=%s-%s.bt5' % (business_template.getTitle(), business_template.getVersion())) 'inline;filename=%s-%s.bt5' % (business_template.getTitle(), business_template.getVersion()))
try: try:
...@@ -208,31 +208,22 @@ class TemplateTool (BaseTool): ...@@ -208,31 +208,22 @@ class TemplateTool (BaseTool):
os.remove(path) os.remove(path)
return bt return bt
def _importBusinesstemplateObject(self, name):
"""
Create the object business template
"""
bt_file = os.path.join(name, 'bt.xml')
btf = open(bt_file, 'r')
self._importObjectFromFile(btf, id=id)
pass
def download(self, url, id=None, REQUEST=None): def download(self, url, id=None, REQUEST=None):
""" """
Download Business template, can be file or local directory Download Business template, can be file or local directory
""" """
if REQUEST is None: if REQUEST is None:
REQUEST = getattr(self, 'REQUEST', None) REQUEST = getattr(self, 'REQUEST', None)
from urllib import splittype, urlretrieve
path = string.split(url, ":")
if len(path) == 2: # use of file:/... or http://... type, name = splittype(url)
name = path[1]
else:
name = path[0]
if os.path.isdir(name): # new version of business template in plain format (folder) if os.path.isdir(name): # new version of business template in plain format (folder)
file_list = commands.getoutput('find %r' %name) # use os.path.walk instead file_list = []
file_list = string.split(file_list, '\n') def callback(arg, directory, files):
for file in files:
file_list.append(os.path.join(directory, file))
os.path.walk(name, callback, None)
file_list.sort() file_list.sort()
# import bt object # import bt object
self.newContent(portal_type='Business Template', id=id) self.newContent(portal_type='Business Template', id=id)
...@@ -247,15 +238,14 @@ class TemplateTool (BaseTool): ...@@ -247,15 +238,14 @@ class TemplateTool (BaseTool):
continue continue
prop_path = os.path.join(bt_path, pid) prop_path = os.path.join(bt_path, pid)
value = open(prop_path, 'r').read() value = open(prop_path, 'r').read()
if type == 'text' or type == 'string' or type == 'int': if type in ('text', 'string', 'int'):
bt.setProperty(pid, value, type) bt.setProperty(pid, value, type)
elif type == 'lines' or type == 'tokens': elif type in ('lines', 'tokens'):
bt.setProperty(pid[:-5], value.split('\n'), type) bt.setProperty(pid[:-5], value.split(str(os.linesep)), type)
# import all others objects # import all others objects
bt.importFile(dir=1, file=file_list, root_path=name) bt.importFile(dir=1, file=file_list, root_path=name)
else: else:
from urllib import urlretrieve
tempid, temppath = mkstemp() tempid, temppath = mkstemp()
file, headers = urlretrieve(url, temppath) file, headers = urlretrieve(url, temppath)
bt = self._importBT(temppath, id) bt = self._importBT(temppath, id)
......
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