|
|
@ -2988,7 +2988,7 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
newFile)
|
|
|
|
newFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
if objHeadNew.fileType == "xml_xfce":
|
|
|
|
if "xml_" in objHeadNew.fileType:
|
|
|
|
if objProfNew.getError():
|
|
|
|
if objProfNew.getError():
|
|
|
|
self.setError (_("False profile: " ) + newFile)
|
|
|
|
self.setError (_("False profile: " ) + newFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -3017,7 +3017,7 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
title = title.encode("UTF-8")
|
|
|
|
title = title.encode("UTF-8")
|
|
|
|
# Замена
|
|
|
|
# Замена
|
|
|
|
if objHeadNew.typeAppend == "replace":
|
|
|
|
if objHeadNew.typeAppend == "replace":
|
|
|
|
if objHeadNew.fileType == "xml_xfce":
|
|
|
|
if "xml_" in objHeadNew.fileType:
|
|
|
|
data = self.newProfile.split("\n")
|
|
|
|
data = self.newProfile.split("\n")
|
|
|
|
data.insert(1,title)
|
|
|
|
data.insert(1,title)
|
|
|
|
self.oldProfile = "\n".join(data)
|
|
|
|
self.oldProfile = "\n".join(data)
|
|
|
@ -3031,7 +3031,7 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
return filesApply
|
|
|
|
return filesApply
|
|
|
|
# Впереди
|
|
|
|
# Впереди
|
|
|
|
elif objHeadNew.typeAppend == "before":
|
|
|
|
elif objHeadNew.typeAppend == "before":
|
|
|
|
if objHeadNew.fileType == "xml_xfce":
|
|
|
|
if "xml_" in objHeadNew.fileType:
|
|
|
|
self.setError (\
|
|
|
|
self.setError (\
|
|
|
|
_("False option append=before in profile %s") %newFile)
|
|
|
|
_("False option append=before in profile %s") %newFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -3053,7 +3053,7 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
return filesApply
|
|
|
|
return filesApply
|
|
|
|
# Cзади
|
|
|
|
# Cзади
|
|
|
|
elif objHeadNew.typeAppend == "after":
|
|
|
|
elif objHeadNew.typeAppend == "after":
|
|
|
|
if objHeadNew.fileType == "xml_xfce":
|
|
|
|
if "xml_" in objHeadNew.fileType:
|
|
|
|
self.setError (\
|
|
|
|
self.setError (\
|
|
|
|
_("False option append=after in profile %s") %newFile)
|
|
|
|
_("False option append=after in profile %s") %newFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -3093,7 +3093,7 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
+ objHeadNew.fileType + " : " +\
|
|
|
|
+ objHeadNew.fileType + " : " +\
|
|
|
|
newFile)
|
|
|
|
newFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
if objHeadNew.fileType == "xml_xfce":
|
|
|
|
if "xml_" in objHeadNew.fileType:
|
|
|
|
if objProfNew.getError():
|
|
|
|
if objProfNew.getError():
|
|
|
|
self.setError (_("False profile: " ) + newFile)
|
|
|
|
self.setError (_("False profile: " ) + newFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -3135,7 +3135,7 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
exec ("objProfOld=%s(self.oldProfile)"%\
|
|
|
|
exec ("objProfOld=%s(self.oldProfile)"%\
|
|
|
|
(objHeadNew.fileType))
|
|
|
|
(objHeadNew.fileType))
|
|
|
|
if objHeadNew.fileType == "xml_xfce":
|
|
|
|
if "xml_" in objHeadNew.fileType:
|
|
|
|
if objProfOld.getError():
|
|
|
|
if objProfOld.getError():
|
|
|
|
self.setError (_("False profile: " ) + oldFile)
|
|
|
|
self.setError (_("False profile: " ) + oldFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -3145,12 +3145,9 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
#print "#%s#" %(objProfOld.docObj.body.toprettyxml())
|
|
|
|
#print "#%s#" %(objProfOld.docObj.body.toprettyxml())
|
|
|
|
#print "#%s#" %(objProfNew.docObj.body.toprettyxml())
|
|
|
|
#print "#%s#" %(objProfNew.docObj.body.toprettyxml())
|
|
|
|
objProfOld.join(objProfNew)
|
|
|
|
objProfOld.join(objProfNew)
|
|
|
|
#if objHeadNew.fileType=="xml_xfce":
|
|
|
|
|
|
|
|
#print "OLD"
|
|
|
|
|
|
|
|
#print "New"
|
|
|
|
|
|
|
|
#print objProfOld.doc.toprettyxml()
|
|
|
|
#print objProfOld.doc.toprettyxml()
|
|
|
|
#print objProfNew.doc.toprettyxml()
|
|
|
|
#print objProfNew.doc.toprettyxml()
|
|
|
|
if objHeadNew.fileType == "xml_xfce":
|
|
|
|
if "xml_" in objHeadNew.fileType:
|
|
|
|
if objProfOld.getError():
|
|
|
|
if objProfOld.getError():
|
|
|
|
self.setError (_("False profile: " ) + newFile)
|
|
|
|
self.setError (_("False profile: " ) + newFile)
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -5100,8 +5097,6 @@ class xml_xfce(_error):
|
|
|
|
self.text = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
self.text = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<channel version="1.0">
|
|
|
|
<channel version="1.0">
|
|
|
|
</channel>'''
|
|
|
|
</channel>'''
|
|
|
|
if hasattr(self, "objVar"):
|
|
|
|
|
|
|
|
print self.objVar.Get("cl_pass_file")
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.doc = xml.dom.minidom.parseString(self.text)
|
|
|
|
self.doc = xml.dom.minidom.parseString(self.text)
|
|
|
|
except:
|
|
|
|
except:
|
|
|
@ -5114,7 +5109,12 @@ class xml_xfce(_error):
|
|
|
|
def join(self, xml_xfceObj):
|
|
|
|
def join(self, xml_xfceObj):
|
|
|
|
"""Объединяем конфигурации"""
|
|
|
|
"""Объединяем конфигурации"""
|
|
|
|
if isinstance(xml_xfceObj, xml_xfce):
|
|
|
|
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):
|
|
|
|
def _removeDropNodesAndAttrAction(self, xmlNode):
|
|
|
|
"""Удаляет ноды с аттрибутом action='drop'
|
|
|
|
"""Удаляет ноды с аттрибутом action='drop'
|
|
|
@ -5363,3 +5363,176 @@ class squid(procmail):
|
|
|
|
print squidObj.doc.toprettyxml()
|
|
|
|
print squidObj.doc.toprettyxml()
|
|
|
|
#print squidObj.getConfig()
|
|
|
|
#print squidObj.getConfig()
|
|
|
|
self.docObj.joinDoc(squidObj.doc)
|
|
|
|
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 = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
|
|
|
<!DOCTYPE config SYSTEM "config.dtd">
|
|
|
|
|
|
|
|
<panels>
|
|
|
|
|
|
|
|
</panels>'''
|
|
|
|
|
|
|
|
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
|