|
|
|
@ -92,12 +92,9 @@ class share(color_print):
|
|
|
|
|
else:
|
|
|
|
|
return dirsFiles
|
|
|
|
|
|
|
|
|
|
def printVars(self, opts=["all"]):
|
|
|
|
|
def printVars(self, *arg, **argv):
|
|
|
|
|
"""Печать существующих переменных"""
|
|
|
|
|
if opts == ["all"]:
|
|
|
|
|
self.clVars.printVars()
|
|
|
|
|
else:
|
|
|
|
|
self.clVars.printVars(opts)
|
|
|
|
|
self.clVars.printVars(*arg, **argv)
|
|
|
|
|
|
|
|
|
|
class RsyncProgressBar:
|
|
|
|
|
'''Объект запуска rsync для получения количества созданных файлов и
|
|
|
|
@ -1040,7 +1037,7 @@ class client(share, commandServer, encrypt):
|
|
|
|
|
# файлов
|
|
|
|
|
pathListFile = os.path.join(homeTemplate,
|
|
|
|
|
self.listTemplFile)
|
|
|
|
|
if not self.removeFilesInTemplate(homeDir, pathListFile):
|
|
|
|
|
if not self.removeFilesInTemplate(homeDir,pathListFile):
|
|
|
|
|
# Отмонтируем пользовательские ресурсы в
|
|
|
|
|
# случае ошибки
|
|
|
|
|
self.umountUserRes(homeDir)
|
|
|
|
@ -1280,6 +1277,84 @@ class client(share, commandServer, encrypt):
|
|
|
|
|
os.remove(rmFile)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def scanDirectory(self, scanDir, listFiles, skipPath=[], prefix=False,
|
|
|
|
|
flagDir=False):
|
|
|
|
|
"""Генерация списка файлов и директорий"""
|
|
|
|
|
if not prefix:
|
|
|
|
|
prefix = os.path.join(scanDir,"")
|
|
|
|
|
if flagDir or stat.S_ISDIR(os.lstat(scanDir)[stat.ST_MODE]):
|
|
|
|
|
for fileOrDir in os.listdir(scanDir):
|
|
|
|
|
absPath = os.path.join(scanDir,fileOrDir)
|
|
|
|
|
relPath = absPath.split(prefix)[1]
|
|
|
|
|
if relPath in skipPath:
|
|
|
|
|
continue
|
|
|
|
|
listFiles.append(relPath)
|
|
|
|
|
stInfo = os.lstat(absPath)
|
|
|
|
|
statInfo = stInfo[stat.ST_MODE]
|
|
|
|
|
if stat.S_ISDIR(statInfo):
|
|
|
|
|
self.scanDirectory(absPath, listFiles,
|
|
|
|
|
skipPath, prefix, True)
|
|
|
|
|
|
|
|
|
|
def getListFilesTemplate(self, homeDir):
|
|
|
|
|
"""Генерация списка файлов в домашней директориии
|
|
|
|
|
|
|
|
|
|
Исключая монтируемые директории
|
|
|
|
|
"""
|
|
|
|
|
home = os.path.join(homeDir, "")
|
|
|
|
|
execStr = "mount"
|
|
|
|
|
textLines = self.execProg(execStr,False,False)
|
|
|
|
|
# Пропускаемые директории для сканирования
|
|
|
|
|
skipPaths = []
|
|
|
|
|
if textLines:
|
|
|
|
|
for line in textLines:
|
|
|
|
|
if home in line:
|
|
|
|
|
skipPath =\
|
|
|
|
|
line.partition(home)[2].rpartition(" type")[0]
|
|
|
|
|
skipPaths.append(skipPath)
|
|
|
|
|
# Список файлов в профиле пользователя
|
|
|
|
|
listFiles = []
|
|
|
|
|
if not skipPaths:
|
|
|
|
|
self.printERROR(_("Not found the mount point of server resources"))
|
|
|
|
|
return False
|
|
|
|
|
self.scanDirectory(homeDir, listFiles, skipPaths)
|
|
|
|
|
return listFiles
|
|
|
|
|
|
|
|
|
|
def removeFilesInTemplate(self, homeDir, pathListFile):
|
|
|
|
|
"""Удаляем файлы которых нет в профиле пользователя"""
|
|
|
|
|
# Получаем файлы профиля на сервере
|
|
|
|
|
try:
|
|
|
|
|
filesTemplateTxt = open(pathListFile).read()
|
|
|
|
|
except:
|
|
|
|
|
self.printERROR(_("Can not open %s")%pathListFile)
|
|
|
|
|
return False
|
|
|
|
|
listFilesTemplate = filter(lambda x: x.strip(),
|
|
|
|
|
filesTemplateTxt.split("\n"))
|
|
|
|
|
filesTemplate = set(listFilesTemplate)
|
|
|
|
|
# Получаем файлы в домашней директории
|
|
|
|
|
listFilesHome = self.getListFilesTemplate(homeDir)
|
|
|
|
|
if listFilesHome is False:
|
|
|
|
|
return False
|
|
|
|
|
filesHome = set(listFilesHome)
|
|
|
|
|
filesRemove = list(filesHome - filesTemplate)
|
|
|
|
|
filesRemove.sort(lambda x, y: cmp(len(y), len(x)))
|
|
|
|
|
|
|
|
|
|
rmPath = ""
|
|
|
|
|
try:
|
|
|
|
|
for rmFile in filesRemove:
|
|
|
|
|
rmPath = os.path.join(homeDir, rmFile)
|
|
|
|
|
if os.path.islink(rmPath):
|
|
|
|
|
os.unlink(rmPath)
|
|
|
|
|
elif os.path.isfile(rmPath):
|
|
|
|
|
os.remove(rmPath)
|
|
|
|
|
elif os.path.isdir(rmPath):
|
|
|
|
|
os.rmdir(rmPath)
|
|
|
|
|
else:
|
|
|
|
|
os.remove(rmPath)
|
|
|
|
|
except:
|
|
|
|
|
self.printERROR(_("Can nor remove %s")%rmPath)
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def clearUserKey(self, userName):
|
|
|
|
|
"""Очищает пользовательский ключ ядра"""
|
|
|
|
|
# Ищем ключ в ядре
|
|
|
|
|