Commit 55d89945 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Move addObject to BusinessTemplateArchive to avoid code duplication in

its children classes



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39865 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 39c6af78
...@@ -321,8 +321,24 @@ class BusinessTemplateArchive: ...@@ -321,8 +321,24 @@ class BusinessTemplateArchive:
def addFolder(self, **kw): def addFolder(self, **kw):
pass pass
def addObject(self, *kw): def addObject(self, obj, name, path=None, ext='.xml'):
pass name = name.replace('\\', '/')
name = quote(name)
name = os.path.normpath(name)
if path is None:
object_path = os.path.join(self.path, name)
else:
if '%' not in path:
tail, path = os.path.splitdrive(path)
path = path.replace('\\', '/')
path = tail + quote(path)
path = os.path.normpath(path)
object_path = os.path.join(path, name)
f = open(object_path+ext, 'wb')
try:
f.write(str(obj))
finally:
f.close()
def finishCreation(self, name=None, **kw): def finishCreation(self, name=None, **kw):
pass pass
...@@ -348,25 +364,6 @@ class BusinessTemplateFolder(BusinessTemplateArchive): ...@@ -348,25 +364,6 @@ class BusinessTemplateFolder(BusinessTemplateArchive):
os.makedirs(path) os.makedirs(path)
return path return path
def addObject(self, obj, name, path=None, ext='.xml'):
name = name.replace('\\', '/')
name = quote(name)
name = os.path.normpath(name)
if path is None:
object_path = os.path.join(self.path, name)
else:
if '%' not in path:
tail, path = os.path.splitdrive(path)
path = path.replace('\\', '/')
path = tail + quote(path)
path = os.path.normpath(path)
object_path = os.path.join(path, name)
f = open(object_path+ext, 'wb')
try:
f.write(str(obj))
finally:
f.close()
def _initImport(self, file=None, path=None, **kw): def _initImport(self, file=None, path=None, **kw):
# Normalize the paths to eliminate the effect of double-slashes. # Normalize the paths to eliminate the effect of double-slashes.
root_path_len = len(os.path.normpath(path)) + len(os.sep) root_path_len = len(os.path.normpath(path)) + len(os.sep)
...@@ -429,25 +426,6 @@ class BusinessTemplateTarball(BusinessTemplateArchive): ...@@ -429,25 +426,6 @@ class BusinessTemplateTarball(BusinessTemplateArchive):
if not os.path.exists(name): if not os.path.exists(name):
os.makedirs(name) os.makedirs(name)
def addObject(self, obj, name, path=None, ext='.xml'):
name = name.replace('\\', '/')
name = quote(name)
name = os.path.normpath(name)
if path is None:
object_path = os.path.join(self.path, name)
else:
if '%' not in path:
tail, path = os.path.splitdrive(path)
path = path.replace('\\', '/')
path = tail + quote(path)
path = os.path.normpath(path)
object_path = os.path.join(path, name)
f = open(object_path+ext, 'wb')
try:
f.write(str(obj))
finally:
f.close()
def finishCreation(self, name): def finishCreation(self, name):
self.tar.add(name) self.tar.add(name)
self.tar.close() self.tar.close()
......
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