Commit a596ed61 authored by Julien Muchembled's avatar Julien Muchembled

Speed up download of *.bt5 BT by a factor of 2

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40875 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 862c9088
...@@ -427,35 +427,26 @@ class BusinessTemplateTarball(BusinessTemplateArchive): ...@@ -427,35 +427,26 @@ class BusinessTemplateTarball(BusinessTemplateArchive):
return self.fobj return self.fobj
def _initImport(self, file=None, **kw): def _initImport(self, file=None, **kw):
self.f = file self.tar = tarfile.TarFile(fileobj=StringIO(GzipFile(fileobj=file).read()))
self.item_dict = {}
setdefault = self.item_dict.setdefault
for info in self.tar.getmembers():
if info.isreg():
path = info.name.split('/')
if path[0] == '.':
del path[0]
file_name = '/'.join(path[2:])
if '%' in file_name:
file_name = unquote(file_name)
setdefault(path[1], []).append((file_name, info))
def importFiles(self, item, **kw): def importFiles(self, item, **kw):
""" """
Import all file from the archive to the site Import all file from the archive to the site
""" """
class_name = item.__class__.__name__ extractfile = self.tar.extractfile
self.f.seek(0) for file_name, info in self.item_dict.get(item.__class__.__name__, ()):
data = GzipFile(fileobj=self.f).read() item._importFile(file_name, extractfile(info))
io = StringIO(data)
tar = tarfile.TarFile(fileobj=io)
for info in tar.getmembers():
if 'CVS' in info.name.split('/'):
continue
if '.svn' in info.name.split('/'):
continue
if class_name in info.name.split('/'):
if info.isreg():
file = tar.extractfile(info)
tar_file_name = info.name.startswith('./') and info.name[2:] or \
info.name
folders = tar_file_name.split('/')
file_name = ('/').join(folders[2:])
if '%' in file_name:
file_name = unquote(file_name)
item._importFile(file_name, file)
file.close()
tar.close()
io.close()
class TemplateConditionError(Exception): pass class TemplateConditionError(Exception): pass
class TemplateConflictError(Exception): pass class TemplateConflictError(Exception): pass
......
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