diff --git a/pym/cl_profile.py b/pym/cl_profile.py
index 616aeac..3c25dfd 100644
--- a/pym/cl_profile.py
+++ b/pym/cl_profile.py
@@ -2988,7 +2988,7 @@ class profile(_file, _terms, xmlShare):
newFile)
return False
- if objHeadNew.fileType == "xml_xfce":
+ if "xml_" in objHeadNew.fileType:
if objProfNew.getError():
self.setError (_("False profile: " ) + newFile)
return False
@@ -3017,7 +3017,7 @@ class profile(_file, _terms, xmlShare):
title = title.encode("UTF-8")
# Замена
if objHeadNew.typeAppend == "replace":
- if objHeadNew.fileType == "xml_xfce":
+ if "xml_" in objHeadNew.fileType:
data = self.newProfile.split("\n")
data.insert(1,title)
self.oldProfile = "\n".join(data)
@@ -3031,7 +3031,7 @@ class profile(_file, _terms, xmlShare):
return filesApply
# Впереди
elif objHeadNew.typeAppend == "before":
- if objHeadNew.fileType == "xml_xfce":
+ if "xml_" in objHeadNew.fileType:
self.setError (\
_("False option append=before in profile %s") %newFile)
return False
@@ -3053,7 +3053,7 @@ class profile(_file, _terms, xmlShare):
return filesApply
# Cзади
elif objHeadNew.typeAppend == "after":
- if objHeadNew.fileType == "xml_xfce":
+ if "xml_" in objHeadNew.fileType:
self.setError (\
_("False option append=after in profile %s") %newFile)
return False
@@ -3093,7 +3093,7 @@ class profile(_file, _terms, xmlShare):
+ objHeadNew.fileType + " : " +\
newFile)
return False
- if objHeadNew.fileType == "xml_xfce":
+ if "xml_" in objHeadNew.fileType:
if objProfNew.getError():
self.setError (_("False profile: " ) + newFile)
return False
@@ -3135,7 +3135,7 @@ class profile(_file, _terms, xmlShare):
else:
exec ("objProfOld=%s(self.oldProfile)"%\
(objHeadNew.fileType))
- if objHeadNew.fileType == "xml_xfce":
+ if "xml_" in objHeadNew.fileType:
if objProfOld.getError():
self.setError (_("False profile: " ) + oldFile)
return False
@@ -3145,12 +3145,9 @@ class profile(_file, _terms, xmlShare):
#print "#%s#" %(objProfOld.docObj.body.toprettyxml())
#print "#%s#" %(objProfNew.docObj.body.toprettyxml())
objProfOld.join(objProfNew)
- #if objHeadNew.fileType=="xml_xfce":
- #print "OLD"
- #print "New"
#print objProfOld.doc.toprettyxml()
#print objProfNew.doc.toprettyxml()
- if objHeadNew.fileType == "xml_xfce":
+ if "xml_" in objHeadNew.fileType:
if objProfOld.getError():
self.setError (_("False profile: " ) + newFile)
return False
@@ -5100,8 +5097,6 @@ class xml_xfce(_error):
self.text = '''
'''
- if hasattr(self, "objVar"):
- print self.objVar.Get("cl_pass_file")
try:
self.doc = xml.dom.minidom.parseString(self.text)
except:
@@ -5114,7 +5109,12 @@ class xml_xfce(_error):
def join(self, xml_xfceObj):
"""Объединяем конфигурации"""
if isinstance(xml_xfceObj, xml_xfce):
- self.joinDoc(xml_xfceObj.doc)
+ try:
+ self.joinDoc(xml_xfceObj.doc)
+ except:
+ self.setError(_("Can not join profile"))
+ return False
+ return True
def _removeDropNodesAndAttrAction(self, xmlNode):
"""Удаляет ноды с аттрибутом action='drop'
@@ -5362,4 +5362,177 @@ class squid(procmail):
if isinstance(squidObj, squid):
print squidObj.doc.toprettyxml()
#print squidObj.getConfig()
- self.docObj.joinDoc(squidObj.doc)
\ No newline at end of file
+ self.docObj.joinDoc(squidObj.doc)
+
+class xml_xfcepanel(xml_xfce):
+ """Класс для объединения xfce-panel файлов"""
+ def __init__(self, text):
+ xml_xfce.__init__(self, text)
+ self.panelNumbers = {}
+
+ def textToXML(self):
+ """Создание из текста XML документа
+ Храним xml в своем формате
+ """
+ if not self.text.strip():
+ self.text = '''
+
+
+'''
+ try:
+ self.doc = xml.dom.minidom.parseString(self.text)
+ except:
+ self.setError(_("Can not text profile is XML"))
+ return False
+ self.rootNode = self.doc.documentElement
+ self.bodyNode = self.rootNode
+ return self.doc
+
+ def setNameBodyNode(self, name):
+ """Пустой метод"""
+ return True
+
+ def _join(self, xmlNewNode, xmlOldNode, flagRootNode=True, levelNumber=0):
+ """Объединение корневой ноды профиля и корненвой ноды файла"""
+ xmlNode = xmlNewNode
+ childNodes = xmlNode.childNodes
+ nextOldNode = xmlOldNode
+ flagError = False
+ if xmlNode.nodeType ==xmlNode.ELEMENT_NODE:
+ n = xmlNode
+ path = u''
+ nName = u''
+ flagArray = False
+ nValue = u''
+ nAction = u''
+ attrName = ''
+ attrType = ''
+ path = n.tagName
+ if path == "items":
+ flagArray = True
+ if not flagArray:
+ if n.hasAttribute("name"):
+ nName = n.getAttribute("name")
+ attrName = u"attribute::name='%s'"%nName
+ if n.hasAttribute("value"):
+ nValue = n.getAttribute("value")
+ if n.hasAttribute("action"):
+ nAction = n.getAttribute("action")
+ if not nAction in ("join","replace","drop"):
+ textError = _('''In the text, XML profile, look \
+for a reserved attribute 'action' with the incorrect value.\n\
+Valid values attribute 'action': \
+(action="join", action="replace", action="drop")''')
+ self.setError(textError)
+ return False
+ if xmlOldNode.parentNode:
+ findStr = u"child::%s"%path
+ findAttrStr = ""
+ if attrName:
+ findAttrStr = "[%s]"%attrName
+ findPath = u"child::%s%s"%(path,findAttrStr)
+ # Рабочая нода
+ if flagRootNode:
+ workNode = xmlOldNode.parentNode
+ else:
+ workNode = xmlOldNode
+ oldNodes = xpath.Evaluate(findPath, workNode)
+ flagDrop = False
+ flagJoin = True
+ flagReplace = False
+ flagAppend = False
+ if nAction == "replace":
+ flagJoin = False
+ flagReplace = True
+ elif nAction == "drop":
+ flagJoin = False
+ flagDrop = True
+ if flagRootNode:
+ textError = _('Incorrect action="drop" in root node')
+ self.setError(textError)
+ return False
+ if path == "panel":
+ flagJoin = False
+ if levelNumber in self.panelNumbers.keys():
+ self.panelNumbers[levelNumber] += 1
+ else:
+ self.panelNumbers[levelNumber] = 0
+ if oldNodes:
+ if len(oldNodes)>1 and path != "panel":
+ textError = _("The uncertainty in this profile are \
+the same nodes at one level")
+ self.setError(textError)
+ return False
+ if path == "panel":
+ if len(oldNodes)<=self.panelNumbers[levelNumber]:
+ nextOldNode = oldNodes[-1]
+ # Добавляем ноду
+ if not flagDrop:
+ flagAppend = True
+ flagReplace = False
+ childNodes = False
+ else:
+ nextOldNode=oldNodes[self.panelNumbers[levelNumber]]
+ else:
+ nextOldNode = oldNodes[0]
+ # Замещаем ноду в случае массива
+ if flagArray and not flagDrop:
+ replaceXmlNode = xmlNode.cloneNode(True)
+ if nAction:
+ replaceXmlNode.removeAttribute("action")
+ workNode.replaceChild(replaceXmlNode,
+ nextOldNode)
+ flagJoin = False
+ flagReplace = False
+ childNodes = False
+ # Объединение нод
+ if flagJoin:
+ if nextOldNode.hasAttribute("value"):
+ oValue = nextOldNode.getAttribute("value")
+ if nValue != oValue:
+ nextOldNode.setAttribute("value",nValue)
+ # Замещение ноды
+ elif flagReplace:
+ replaceXmlNode = xmlNode.cloneNode(True)
+ if not\
+ self._removeDropNodesAndAttrAction(replaceXmlNode):
+ return False
+ workNode.replaceChild(replaceXmlNode,
+ nextOldNode)
+ childNodes = False
+ # Удаление ноды
+ elif flagDrop:
+ workNode.removeChild(nextOldNode)
+ childNodes = False
+ else:
+ flagAppend = True
+ flagDrop = False
+ if flagAppend and not flagDrop:
+ # Добавление ноды
+ childNodes = False
+ if not flagDrop:
+ appendXmlNode = xmlNode.cloneNode(True)
+ if not\
+ self._removeDropNodesAndAttrAction(appendXmlNode):
+ return False
+ workNode.appendChild(appendXmlNode)
+ if childNodes:
+ for node in childNodes:
+ levelNumber +=1
+ if not self._join(node, nextOldNode, False, levelNumber):
+ flagError = True
+ break
+ levelNumber -= 1
+ if flagError:
+ return False
+ return True
+
+ def join(self, xml_xfceObj):
+ """Объединяем конфигурации"""
+ if isinstance(xml_xfceObj, xml_xfcepanel):
+ try:
+ self.joinDoc(xml_xfceObj.doc)
+ except:
+ self.setError(_("Can not join profile"))
+ return False
+ return True
\ No newline at end of file