develop
asamoukin 15 years ago
parent 75b24341c5
commit 5af79ac9ee

@ -6797,39 +6797,6 @@ Samba and Unix services") %", ".join(exclGroup)
self.printSUCCESS(_("Modified comment"))
return True
class filterProfiles(cl_profile.profile):
"""Класс для фильтрации налагаемых профилей"""
def __init__(self, objVar, servDir=False, dirsFilter=[],
filesFilter=[]):
self.dirsFilter = dirsFilter
self.filesFilter = filesFilter
cl_profile.profile.__init__(self, objVar, servDir)
def scanDirs(self, profilesDirs):
"""Измененный метод сканирования директорий"""
rez = cl_profile.profile.scanDirs(self, profilesDirs)
if rez and (self.dirsFilter or self.filesFilter):
for obj in rez:
dirs = []
dirsRel = []
for dirName in obj.dirs:
oldDir = dirName.partition(obj.baseDir)[2]
if not oldDir in self.dirsFilter:
dirs.append(dirName)
dirsRel.append(oldDir)
files = []
for fullFileName in obj.files:
oldFile = fullFileName.partition(obj.baseDir)[2]
dirName,fileName = os.path.split(oldFile)
if dirName in dirsRel:
fileName = fileName.split("?")[0]
oldFile = os.path.join(dirName, fileName)
if not oldFile in self.filesFilter:
files.append(fullFileName)
obj.dirs = dirs
obj.files = files
return rez
class servLdap(shareLdap):
"""Методы севисa Ldap"""
@ -6899,26 +6866,6 @@ class servLdap(shareLdap):
return False
return True
def getServiceSetupPathProfiles(self):
"""Находим пути к профилям установленных сервисов
Выдаем два списка ([пути к профилям сервисов],[установленные сервисы])
"""
servicePaths = []
servInstalled = []
# Инсталлированные сервисы
servInst = self.getServiceSetup()
# пути к директориям профилей
profilePaths = self.clVars.Get("cl_profile_path")
for profilePath in profilePaths:
for serv in servInst:
if self.clVars.Get("sr_%s_set"%serv) == "on":
servPath = os.path.join(profilePath,serv)
if os.path.exists(servPath):
servicePaths.append(servPath)
servInstalled.append(serv)
return (servicePaths, servInstalled)
def rebuildServer(self, options):
"""Перегенерирует конфигурационные файлы, и базу данных LDAP"""
bFile = self.getArchFile()
@ -7013,7 +6960,7 @@ outdated. If the backup is obsolete, use cl-backup."))
"""Применяем профили для данного сервиса"""
# Cоздаем объект профиль устанавливая директорию
# service для файлов профилей
clProf = filterProfiles(self.clVars,service, dirsFilter, filesFilter)
clProf = cl_profile.profile(self.clVars,service,dirsFilter,filesFilter)
# Объединяем профили
data = clProf.applyProfiles()
if clProf.getError():
@ -7393,23 +7340,12 @@ outdated. If the backup is obsolete, use cl-backup."))
def updateLdapServer(self, options, serviceUpdate):
"""Обновление сервисов"""
return self.updateServer(options ,serviceUpdate)
def scanServiceDirs(self, servicePaths):
"""Сканирует пути сервисов и выдает список файлов от корня"""
allArchFiles = []
fileObj = cl_profile._file()
dirObjs = fileObj.scanDirs(servicePaths)
i = 0
for dirObj in dirObjs:
for fileProfile in dirObj.files:
archFile = fileProfile.split(servicePaths[i])[1]
if "?" in archFile:
dirName, fileName = os.path.split(archFile)
fileName = fileName.split("?")[0]
archFile = os.path.join(dirName, fileName)
allArchFiles.append(archFile)
i += 1
return allArchFiles
def scanServiceDirs(self, serviceName):
"""На основании имени сервиса выдает список файлов от корня"""
clProf = cl_profile.profile(self.clVars)
return clProf.scanProfiles(serviceName)
def backupServer(self):
"""Сохраняет настройки установленных сервисов и базу LDAP"""
@ -7487,14 +7423,26 @@ outdated. If the backup is obsolete, use cl-backup."))
backupFile = "%s.tar.bz2" %strData
# если существуют удаляем файлы в /tmp
self.removeTmpFiles()
# находим пути к профилям установленных сервисов
servicePaths, servInstalled = self.getServiceSetupPathProfiles()
if not servicePaths:
# находим установленные сервисы
servInstalled = self.getServiceSetup()
if not servInstalled:
self.printERROR("unable to create a backup")
self.printERROR("Services are not installed")
return False
# Все файлы которые нужно заархивировать
allArchFiles = self.scanServiceDirs(servicePaths)
allArchFiles = []
flagError = False
for serviceName in servInstalled:
archFiles = self.scanServiceDirs(serviceName)
if archFiles == False:
flagError = True
break
allArchFiles += archFiles
if flagError:
self.printERROR("Error create list archive files")
return False
scanPrivDirs = []
# файлы в архиве для Unix
@ -7520,24 +7468,32 @@ outdated. If the backup is obsolete, use cl-backup."))
# В случае включения репликации
if replServices:
i = 0
serviceUnixPaths = []
serviceSambaPaths = []
serviceMailPaths = []
for service in servInstalled:
if service == "unix":
serviceUnixPaths.append(servicePaths[i])
archFiles = self.scanServiceDirs(service)
if archFiles == False:
flagError = True
break
# файлы в архиве для Unix
replArchFilesUnix = archFiles
elif service == "samba":
serviceSambaPaths.append(servicePaths[i])
archFiles = self.scanServiceDirs(service)
if archFiles == False:
flagError = True
break
# файлы в aрхиве для Samba
replArchFilesSamba = archFiles
if service == "mail":
serviceMailPaths.append(servicePaths[i])
i += 1
# файлы в архиве для Unix
replArchFilesUnix = self.scanServiceDirs(serviceUnixPaths)
# файлы в aрхиве для Samba
replArchFilesSamba = self.scanServiceDirs(serviceSambaPaths)
# файлы в aрхиве для Mail
replArchFilesMail = self.scanServiceDirs(serviceMailPaths)
archFiles = self.scanServiceDirs(service)
if archFiles == False:
flagError = True
break
# файлы в aрхиве для Mail
replArchFilesMail = archFiles
if flagError:
self.printERROR("Error create list archive files for \
service %s")%service
return False
# Cоздаем файловый объект
fileObj = cl_profile._file()
if "ldap" in servInstalled:
@ -7938,8 +7894,9 @@ the extension '.env'")%bFile)
self.clVars.Set("cl_env_path", envPaths, True)
# считаем переменные из ini файлов
self.clVars.flIniFile()
servicePaths, servInstalled = self.getServiceSetupPathProfiles()
if not servicePaths:
# Установленные сервисы
servInstalled = self.getServiceSetup()
if not servInstalled:
self.printERROR("Services are not installed in archive %s" %bFile)
return False
# Найдем сервисы которые нужно установить

Loading…
Cancel
Save