Commit 1aefe60b authored by Yoshinori Okuji's avatar Yoshinori Okuji

Change DocumentTemplateItem and its subclasses not to put a class name as a...

Change DocumentTemplateItem and its subclasses not to put a class name as a prefix into each key when being built. Also, fix some coding crimes.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33779 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3dbba6ed
...@@ -349,7 +349,9 @@ class BusinessTemplateFolder(BusinessTemplateArchive): ...@@ -349,7 +349,9 @@ class BusinessTemplateFolder(BusinessTemplateArchive):
path = os.path.normpath(path) path = os.path.normpath(path)
object_path = os.path.join(path, name) object_path = os.path.join(path, name)
f = open(object_path+ext, 'wb') f = open(object_path+ext, 'wb')
try:
f.write(str(obj)) f.write(str(obj))
finally:
f.close() f.close()
def _initImport(self, file=None, path=None, **kw): def _initImport(self, file=None, path=None, **kw):
...@@ -428,7 +430,9 @@ class BusinessTemplateTarball(BusinessTemplateArchive): ...@@ -428,7 +430,9 @@ class BusinessTemplateTarball(BusinessTemplateArchive):
path = os.path.normpath(path) path = os.path.normpath(path)
object_path = os.path.join(path, name) object_path = os.path.join(path, name)
f = open(object_path+ext, 'wb') f = open(object_path+ext, 'wb')
try:
f.write(str(obj)) f.write(str(obj))
finally:
f.close() f.close()
def finishCreation(self, name): def finishCreation(self, name):
...@@ -3124,23 +3128,20 @@ class DocumentTemplateItem(BaseTemplateItem): ...@@ -3124,23 +3128,20 @@ class DocumentTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
for id in self._archive.keys(): for key in self._archive.iterkeys():
self._objects[self.__class__.__name__+'/'+id] = self.local_file_reader_name(id) self._objects[key] = self.local_file_reader_name(key)
def preinstall(self, context, installed_item, **kw): def preinstall(self, context, installed_item, **kw):
modified_object_list = {} modified_object_list = {}
if context.getTemplateFormatVersion() == 1: if context.getTemplateFormatVersion() == 1:
new_keys = self._objects.keys() new_keys = self._objects.keys()
new_dict = PersistentMapping()
# fix key if necessary in installed bt for diff # fix key if necessary in installed bt for diff
extra_prefix = self.__class__.__name__ + '/'
for key in installed_item._objects.keys(): for key in installed_item._objects.keys():
if self.__class__.__name__ in key: if key.startswith(extra_prefix):
new_key = key[len('%s/' % self.__class__.__name__):] new_key = key[len(extra_prefix):]
new_dict[new_key] = installed_item._objects[key] installed_item._objects[new_key] = installed_item._objects[key]
else: del installed_item._objects[key]
new_dict[key] = installed_item._objects[key]
if len(new_dict):
installed_item._objects = new_dict
for path in new_keys: for path in new_keys:
if installed_item._objects.has_key(path): if installed_item._objects.has_key(path):
# compare object to see if there is changes # compare object to see if there is changes
...@@ -3177,7 +3178,7 @@ class DocumentTemplateItem(BaseTemplateItem): ...@@ -3177,7 +3178,7 @@ class DocumentTemplateItem(BaseTemplateItem):
self.local_file_writer_name(name, text, create=0) self.local_file_writer_name(name, text, create=0)
except IOError, error: except IOError, error:
LOG("BusinessTemplate.py", WARNING, "Cannot install class %s on file system" %(name,)) LOG("BusinessTemplate.py", WARNING, "Cannot install class %s on file system" %(name,))
if error.errno : if error.errno:
raise raise
continue continue
if self.local_file_importer_name is not None: if self.local_file_importer_name is not None:
...@@ -3207,8 +3208,8 @@ class DocumentTemplateItem(BaseTemplateItem): ...@@ -3207,8 +3208,8 @@ class DocumentTemplateItem(BaseTemplateItem):
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._archive.keys() object_keys = self._archive.keys()
for id in object_keys: for key in object_keys:
self.local_file_remover_name(id) self.local_file_remover_name(key)
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
...@@ -3216,9 +3217,13 @@ class DocumentTemplateItem(BaseTemplateItem): ...@@ -3216,9 +3217,13 @@ class DocumentTemplateItem(BaseTemplateItem):
return return
path = os.path.join(bta.path, self.__class__.__name__) path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path) bta.addFolder(name=path)
for path in self._objects.keys(): extra_prefix = self.__class__.__name__ + '/'
obj = self._objects[path] for key in self._objects.keys():
bta.addObject(obj=obj, name=path, path=None, ext='.py') obj = self._objects[key]
# BBB the prefix was put into each key in the previous implementation.
if not key.startswith(extra_prefix):
key = extra_prefix + key
bta.addObject(obj=obj, name=key, ext='.py')
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
if not file_name.endswith('.py'): if not file_name.endswith('.py'):
......
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