Changed algorithm of the synchronization user profile.

master3.3
Самоукин Алексей 14 years ago
parent 29ce02910a
commit d9a965701d

@ -751,7 +751,46 @@ class client(share, commandServer, encrypt):
stdin.close()
os.close(fd)
def unpackTemplate(self, homeDir, archFile, progress=False,\
def moveArch(self, srcArchFile, dstArchFile, progress=False,\
remoteServer=False):
"""Перенос архива из одной директории в другую"""
class copyTo(color_print):
def __init__(self, destFile):
self.FD = open(destFile, "w")
def write(self, data):
self.FD.write(data)
def close(self):
self.FD.close()
# Создаем прогрессбар
if progress:
title = _("Copying archive from server")
if remoteServer:
title += " " + remoteServer
title += " ..."
progressObj = ProgressBar(title)
archiveSize = os.stat(srcArchFile).st_size
progressObj.setMaximum(archiveSize)
try:
copyToObj = copyTo(dstArchFile)
except:
self.printERROR(_("Can not create file '%s'")%dstArchFile)
return False
# Копирование файла
try:
if progress:
self.fileReader(srcArchFile, copyToObj, progressObj)
else:
self.fileReader(srcArchFile, copyToObj)
except:
self.printERROR(_("Can not copy '%s' -> '%s'")\
%(srcArchFile, dstArchFile))
return False
if progress:
progressObj.shutdownDialog()
return True
def unpackArch(self, homeDir, archFile, progress=False,\
remoteServer=False):
"""Распаковка архива в домашнюю директорию пользователя"""
# Создаем прогрессбар
@ -878,14 +917,6 @@ class client(share, commandServer, encrypt):
self.printERROR(_("Can not found user %s")%userName)
self.umountUserRes()
return False
homeDir = pwdObj.pw_dir
uid = pwdObj.pw_uid
gid = pwdObj.pw_gid
configFileName = os.path.join(homeDir, self.configFileDesktop)
# записываем в конфигурационный файл статус "локальный режим"
# Write to the configuration file status of "local mode"
self.setVarToConfig("main", {"status_sync":"local"},
configFileName, uid, gid)
self.printWARNING(_("We use user information from /etc/passwd"))
return True
# Проверим что компьютер в домене и смонтирован [remote]
@ -968,6 +999,8 @@ class client(share, commandServer, encrypt):
dateDefaultTemplate = ""
# Текущее время
currTime = str(float(time.time()))
archPathSrc = ""
archPathDst = ""
# Создаваемые пути при монтировании
for name in names:
# Пропускаем монтирование директории если нет синхронизации
@ -1098,15 +1131,33 @@ class client(share, commandServer, encrypt):
flagIncrArch = False
break
else:
archPathSrc = archPathSuccess
archPathDst = ".".join(filter(lambda x: x!="/",
archPathSuccess.rpartition("/")))
# Копируем архив
if not self.moveArch(archPathSrc, archPathDst,
progress, remoteServer):
flagError = True
if archPathSrc:
# Удаление архивного файла
if os.path.exists(archPathSrc):
# Удаляем файл архива
os.remove(archPathSrc)
if archPathDst:
# Удаление архивного файла
if os.path.exists(archPathDst):
# Удаляем файл архива
os.remove(archPathDst)
break
# Распаковываем архив в домашнюю директорию
if not self.unpackTemplate(homeDir, archPathSuccess,
progress, remoteServer):
if not self.unpackArch(homeDir, archPathDst,
progress, remoteServer):
flagError = True
if archPathSuccess:
if archPathDst:
# Удаление архивного файла
if os.path.exists(archPathSuccess):
if os.path.exists(archPathDst):
# Удаляем файл архива
os.remove(archPathSuccess)
os.remove(archPathDst)
break
# Cканирование домашней директории и получение списка
# файлов
@ -1120,13 +1171,15 @@ class client(share, commandServer, encrypt):
else:
if name == "remote_profile":
flagIncrArch = False
if archPathProcess or archPathSuccess:
if archPathProcess or archPathSuccess or archPathSrc or archPathDst:
# Удаление архивных файлов
rmFiles = [archPathProcess, archPathSuccess]
rmFiles = [archPathProcess, archPathSuccess, archPathSrc,
archPathDst]
rmFiles = filter(lambda x: x, list(set(rmFiles)))
for rmFile in rmFiles:
if os.path.exists(rmFile):
# Удаляем файл архива
os.remove(archPathSuccess)
os.remove(rmFile)
# Если не удалось замонтировать удаленный профиль
if flagErrorMountRemote:
syncStatus = False
@ -1161,9 +1214,9 @@ class client(share, commandServer, encrypt):
return False
if not flagError and flagCopyPrivateFiles:
configFileName = os.path.join(homeDir, self.configFileDesktop)
# записываем в конфигурационный файл статус "локальный режим"
# Write to the configuration file status of "local mode"
self.setVarToConfig("main", {"status_sync":"local"},
# записываем в конфигурационный файл статус
# Write to the configuration file status
self.setVarToConfig("main", {"status_sync":"success"},
configFileName, uid, gid)
# Копируем приватные файлы с сервера
# Copy private files from the server
@ -1243,9 +1296,9 @@ class client(share, commandServer, encrypt):
return False
if not flagError and flagCopyPrivateFiles:
configFileName = os.path.join(homeDir, self.configFileDesktop)
# записываем в конфигурационный файл статус "локальный режим"
# Write to the configuration file status of "local mode"
self.setVarToConfig("main", {"status_sync":"local"},
# записываем в конфигурационный файл статус
# Write to the configuration file status
self.setVarToConfig("main", {"status_sync":"success"},
configFileName, uid, gid)
# Копируем приватные файлы с сервера
# Copy private files from the server

Loading…
Cancel
Save