Commit 2eba8a3e authored by Nicolas Delaby's avatar Nicolas Delaby

Embrace the future, replace minidom by lxml & improve performances

reviewed by Aurel


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33129 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3a934974
...@@ -71,7 +71,7 @@ customImporters={ ...@@ -71,7 +71,7 @@ customImporters={
from zLOG import LOG, WARNING, PROBLEM from zLOG import LOG, WARNING, PROBLEM
from warnings import warn from warnings import warn
from gzip import GzipFile from gzip import GzipFile
from xml.dom.minidom import parse from lxml.etree import parse
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
from Products.ERP5Type import tarfile from Products.ERP5Type import tarfile
...@@ -1581,17 +1581,14 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem): ...@@ -1581,17 +1581,14 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem):
# import workflow chain for portal_type # import workflow chain for portal_type
skin_selection_dict = {} skin_selection_dict = {}
xml = parse(file) xml = parse(file)
skin_folder_selection_list = xml.getElementsByTagName('skin_folder_selection') for skin_folder_selection in xml.getroot():
for skin_folder_selection in skin_folder_selection_list: skin_folder_id = skin_folder_selection.find('skin_folder').text
skin_folder_id = skin_folder_selection.getElementsByTagName( selection_string = skin_folder_selection.find('skin_selection').text
'skin_folder')[0].childNodes[0].data
selection_string = skin_folder_selection.getElementsByTagName(
'skin_selection')[0].childNodes
if not selection_string: if not selection_string:
selection_list = [] selection_list = []
else: else:
selection_list = selection_string[0].data.split(',') selection_list = selection_string.split(',')
skin_selection_dict[str(skin_folder_id)] = selection_list skin_selection_dict[skin_folder_id] = selection_list
self._objects = skin_selection_dict self._objects = skin_selection_dict
...@@ -1722,18 +1719,14 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -1722,18 +1719,14 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
if 'workflow_chain_type.xml' in file_name: if 'workflow_chain_type.xml' in file_name:
# import workflow chain for portal_type # import workflow chain for portal_type
dict = {} result_dict = {}
xml = parse(file) xml = parse(file)
chain_list = xml.getElementsByTagName('chain') chain_list = xml.findall('//chain')
for chain in chain_list: for chain in chain_list:
ptype = chain.getElementsByTagName('type')[0].childNodes[0].data portal_type = chain.find('type').text
workflow_list = chain.getElementsByTagName('workflow')[0].childNodes workflow = chain.find('workflow').text or ''
if len(workflow_list) == 0: result_dict[portal_type] = workflow
workflow = '' self._workflow_chain_archive = result_dict
else:
workflow = workflow_list[0].data
dict[str(ptype)] = str(workflow)
self._workflow_chain_archive = dict
else: else:
ObjectTemplateItem._importFile(self, file_name, file) ObjectTemplateItem._importFile(self, file_name, file)
...@@ -1935,20 +1928,16 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): ...@@ -1935,20 +1928,16 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
# import workflow chain for portal_type # import workflow chain for portal_type
dict = {} result_dict = {}
xml = parse(file) xml = parse(file)
chain_list = xml.getElementsByTagName('chain') chain_list = xml.findall('chain')
for chain in chain_list: for chain in chain_list:
ptype = chain.getElementsByTagName('type')[0].childNodes[0].data portal_type = chain.find('type').text
workflow_list = chain.getElementsByTagName('workflow')[0].childNodes workflow = chain.find('workflow').text or ''
if len(workflow_list) == 0: if 'portal_type_workflow_chain/' not in portal_type:
workflow = '' portal_type = 'portal_type_workflow_chain/%s' % (portal_type,)
else: result_dict[portal_type] = workflow
workflow = workflow_list[0].data self._objects = result_dict
if 'portal_type_workflow_chain/' not in str(ptype):
ptype = 'portal_type_workflow_chain/' + str(ptype)
dict[str(ptype)] = str(workflow)
self._objects = dict
# just for backward compatibility # just for backward compatibility
PortalTypeTemplateWorkflowChainItem = PortalTypeWorkflowChainTemplateItem PortalTypeTemplateWorkflowChainItem = PortalTypeWorkflowChainTemplateItem
...@@ -2047,14 +2036,11 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem): ...@@ -2047,14 +2036,11 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem):
return return
path, name = posixpath.split(file_name) path, name = posixpath.split(file_name)
xml = parse(file) xml = parse(file)
portal_type_list = xml.getElementsByTagName('portal_type') portal_type_list = xml.findall('portal_type')
for portal_type in portal_type_list: for portal_type in portal_type_list:
id = portal_type.getAttribute('id') id = portal_type.get('id')
item_type_list = [] item_type_list = [item.text for item in portal_type.findall('item')]
item_list = portal_type.getElementsByTagName('item') self._objects['%s/%s' % (self.class_property, id,)] = item_type_list
for item in item_list:
item_type_list.append(str(item.childNodes[0].data))
self._objects[self.class_property+'/'+id] = item_type_list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
p = context.getPortalObject() p = context.getPortalObject()
...@@ -2412,20 +2398,17 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -2412,20 +2398,17 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
name = os.path.basename(file_name) name = os.path.basename(file_name)
id = name.split('.', 1)[0] id = name.split('.', 1)[0]
xml = parse(file) xml = parse(file)
method_list = xml.getElementsByTagName('item') method_list = xml.findall('item')
for method in method_list: for method in method_list:
key = method.getAttribute('key') key = method.get('key')
key_type = str(method.getAttribute('type')) key_type = method.get('type')
value_node = method.find('value')
if key_type == "str": if key_type == "str":
if len(method.getElementsByTagName('value')[0].childNodes): value = value_node.text or ''
value = str(method.getElementsByTagName('value')[0].childNodes[0].data)
else:
value = ''
elif key_type == "int": elif key_type == "int":
value = int(method.getElementsByTagName('value')[0].childNodes[0].data) value = int(value_node.text)
elif key_type == "tuple": elif key_type == "tuple":
value = tuple(item.childNodes[0].data value = tuple([value_node.text for value_node in method.findall('value')])
for item in method.getElementsByTagName('value'))
else: else:
LOG('BusinessTemplate import CatalogMethod, type unknown', 0, key_type) LOG('BusinessTemplate import CatalogMethod, type unknown', 0, key_type)
continue continue
...@@ -2729,28 +2712,32 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem): ...@@ -2729,28 +2712,32 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem):
return return
type_roles_list = [] type_roles_list = []
xml = parse(file) xml = parse(file)
xml_type_roles_list = xml.getElementsByTagName('role') xml_type_roles_list = xml.findall('role')
for role in xml_type_roles_list: for role in xml_type_roles_list:
id = role.getAttribute('id').encode('utf_8', 'backslashreplace') id = role.get('id')
type_role_property_dict = {'id':id} if isinstance(id, unicode):
id = id.encode('utf_8', 'backslashreplace')
type_role_property_dict = {'id': id}
# uniq # uniq
property_list = role.getElementsByTagName('property') property_list = role.findall('property')
for property in property_list: for property_node in property_list:
property_id = property.getAttribute('id').encode() property_id = property_node.get('id')
if property.hasChildNodes(): if property_node.text:
property_value = property.childNodes[0].data.encode('utf_8', 'backslashreplace') value = property_node.text
type_role_property_dict[property_id] = property_value if isinstance(value, unicode):
value = value.encode('utf_8', 'backslashreplace')
type_role_property_dict[property_id] = value
# multi # multi
multi_property_list = role.getElementsByTagName('multi_property') multi_property_list = role.findall('multi_property')
for property in multi_property_list: for property_node in multi_property_list:
property_id = property.getAttribute('id').encode() property_id = property_node.get('id')
if not type_role_property_dict.has_key(property_id): if property_node.text:
type_role_property_dict[property_id] = [] value = property_node.text
if property.hasChildNodes(): if isinstance(value, unicode):
property_value = property.childNodes[0].data.encode('utf_8', 'backslashreplace') value = value.encode('utf_8', 'backslashreplace')
type_role_property_dict[property_id].append(property_value) type_role_property_dict.setdefault(property_id, []).append(value)
type_roles_list.append(type_role_property_dict) type_roles_list.append(type_role_property_dict)
self._objects['portal_type_roles/'+file_name[:-4]] = type_roles_list self._objects['portal_type_roles/%s' % (file_name[:-4],)] = type_roles_list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
...@@ -2809,20 +2796,15 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -2809,20 +2796,15 @@ class SitePropertyTemplateItem(BaseTemplateItem):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
xml = parse(file) xml = parse(file)
property_list = xml.getElementsByTagName('property') property_node = xml.getroot()[0]
for prop in property_list: property_id = property_node.find('id').text
id = prop.getElementsByTagName('id')[0].childNodes[0].data prop_type = property_node.find('type').text
prop_type = prop.getElementsByTagName('type')[0].childNodes[0].data value_node = property_node.find('value')
if prop_type in ('lines', 'tokens'): if prop_type in ('lines', 'tokens'):
value = [] value = [item.text for item in value_node.findall('item')]
values = prop.getElementsByTagName('value')[0] else:
items = values.getElementsByTagName('item') value = value_node.text
for item in items: self._objects[property_id] = (prop_type, value)
i = item.childNodes[0].data
value.append(str(i))
else:
value = str(prop.getElementsByTagName('value')[0].childNodes[0].data)
self._objects[str(id)] = (str(prop_type), value)
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
...@@ -3014,46 +2996,27 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -3014,46 +2996,27 @@ class ModuleTemplateItem(BaseTemplateItem):
mapping = {} mapping = {}
xml = parse(file) xml = parse(file)
for key in ('portal_type', 'id', 'title', 'permission_list'): for key in ('portal_type', 'id', 'title', 'permission_list'):
elt = xml.getElementsByTagName(key)[0] key_node = xml.find(key)
if key == 'permission_list': if key == 'permission_list':
plist = [] permission_list = []
perm_list = elt.getElementsByTagName('permission') for permission in key_node:
for perm in perm_list: permission_type = permission.get('type', None)
perm_type = perm.getAttribute('type').encode() or None name = permission.find('name').text
name_elt = perm.getElementsByTagName('name')[0] role_list = [role.text for role in permission.findall('role')]
name_node = name_elt.childNodes[0] if permission_type in ('list', None):
name = name_node.data perm_tuple = (name, list(role_list))
role_list = perm.getElementsByTagName('role')
rlist = []
for role in role_list:
role_node = role.childNodes[0]
role = role_node.data
rlist.append(str(role))
if perm_type == 'list' or perm_type is None:
perm_tuple = (str(name), list(rlist))
else: else:
perm_tuple = (str(name), tuple(rlist)) perm_tuple = (name, tuple(role_list))
plist.append(perm_tuple) permission_list.append(perm_tuple)
mapping[key] = plist mapping[key] = permission_list
else: else:
node_list = elt.childNodes mapping[key] = key_node.text or ''
if len(node_list) == 0:
value = ''
else:
value = node_list[0].data
mapping[key] = str(value)
category_list = [] category_list = []
try: category_list_node = xml.find('category_list')
elt = xml.getElementsByTagName('category_list')[0] if category_list_node is not None:
except IndexError: category_list.extend(node.text for node\
pass in category_list_node.findall('category'))
else:
category_element_list = elt.getElementsByTagName('category')
for category_element in category_element_list:
category_node = category_element.childNodes[0]
category = str(category_node.data)
category_list.append(category)
mapping['category_list'] = category_list mapping['category_list'] = category_list
self._objects[file_name[:-4]] = mapping self._objects[file_name[:-4]] = mapping
...@@ -3185,7 +3148,7 @@ class DocumentTemplateItem(BaseTemplateItem): ...@@ -3185,7 +3148,7 @@ class DocumentTemplateItem(BaseTemplateItem):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
text = file.read() text = file.read()
self._objects[file_name[:-3]]=text self._objects[file_name[:-3]] = text
class PropertySheetTemplateItem(DocumentTemplateItem): class PropertySheetTemplateItem(DocumentTemplateItem):
local_file_reader_name = 'readLocalPropertySheet' local_file_reader_name = 'readLocalPropertySheet'
...@@ -3280,11 +3243,9 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -3280,11 +3243,9 @@ class RoleTemplateItem(BaseTemplateItem):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
xml = parse(file) xml = parse(file)
role_list = xml.getElementsByTagName('role') for role in xml.getroot():
for role in role_list: value = role.text
node = role.childNodes[0] self._objects[value] = 1
value = node.data
self._objects[str(value)] = 1
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
p = context.getPortalObject() p = context.getPortalObject()
...@@ -3350,14 +3311,9 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem): ...@@ -3350,14 +3311,9 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -3444,14 +3400,9 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem): ...@@ -3444,14 +3400,9 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -3541,14 +3492,9 @@ class CatalogResultTableTemplateItem(BaseTemplateItem): ...@@ -3541,14 +3492,9 @@ class CatalogResultTableTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -3636,14 +3582,9 @@ class CatalogKeywordKeyTemplateItem(BaseTemplateItem): ...@@ -3636,14 +3582,9 @@ class CatalogKeywordKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -3731,14 +3672,9 @@ class CatalogDateTimeKeyTemplateItem(BaseTemplateItem): ...@@ -3731,14 +3672,9 @@ class CatalogDateTimeKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(context) catalog = _getCatalogValue(context)
...@@ -3826,14 +3762,9 @@ class CatalogFullTextKeyTemplateItem(BaseTemplateItem): ...@@ -3826,14 +3762,9 @@ class CatalogFullTextKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -3922,14 +3853,9 @@ class CatalogRequestKeyTemplateItem(BaseTemplateItem): ...@@ -3922,14 +3853,9 @@ class CatalogRequestKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -4017,14 +3943,9 @@ class CatalogMultivalueKeyTemplateItem(BaseTemplateItem): ...@@ -4017,14 +3943,9 @@ class CatalogMultivalueKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -4111,14 +4032,9 @@ class CatalogTopicKeyTemplateItem(BaseTemplateItem): ...@@ -4111,14 +4032,9 @@ class CatalogTopicKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -4205,14 +4121,9 @@ class CatalogScriptableKeyTemplateItem(BaseTemplateItem): ...@@ -4205,14 +4121,9 @@ class CatalogScriptableKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -4301,14 +4212,9 @@ class CatalogRoleKeyTemplateItem(BaseTemplateItem): ...@@ -4301,14 +4212,9 @@ class CatalogRoleKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -4397,14 +4303,9 @@ class CatalogLocalRoleKeyTemplateItem(BaseTemplateItem): ...@@ -4397,14 +4303,9 @@ class CatalogLocalRoleKeyTemplateItem(BaseTemplateItem):
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
list = []
xml = parse(file) xml = parse(file)
key_list = xml.getElementsByTagName('key') key_list = [key.text for key in xml.getroot()]
for key in key_list: self._objects[file_name[:-4]] = key_list
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self) catalog = _getCatalogValue(self)
...@@ -4629,11 +4530,9 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4629,11 +4530,9 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
self._objects[file_name[:-3]] = text self._objects[file_name[:-3]] = text
elif name == 'language.xml': elif name == 'language.xml':
xml = parse(file) xml = parse(file)
language_element = xml.getElementsByTagName('language')[0] language_element = xml.find('language')
name_element = language_element.getElementsByTagName('name')[0] name = language_element.find('name').text
name = str(name_element.childNodes[0].data) code = language_element.find('code').text
code_element = language_element.getElementsByTagName('code')[0]
code = str(code_element.childNodes[0].data)
self._objects[code] = name self._objects[code] = name
class LocalRolesTemplateItem(BaseTemplateItem): class LocalRolesTemplateItem(BaseTemplateItem):
...@@ -4691,19 +4590,13 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4691,19 +4590,13 @@ class LocalRolesTemplateItem(BaseTemplateItem):
return return
xml = parse(file) xml = parse(file)
# local roles # local roles
local_roles = xml.getElementsByTagName('local_roles')[0] local_roles_list = xml.findall('//role')
local_roles_list = local_roles.getElementsByTagName('role')
local_roles_dict = {} local_roles_dict = {}
for role in local_roles_list: for role in local_roles_list:
id = role.getAttribute('id') id = role.get('id')
if isinstance(id, unicode): item_type_list = [item.text for item in role]
id = id.encode('utf-8')
item_type_list = []
item_list = role.getElementsByTagName('item')
for item in item_list:
item_type_list.append(str(item.childNodes[0].data))
local_roles_dict[id] = item_type_list local_roles_dict[id] = item_type_list
self._objects['local_roles/'+file_name[:-4]] = (local_roles_dict, ) self._objects['local_roles/%s' % (file_name[:-4],)] = (local_roles_dict, )
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
......
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