diff --git a/pym/cl_profile.py b/pym/cl_profile.py index 26357a3..9b04621 100644 --- a/pym/cl_profile.py +++ b/pym/cl_profile.py @@ -205,7 +205,7 @@ class calcHeader(_terms): if fileType != False: if fileType=="bin": - self.params["type"] = fileType + self.params["format"] = fileType self.fileType = self._getType() self.typeAppend = self._getAppend() else: @@ -262,8 +262,8 @@ class calcHeader(_terms): def _getType(self): """Выдать тип файла""" - if self.params.has_key("type"): - return self.params["type"] + if self.params.has_key("format"): + return self.params["format"] else: return "raw" @@ -733,7 +733,7 @@ class xmlDoc: for newNode, nxtNode, app in insSplLst: flagCompareSeplist = False newValues = self.getFieldValues(newNode) - for nodeRepl, nxtNode in insNodesRepl: + for nodeRepl, nxtNode, app in insNodesRepl: oldValues = self.getFieldValues(nodeRepl) for newValue in newValues: if newValue in oldValues: @@ -766,9 +766,6 @@ class xmlDoc: xmlArea.replaceChild(xmlNewField.cloneNode(True), fieldsOldComp[-1]) - #print "-------------------------------------------------------" - #print "ACTION", newFieldsAction - #print xmlNewField.toprettyxml() if newFieldsAction == "join": fieldsOldRemove = [] else: @@ -1657,36 +1654,6 @@ class _file(_error): self.__closeNewFile() self.__closeOldFile() -class meta(type): - """Метакласс для новых генерируемых genClass классов""" - def __new__(cls, name, bases, dict): - return type.__new__(cls, name, bases, dict) - - def __setAtr(cls, name, bases, dict): - cls.__name__ = name - for cl in bases: - if cl.__dict__.has_key("__init__"): - # метод run необходимо запустить после создания объекта - cls.run = cl.__init__ - #print bases - #print "--------------------" - #cls.__bases__ - #print "####################" - if len(cls.__bases__) <2: - cls.__bases__ += bases - for key in dict.keys(): - setattr(cls, key, dict[key]) - - def __init__(cls, *args): - cls.__init__ = cls.__setAtr - - def __init__(cls, *args): - cls.__init__ = cls.__setAtr - -class genClass: - """Класс для генерирования новых классов""" - __metaclass__ = meta - class profile(_file, _terms): """Класс для работы с профилями @@ -1697,8 +1664,8 @@ class profile(_file, _terms): """ def __init__(self, objVar, servDir=False): _file.__init__(self) - # Словарь для создания новых классов по образцу - self.dncp = {'proftpd':(apache,),} + # Словарь для создания объектов новых классов по образцу + self.newObjProt = {'proftpd':(apache,),} # Заголовок title self.__titleHead = "--------------------------------------\ ----------------------------------------" @@ -1965,12 +1932,12 @@ class profile(_file, _terms): os.symlink(oldFile, prevOldFile) return objHeadNew - def createNewClassObj(self, name, bases, attrs={}): + def createNewClass(self, name, bases, attrs={}): """Создает объект нового класса - createNewClassObj(self, name, bases, attrs) + createNewClass(self, name, bases, attrs) name - имя класса - str, - bases - cписок наследуемых классов - (typle), + bases - cписок наследуемых классов - (tuple), attrs - аттрибуты класса - {dict} """ class newMethod: @@ -1979,13 +1946,12 @@ class profile(_file, _terms): if newObj.__class__.__name__ == self.__class__.__name__: self.docObj.joinDoc(newObj.doc) attrsNew = {} - attrsNew["configName"] = self.__class__.__name__ + attrsNew["configName"] = name if attrs: for key in attrs.keys(): attrsNew[key] = attrs[key] - - newObj = genClass(name, (newMethod,)+bases, attrs) - return newObj + newCl = type(name, bases + (newMethod, object,), attrsNew) + return newCl @@ -2070,11 +2036,13 @@ class profile(_file, _terms): exec ("objProfNew=%s(self.newProfile)"%\ (objHeadNew.fileType)) except NameError: - if self.dncp.has_key(objHeadNew.fileType): - objProfNew = self.createNewClassObj(\ - objHeadNew.fileType, - self.dncp[objHeadNew.fileType]) - objProfNew.run(self.newProfile) + #Создаем объект из self.newObjProt с помощью + # метаклассов + if self.newObjProt.has_key(objHeadNew.fileType): + objProfNewCl = self.createNewClass(\ + objHeadNew.fileType, + self.newObjProt[objHeadNew.fileType]) + objProfNew = objProfNewCl(self.newProfile) else: self.setError (\ _("False join profile for type profile: ")\ @@ -2092,24 +2060,26 @@ class profile(_file, _terms): reNoClean = re.compile("[^\s]",re.M) if not self.oldProfile or\ not reNoClean.search(self.oldProfile): - if objHeadNew.execStr: - self.oldProfile = objHeadNew.execStr + \ - title + self.newProfile - else: - self.oldProfile = title + self.newProfile - self.saveOldFile() - return True + self.oldProfile = "" + #if objHeadNew.execStr: + #self.oldProfile = objHeadNew.execStr + \ + #title + objProfNew.getConfig().encode("UTF-8") + #else: + #self.oldProfile = title +\ + #objProfNew.getConfig().encode("UTF-8") + #self.saveOldFile() + #return True objHeadOld = calcHeader(self.oldProfile, objProfNew._comment) if objHeadOld.body: self.oldProfile = objHeadOld.body else: self.oldProfile = "" - if self.dncp.has_key(objHeadNew.fileType): - objProfOld = self.createNewClassObj(\ - objHeadNew.fileType, - self.dncp[objHeadNew.fileType]) - objProfOld.run(self.oldProfile) + if self.newObjProt.has_key(objHeadNew.fileType): + objProfOldCl = self.createNewClass(\ + objHeadNew.fileType, + self.newObjProt[objHeadNew.fileType]) + objProfOld = objProfOldCl(self.oldProfile) else: exec ("objProfOld=%s(self.oldProfile)"%\ (objHeadNew.fileType)) @@ -2960,16 +2930,3 @@ class postfix(apache): fields.append(field) field = fieldData() return fields - - -#class proftpd(apache): - #"""Класс для обработки конфигурационного файла типа proftpd - - #""" - #configName = "proftpd" - #configVersion = "0.1" - - #def join(self, namedObj): - #"""Объединяем конфигурации""" - #if isinstance(namedObj, proftpd): - #self.docObj.joinDoc(namedObj.doc) \ No newline at end of file