|
|
|
@ -1657,6 +1657,37 @@ 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):
|
|
|
|
|
"""Класс для работы с профилями
|
|
|
|
|
|
|
|
|
@ -1666,6 +1697,8 @@ class profile(_file, _terms):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self, objVar, servDir=False):
|
|
|
|
|
_file.__init__(self)
|
|
|
|
|
# Словарь для создания новых классов по образцу
|
|
|
|
|
self.dncp = {'proftpd':(apache,),}
|
|
|
|
|
# Заголовок title
|
|
|
|
|
self.__titleHead = "--------------------------------------\
|
|
|
|
|
----------------------------------------"
|
|
|
|
@ -1932,6 +1965,30 @@ class profile(_file, _terms):
|
|
|
|
|
os.symlink(oldFile, prevOldFile)
|
|
|
|
|
return objHeadNew
|
|
|
|
|
|
|
|
|
|
def createNewClassObj(self, name, bases, attrs={}):
|
|
|
|
|
"""Создает объект нового класса
|
|
|
|
|
|
|
|
|
|
createNewClassObj(self, name, bases, attrs)
|
|
|
|
|
name - имя класса - str,
|
|
|
|
|
bases - cписок наследуемых классов - (typle),
|
|
|
|
|
attrs - аттрибуты класса - {dict}
|
|
|
|
|
"""
|
|
|
|
|
class newMethod:
|
|
|
|
|
#Объединяем конфигурации
|
|
|
|
|
def join(self, newObj):
|
|
|
|
|
if newObj.__class__.__name__ == self.__class__.__name__:
|
|
|
|
|
self.docObj.joinDoc(newObj.doc)
|
|
|
|
|
attrsNew = {}
|
|
|
|
|
attrsNew["configName"] = self.__class__.__name__
|
|
|
|
|
if attrs:
|
|
|
|
|
for key in attrs.keys():
|
|
|
|
|
attrsNew[key] = attrs[key]
|
|
|
|
|
|
|
|
|
|
newObj = genClass(name, (newMethod,)+bases, attrs)
|
|
|
|
|
return newObj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def join(self, newFile, oldFile, ListOptTitle):
|
|
|
|
|
"""Объединения профиля и конф. файла
|
|
|
|
|
|
|
|
|
@ -2013,10 +2070,17 @@ class profile(_file, _terms):
|
|
|
|
|
exec ("objProfNew=%s(self.newProfile)"%\
|
|
|
|
|
(objHeadNew.fileType))
|
|
|
|
|
except NameError:
|
|
|
|
|
self.setError (_("False join profile for type profile: " )\
|
|
|
|
|
if self.dncp.has_key(objHeadNew.fileType):
|
|
|
|
|
objProfNew = self.createNewClassObj(\
|
|
|
|
|
objHeadNew.fileType,
|
|
|
|
|
self.dncp[objHeadNew.fileType])
|
|
|
|
|
objProfNew.run(self.newProfile)
|
|
|
|
|
else:
|
|
|
|
|
self.setError (\
|
|
|
|
|
_("False join profile for type profile: ")\
|
|
|
|
|
+ objHeadNew.fileType + " : " +\
|
|
|
|
|
newFile)
|
|
|
|
|
return False
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# Титл для объединения
|
|
|
|
|
if ListOptTitle:
|
|
|
|
@ -2041,7 +2105,13 @@ class profile(_file, _terms):
|
|
|
|
|
self.oldProfile = objHeadOld.body
|
|
|
|
|
else:
|
|
|
|
|
self.oldProfile = ""
|
|
|
|
|
exec ("objProfOld=%s(self.oldProfile)"%\
|
|
|
|
|
if self.dncp.has_key(objHeadNew.fileType):
|
|
|
|
|
objProfOld = self.createNewClassObj(\
|
|
|
|
|
objHeadNew.fileType,
|
|
|
|
|
self.dncp[objHeadNew.fileType])
|
|
|
|
|
objProfOld.run(self.oldProfile)
|
|
|
|
|
else:
|
|
|
|
|
exec ("objProfOld=%s(self.oldProfile)"%\
|
|
|
|
|
(objHeadNew.fileType))
|
|
|
|
|
|
|
|
|
|
#print "#%s#" %(objProfOld.docObj.body.toprettyxml())
|
|
|
|
@ -2892,14 +2962,14 @@ class postfix(apache):
|
|
|
|
|
return fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class proftpd(apache):
|
|
|
|
|
"""Класс для обработки конфигурационного файла типа proftpd
|
|
|
|
|
#class proftpd(apache):
|
|
|
|
|
#"""Класс для обработки конфигурационного файла типа proftpd
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
configName = "proftpd"
|
|
|
|
|
configVersion = "0.1"
|
|
|
|
|
#"""
|
|
|
|
|
#configName = "proftpd"
|
|
|
|
|
#configVersion = "0.1"
|
|
|
|
|
|
|
|
|
|
def join(self, namedObj):
|
|
|
|
|
"""Объединяем конфигурации"""
|
|
|
|
|
if isinstance(namedObj, proftpd):
|
|
|
|
|
self.docObj.joinDoc(namedObj.doc)
|
|
|
|
|
#def join(self, namedObj):
|
|
|
|
|
#"""Объединяем конфигурации"""
|
|
|
|
|
#if isinstance(namedObj, proftpd):
|
|
|
|
|
#self.docObj.joinDoc(namedObj.doc)
|