|
|
|
@ -1745,7 +1745,7 @@ class _file(_error):
|
|
|
|
|
|
|
|
|
|
self.openNewFile = self.__openNewFile
|
|
|
|
|
self.absFileName = self.__absFileName
|
|
|
|
|
self.closeNewFile =self.__closeNewFile
|
|
|
|
|
self.closeNewFile = self.__closeNewFile
|
|
|
|
|
|
|
|
|
|
def getFileType(self, profile="New"):
|
|
|
|
|
"""выдать тип файла (text, bin)
|
|
|
|
@ -1759,14 +1759,18 @@ class _file(_error):
|
|
|
|
|
textLine = fout.readline()
|
|
|
|
|
fout.readlines()
|
|
|
|
|
fout.close()
|
|
|
|
|
retText = ""
|
|
|
|
|
if textLine:
|
|
|
|
|
listTextLine = textLine.split(":")
|
|
|
|
|
if len(listTextLine) == 2:
|
|
|
|
|
if "text" in listTextLine[1]:
|
|
|
|
|
return "text"
|
|
|
|
|
else:
|
|
|
|
|
return "bin"
|
|
|
|
|
return ""
|
|
|
|
|
textFormats = ["text", "XML"]
|
|
|
|
|
retText = "bin"
|
|
|
|
|
fileTypeString = listTextLine[1]
|
|
|
|
|
for textFormat in textFormats:
|
|
|
|
|
if textFormat in fileTypeString:
|
|
|
|
|
retText = "text"
|
|
|
|
|
break
|
|
|
|
|
return retText
|
|
|
|
|
|
|
|
|
|
def createDir(self, baseProfDir, profDir, baseDirMv):
|
|
|
|
|
"""Создает директорию
|
|
|
|
@ -4241,7 +4245,6 @@ class procmail(objShare):
|
|
|
|
|
def __init__(self, text):
|
|
|
|
|
self.text = text
|
|
|
|
|
self.docObj = self.textToXML()
|
|
|
|
|
# Создаем поля-массивы
|
|
|
|
|
self.doc = self.docObj.doc
|
|
|
|
|
|
|
|
|
|
def setDataField(self, txtLines, endtxtLines):
|
|
|
|
@ -5291,3 +5294,72 @@ the same nodes at one level")
|
|
|
|
|
data = self.doc.toprettyxml(encoding='UTF-8').split("\n")
|
|
|
|
|
data = filter(lambda x: x.strip(), data)
|
|
|
|
|
return "\n".join(data).replace("\t"," ").decode("UTF-8")
|
|
|
|
|
|
|
|
|
|
class squid(procmail):
|
|
|
|
|
"""Класс для обработки конфигурационного файла типа squid
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
configName = "squid"
|
|
|
|
|
configVersion = "0.1"
|
|
|
|
|
# разделитель названия и значения переменной
|
|
|
|
|
reSeparator = re.compile(" ")
|
|
|
|
|
|
|
|
|
|
def __init__(self, text):
|
|
|
|
|
procmail.__init__(self, text)
|
|
|
|
|
# Создаем поля-массивы
|
|
|
|
|
self.docObj.postParserList()
|
|
|
|
|
# Создаем поля разделенные массивы
|
|
|
|
|
self.docObj.postParserListSeplist(self.docObj.body)
|
|
|
|
|
|
|
|
|
|
def setDataField(self, txtLines, endtxtLines):
|
|
|
|
|
"""Создаем список объектов с переменными"""
|
|
|
|
|
class fieldData:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.name = False
|
|
|
|
|
self.value = False
|
|
|
|
|
self.comment = False
|
|
|
|
|
self.br = False
|
|
|
|
|
fields = []
|
|
|
|
|
field = fieldData()
|
|
|
|
|
z = 0
|
|
|
|
|
for k in txtLines:
|
|
|
|
|
textLine = k + endtxtLines[z]
|
|
|
|
|
z += 1
|
|
|
|
|
findComment = self.reComment.search(textLine)
|
|
|
|
|
flagVariable = True
|
|
|
|
|
if not textLine.strip():
|
|
|
|
|
field.br = textLine
|
|
|
|
|
fields.append(field)
|
|
|
|
|
field = fieldData()
|
|
|
|
|
flagVariable = False
|
|
|
|
|
elif findComment:
|
|
|
|
|
if textLine[:findComment.start()].strip():
|
|
|
|
|
field.comment = textLine[findComment.start():]
|
|
|
|
|
textLine = textLine[:findComment.start()]
|
|
|
|
|
else:
|
|
|
|
|
field.comment = textLine
|
|
|
|
|
flagVariable = False
|
|
|
|
|
fields.append(field)
|
|
|
|
|
field = fieldData()
|
|
|
|
|
if flagVariable:
|
|
|
|
|
pars = textLine.strip()
|
|
|
|
|
nameValue = self.reSeparator.split(pars)
|
|
|
|
|
if len(nameValue) > 2:
|
|
|
|
|
valueList = nameValue[1:]
|
|
|
|
|
nameValue =[nameValue[0]," ".join(valueList)]
|
|
|
|
|
if len(nameValue) == 2:
|
|
|
|
|
name = nameValue[0]
|
|
|
|
|
value = nameValue[1].replace(self.sepFields,"")
|
|
|
|
|
field.name = name.replace(" ","").replace("\t","")
|
|
|
|
|
field.value = value
|
|
|
|
|
field.br = textLine
|
|
|
|
|
fields.append(field)
|
|
|
|
|
field = fieldData()
|
|
|
|
|
return fields
|
|
|
|
|
|
|
|
|
|
def join(self, squidObj):
|
|
|
|
|
"""Объединяем конфигурации"""
|
|
|
|
|
if isinstance(squidObj, squid):
|
|
|
|
|
print squidObj.doc.toprettyxml()
|
|
|
|
|
#print squidObj.getConfig()
|
|
|
|
|
self.docObj.joinDoc(squidObj.doc)
|