develop
asamoukin 16 years ago
parent df2a723092
commit 6756cdbffe

@ -4092,6 +4092,118 @@ class kde(samba):
self.docObj.joinDoc(kdeObj.doc)
self.postXML()
class xmlDocPlasma:
"""Класс для замены метода joinArea в xmlDoc для plasma"""
# заменяемый метод для xmlDoc
def joinArea(self, baseNode, xmlNewArea):
"""Объединяет область c областью Body (xmlNewArea c baseNode)"""
def appendArea(baseNode, xmlNewArea):
fieldsRemove = xpath.Evaluate(\
"descendant::field[child::action='drop']", xmlNewArea)
for rmNode in fieldsRemove:
parentNode = rmNode.parentNode
parentNode.removeChild(rmNode)
captionAreasRemove = xpath.Evaluate(\
"descendant::area/child::caption[child::action='drop']",
xmlNewArea)
for rmNodeCapt in captionAreasRemove:
rmNode = rmNodeCapt.parentNode
parentNode = rmNode.parentNode
parentNode.removeChild(rmNode)
self.setActionArea(xmlNewArea, "append")
# Добавляем разделитель областей во вложенные области
areaNodes = xpath.Evaluate('descendant::area',xmlNewArea)
for areaNode in areaNodes:
self.setActionArea(areaNode,"append")
parentNode = areaNode.parentNode
parentNode.insertBefore(self.sepAreas.cloneNode(True),
areaNode)
baseNode.appendChild(xmlNewArea)
# Добавляем разделитель областей
baseNode.insertBefore(self.sepAreas.cloneNode(True), xmlNewArea)
nodesNames = xpath.Evaluate('child::area/caption/name',baseNode)
nodesNewArea = xpath.Evaluate('child::caption/name',xmlNewArea)
if not nodesNames:
# Добавляем область
if nodesNewArea:
newAreaAction = self.getActionArea(xmlNewArea)
if not (newAreaAction == "drop" or newAreaAction == "replace"):
appendArea(baseNode, xmlNewArea)
return True
if not nodesNames or not nodesNewArea:
return False
nameArea = ""
if nodesNewArea[0].firstChild:
nameArea = nodesNewArea[0].firstChild.nodeValue.strip()
flagFindArea = False
baseNodes = []
for oName in nodesNames:
newAreaAction = self.getActionArea(xmlNewArea)
oArea = oName.parentNode.parentNode
oNameTxt = ""
if oName.firstChild:
oNameTxt = oName.firstChild.nodeValue
if nameArea == oNameTxt:
flagFindArea = True
# При использовании удаления
if newAreaAction == "drop":
prevNode = oName.parentNode.parentNode.previousSibling
removePrevNodes = []
while (prevNode) and self.getTypeField(prevNode) == "br":
removePrevNodes.append(prevNode)
prevNode = prevNode.previousSibling
for removeNode in removePrevNodes:
baseNode.removeChild(removeNode)
baseNode.removeChild(oName.parentNode.parentNode)
continue
elif newAreaAction == "replace":
oldAreaNode = oName.parentNode.parentNode
newAreaCaption = xpath.Evaluate('child::caption',
xmlNewArea)[0]
oldAreaCaption = xpath.Evaluate('child::caption',
oldAreaNode)[0]
if newAreaCaption and oldAreaCaption:
xmlNewArea.replaceChild(oldAreaCaption,newAreaCaption)
self.setActionArea(xmlNewArea,"replace")
baseNode.replaceChild(xmlNewArea,
oldAreaNode)
continue
baseNodes.append(oName.parentNode.parentNode)
# Заменяем QUOTE
oldAreaNode = oName.parentNode.parentNode
oldAreaQuote = xpath.Evaluate('child::caption/quote',
oldAreaNode)[0]
if oldAreaQuote and\
not oldAreaQuote.firstChild:
newAreaQuote = xpath.Evaluate('child::caption/quote',
xmlNewArea)[0]
oldAreaCaption = xpath.Evaluate('child::caption',
oldAreaNode)[0]
if newAreaQuote and oldAreaCaption:
oldAreaCaption.replaceChild(newAreaQuote, oldAreaQuote)
newFields = xpath.Evaluate('child::field',xmlNewArea)
joinNewFields = xpath.Evaluate(\
"child::field[child::action='join']"
,xmlNewArea)
self.addNewFielsOldArea(newFields, joinNewFields, oArea)
if not flagFindArea:
# Добавляем область
if not (newAreaAction == "drop" or\
newAreaAction == "replace"):
appendArea(baseNode, xmlNewArea)
else:
tmpXmlNewAreas = xpath.Evaluate('child::area',xmlNewArea)
for na in tmpXmlNewAreas:
for bn in baseNodes:
self.joinArea(bn, na)
return True
class plasma(samba):
"""Класс для обработки конфигурационного файла типа kde
@ -4109,7 +4221,6 @@ class plasma(samba):
def __init__(self,text):
samba.__init__(self,text)
# Делим текст на области включая вложенные (areas массив областей)
def splitToAllArea(self, text, areas):
"""Делит текст на области включая вложенные
@ -4190,8 +4301,13 @@ class plasma(samba):
findArea = findPathArea(copy.copy(namesBlock), areas)
namesBlockList.append(namesBlock)
if findArea:
if len(namesBlock) > 1:
namesBlockView = map(lambda x: self.removeSymbolTerm(x),
namesBlock)
else:
namesBlockView = namesBlock
findArea.start = indentionLeft + "[" + \
"][".join(namesBlock) + "]"
"][".join(namesBlockView) + "]"
else:
i = 0
lenNamesBlock = len(namesBlock)
@ -4204,8 +4320,14 @@ class plasma(samba):
areaNew = area()
areaNew.header = nameB
if lenNamesBlock == i:
if len(namesBlock) > 1:
namesBlockView = map(\
lambda x: self.removeSymbolTerm(x),
namesBlock)
else:
namesBlockView = namesBlock
areaNew.start = indentionLeft + "[" + \
"][".join(namesBlock) + "]"
"][".join(namesBlockView) + "]"
else:
areaNew.start = ""
areaNew.end = ""
@ -4415,7 +4537,11 @@ class plasma(samba):
areas = []
if self.text.strip():
self.splitToAllArea(self.text, areas)
docObj = xmlDoc()
#docObj = xmlDoc()
# Создаем новый класс xmlDoc с измененным методом joinArea
newClass = type("newXmlDocPlalma",(xmlDocPlasma,xmlDoc,object),{})
# Создаем экземпляр нового класса
docObj = newClass()
# Создание объекта документ c пустым разделителем между полями
docObj.createDoc(self.configName, self.configVersion)
if not areas:
@ -4444,19 +4570,30 @@ class plasma(samba):
xmlAreas = xpath.Evaluate("descendant::area", self.docObj.body)
#print "-------------------------------------------------------"
#print xmlAreas
if xmlAreas:
prXmlArea = xmlAreas[0]
#if xmlAreas:
#prXmlArea = xmlAreas[0]
for xmlArea in xmlAreas:
#firstArea = False
#xmlFields = xpath.Evaluate("child::field", xmlArea)
#if not (xmlFields and\
#(self.docObj.getTypeField(xmlFields[0]) == "br" or\
#self.docObj.getTypeField(xmlFields[0]) == "comment")):
#xmlArea.insertBefore(self.docObj.createField("br",
#[],"",[],
#False,False),
#xmlFields[0])
# Перед пустой областью и после нее удаляем переводы строк
if getQuotesArea(xmlArea) == ["",""]:
#areaTXT = xpath.Evaluate("child::caption/name", xmlArea)[0]
#print "CL_AREA", areaTXT.firstChild
if xmlArea.previousSibling and\
self.docObj.getTypeField(xmlArea.previousSibling) == "br":
parentNode = xmlArea.previousSibling.parentNode
if xmlArea.previousSibling.previousSibling and\
self.docObj.getTypeField(xmlArea.previousSibling.previousSibling) == "br":
parentNode.removeChild(\
xmlArea.previousSibling.previousSibling)
parentNode.removeChild(xmlArea.previousSibling)
if xmlArea.nextSibling and\
self.docObj.getTypeField(xmlArea.nextSibling) == "br":
parentNode = xmlArea.nextSibling.parentNode
if xmlArea.nextSibling.nextSibling and\
self.docObj.getTypeField(xmlArea.nextSibling.nextSibling) == "br":
parentNode.removeChild(xmlArea.nextSibling.nextSibling)
parentNode.removeChild(xmlArea.nextSibling)
continue
# Собираем поля в кучку
xmlChildAreas = xpath.Evaluate("child::area", xmlArea)
if xmlChildAreas:
@ -4468,7 +4605,6 @@ class plasma(samba):
if self.docObj.getTypeField(\
firstChildArea.previousSibling.previousSibling)=="br":
firstChildArea = firstChildArea.previousSibling
flagFoundArea = False
it = 0
lenChild = len(childNodes)
@ -4485,68 +4621,57 @@ class plasma(samba):
"br":
xmlArea.insertBefore(childNodes[it],
firstChildArea)
xmlArea.insertBefore(\
self.docObj.createField("br",
[],"",[],
False,False),
firstChildArea)
else:
xmlArea.insertBefore(\
self.docObj.createField("br",
# Добавляем BR если его нет первым полем
xmlFields = xpath.Evaluate("child::field", xmlArea)
if not (xmlFields and\
(self.docObj.getTypeField(xmlFields[0]) == "br" or\
self.docObj.getTypeField(xmlFields[0]) == "comment")):
if xmlFields:
xmlArea.insertBefore(self.docObj.createField("br",
[],"",[],
False,False),
firstChildArea)
#continue
if getQuotesArea(xmlArea) == ["",""]:
if xmlArea.previousSibling:
if self.docObj.getTypeField(xmlArea.previousSibling)=="br":
parentNode = xmlArea.parentNode
parentNode.removeChild(xmlArea.previousSibling)
continue
if not xmlArea.previousSibling:
if not xmlArea.nextSibling:
xmlFields[0])
if xmlFields and self.docObj.getTypeField(xmlFields[-1]) == "br":
#print "DEL_BR", xmlFields[-1].nextSibling
#and\
if not xmlFields[-1].nextSibling:
xmlArea.removeChild(xmlFields[-1])
if xmlArea.previousSibling and\
not (self.docObj.getTypeField(xmlArea.previousSibling) == "br" or\
self.docObj.getTypeField(xmlArea.previousSibling) == "comment"):
parentNode = xmlArea.parentNode
parentNode.insertBefore(self.docObj.createField("br",
[],"",[],
False,False),
xmlArea)
# Если есть предыдущее поле, и поле предыдущеее предыдущему
# не равно BR
if xmlArea.previousSibling:
prPrSibling = xmlArea.previousSibling.previousSibling
if prPrSibling and\
not (self.docObj.getTypeField(prPrSibling) == "br" or\
self.docObj.getTypeField(prPrSibling) == "comment"):
parentNode = xmlArea.parentNode
nextNode = xmlArea.nextSibling
parentNode.insertBefore(self.docObj.createField("br",
[],"",[],
False,False),
nextNode)
#else:
#addBr = False
#prSibling = xmlArea.previousSibling
#if xmlArea.previousSibling.tagName == "area":
#xmlFields = xpath.Evaluate("child::field",
#xmlArea.previousSibling)
#if not (xmlFields and\
#(self.docObj.getTypeField(xmlFields[-1]) == "br" or\
#self.docObj.getTypeField(xmlFields[-1]) == "comment")):
#if xmlArea.nextSibling:
#parentNode = xmlArea.parentNode
#nextNode = xmlArea.nextSibling
#parentNode.insertBefore(self.docObj.createField("br",
#[],"",[],
#False,False),
#nextNode)
#addBr = True
#if addBr:
#print "ADD_BR"
#prPrSibling = xmlArea.previousSibling.previousSibling
#print prPrSibling.tagName
#if self.docObj.getTypeField(prSibling) == "br":
#if not self.docObj.getTypeField(prPrSibling) == "br":
#parentNode = xmlArea.parentNode
#parentNode.insertBefore(self.docObj.createField("br",
#[],"",[],
#False,False),
#xmlArea)
#else:
#parentNode = xmlArea.parentNode
#parentNode.insertBefore(self.docObj.createField("br",
#[],"",[],
#False,False),
#xmlArea)
#prXmlArea = xmlArea
[],"",[],
False,False),
xmlArea)
if xmlArea.nextSibling and\
self.docObj.getTypeField(xmlArea.nextSibling) == "br":
if not xmlArea.nextSibling.nextSibling:
parentNode = xmlArea.nextSibling.parentNode
parentNode.removeChild(xmlArea.nextSibling)
#xmlName = xpath.Evaluate("child::caption/name", xmlArea)[0]
#print "------------------------------------"
#print "Name =", xmlName.firstChild
#if xmlArea.previousSibling:
#print "PR_TYPE =", self.docObj.getTypeField(xmlArea.previousSibling)
def join(self, kdeObj):
"""Объединяем конфигурации"""

Loading…
Cancel
Save