|
|
|
@ -15,9 +15,7 @@
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from ..cl_xml import xpath
|
|
|
|
|
# import xml.dom.minidom
|
|
|
|
|
from lxml import etree
|
|
|
|
|
from ..cl_xml import xpath, xml_to_str, str_to_xml_doc
|
|
|
|
|
from ..cl_template import TemplateFormat
|
|
|
|
|
from ..cl_lang import setLocalTranslate
|
|
|
|
|
from collections.abc import Iterable
|
|
|
|
@ -57,7 +55,7 @@ class xml_xfce(TemplateFormat):
|
|
|
|
|
|
|
|
|
|
def setNameBodyNode(self, name):
|
|
|
|
|
"""Устанавливает название для корневой ноды документа"""
|
|
|
|
|
if not self.bodyNode:
|
|
|
|
|
if self.bodyNode is None:
|
|
|
|
|
return False
|
|
|
|
|
self.bodyNode.set("name", name)
|
|
|
|
|
return True
|
|
|
|
@ -71,12 +69,12 @@ class xml_xfce(TemplateFormat):
|
|
|
|
|
<channel version="1.0">
|
|
|
|
|
</channel>'''
|
|
|
|
|
try:
|
|
|
|
|
# self.doc = xml.dom.minidom.parseString(self.text)
|
|
|
|
|
self.doc = etree.XML(bytes(bytearray(self.text, encoding='utf-8')))
|
|
|
|
|
except Exception:
|
|
|
|
|
self.doc = str_to_xml_doc(self.text)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
self.setError(_("The template content is not XML"))
|
|
|
|
|
return False
|
|
|
|
|
self.rootNode = self.doc
|
|
|
|
|
self.rootNode = self.doc.getroottree().getroot()
|
|
|
|
|
self.bodyNode = self.rootNode
|
|
|
|
|
return self.doc
|
|
|
|
|
|
|
|
|
@ -96,7 +94,6 @@ class xml_xfce(TemplateFormat):
|
|
|
|
|
Также удаляет аттрибут action у всех нод
|
|
|
|
|
"""
|
|
|
|
|
childNodes = list(xmlNode)
|
|
|
|
|
# if xmlNode.nodeType == xmlNode.ELEMENT_NODE:
|
|
|
|
|
if "action" in xmlNode.keys():
|
|
|
|
|
nAction = xmlNode.get("action")
|
|
|
|
|
if nAction not in ("join", "replace", "drop"):
|
|
|
|
@ -131,18 +128,18 @@ class xml_xfce(TemplateFormat):
|
|
|
|
|
nextOldNode = xmlOldNode
|
|
|
|
|
# if xmlNode.nodeType == xmlNode.ELEMENT_NODE:
|
|
|
|
|
n = xmlNode
|
|
|
|
|
nType = u''
|
|
|
|
|
nValue = u''
|
|
|
|
|
nAction = u''
|
|
|
|
|
nType = ''
|
|
|
|
|
nValue = ''
|
|
|
|
|
nAction = ''
|
|
|
|
|
attrName = ''
|
|
|
|
|
attrType = ''
|
|
|
|
|
path = n.tag
|
|
|
|
|
if "name" in n.keys():
|
|
|
|
|
nName = n.get("name")
|
|
|
|
|
attrName = u"attribute::name='%s'" % nName
|
|
|
|
|
attrName = "attribute::name='%s'" % nName
|
|
|
|
|
if "type" in n.keys():
|
|
|
|
|
nType = n.get("type")
|
|
|
|
|
attrType = u"attribute::type='%s'" % nType
|
|
|
|
|
attrType = "attribute::type='%s'" % nType
|
|
|
|
|
if "value" in n.keys():
|
|
|
|
|
nValue = n.get("value")
|
|
|
|
|
if "action" in n.keys():
|
|
|
|
@ -161,9 +158,9 @@ class xml_xfce(TemplateFormat):
|
|
|
|
|
findAttr = [x for x in strAttr if x]
|
|
|
|
|
findAttrStr = ''
|
|
|
|
|
if findAttr:
|
|
|
|
|
strAttr = u' and '.join(findAttr)
|
|
|
|
|
strAttr = ' and '.join(findAttr)
|
|
|
|
|
findAttrStr = "[%s]" % strAttr
|
|
|
|
|
findPath = u"child::%s%s" % (path, findAttrStr)
|
|
|
|
|
findPath = "child::%s%s" % (path, findAttrStr)
|
|
|
|
|
# Рабочая нода
|
|
|
|
|
if flagRootNode:
|
|
|
|
|
workNode = xmlOldNode.getparent()
|
|
|
|
@ -237,10 +234,10 @@ class xml_xfce(TemplateFormat):
|
|
|
|
|
|
|
|
|
|
def joinDoc(self, doc):
|
|
|
|
|
"""Объединение документа шаблона и документа файла"""
|
|
|
|
|
if not self.doc:
|
|
|
|
|
if self.doc is None:
|
|
|
|
|
self.setError(_("The text file is not XML"))
|
|
|
|
|
return False
|
|
|
|
|
if not doc:
|
|
|
|
|
if doc is None:
|
|
|
|
|
self.setError(_("The text file is not XML"))
|
|
|
|
|
return False
|
|
|
|
|
# Импортируем корневую ноду нового документа в текущий документ
|
|
|
|
@ -252,6 +249,6 @@ class xml_xfce(TemplateFormat):
|
|
|
|
|
|
|
|
|
|
def getConfig(self):
|
|
|
|
|
"""Получение текстового файла из XML документа"""
|
|
|
|
|
data = self.doc.toprettyxml(encoding='UTF-8').split("\n")
|
|
|
|
|
data = xml_to_str(self.doc).split("\n")
|
|
|
|
|
data = [x for x in data if x.strip()]
|
|
|
|
|
return "\n".join(data).replace("\t", " ").decode("UTF-8")
|
|
|
|
|
return "\n".join(data).replace("\t", " ")
|
|
|
|
|