Modification of code to change the method runOsCommand().

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

@ -367,8 +367,8 @@ class client(share, commandServer, encrypt):
xSession = 0
foundTwoSession = False
reFoundUser = re.compile("%s\s+:\d+\s+"%(userName))
resWho = self.execProg("who",False,False)
if resWho and type(resWho) == types.ListType:
resWho = self.execProg("who")
if resWho:
for string in resWho:
if reFoundUser.search(string):
xSession +=1
@ -435,13 +435,13 @@ class client(share, commandServer, encrypt):
# Монтируем директории
mountStr = "mount -t cifs -o user=%s"%(userName)+\
" //%s/%s %s" %(host, res, path)
textLine = self.execProg(mountStr, None, True, {"PASSWD":userPwd})
textLine = self.execProg(mountStr, envProg={"PASSWD":userPwd})
return textLine
def mountSleepRes(self,host,userName,userPwd,uid,gid,res,path):
"""Монтирует ресурс при неудаче задержка потом повторное монитрование"""
textLine = self.mountSambaRes(host,userName,userPwd,uid,gid,res,path)
if not (textLine is None):
if textLine is False:
# Проверяем на монтирование директории
if isMount(path):
textLineUmount = self.umountSleepPath(path)
@ -449,13 +449,13 @@ class client(share, commandServer, encrypt):
return False
i = 0
sleeps = [0.5, 2, 5]
while (i<len(sleeps) and not (textLine is None)):
while (i<len(sleeps) and textLine is False):
# Задержка перед следующей попыткой
time.sleep(sleeps[i])
# Монтируем Samba ресурс
textLine = self.mountSambaRes(host,userName,userPwd,uid,
gid,res,path)
if not (textLine is None):
if textLine is False:
# Проверяем на монтирование директории
if isMount(path):
textLineUmount = self.umountSleepPath(path)
@ -996,7 +996,7 @@ class client(share, commandServer, encrypt):
# Монтируем Samba ресурс
textLine = self.mountSleepRes(hostConnect, userName, userPwd,
uid, gid, res, path)
if not (textLine is None):
if textLine is False:
if name == "remote_profile":
flagErrorMountRemote = True
break
@ -1073,7 +1073,7 @@ class client(share, commandServer, encrypt):
hostConnect = remoteServer
textLine = self.mountSleepRes(hostConnect,userName,userPwd,
uid,gid,res,path)
if not (textLine is None):
if textLine is False:
self.printERROR(_("Can not mount Samba resource [%s]")\
%res + " ...")
flagError = True
@ -1205,7 +1205,7 @@ class client(share, commandServer, encrypt):
hostConnect = defaultHost
textLine = self.mountSleepRes(hostConnect, userName, userPwd,
uid, gid, res, path)
if not (textLine is None):
if textLine is False:
self.printERROR(_("Can not mount Samba resource [%s]")\
%res + " ...")
flagError = True
@ -1277,8 +1277,8 @@ class client(share, commandServer, encrypt):
"""Проверка на вход пользователя в X"""
xSession = False
reFoundUser = re.compile("%s\s+:\d+\s+"%(userName))
resWho = self.execProg("who",False,False)
if resWho and type(resWho) == types.ListType:
resWho = self.execProg("who")
if resWho:
for string in resWho:
if reFoundUser.search(string):
xSession = True
@ -1340,13 +1340,13 @@ class client(share, commandServer, encrypt):
for fd in filesDir:
execStr = "cp -r '%s' '%s'" %(fd, movedPath)
textLine = self.execProg(execStr)
if not (textLine is None):
if textLine is False:
self.printERROR(_("Can not exec") + " " + str(execStr) +\
" ...")
return False
execStr = "rm -rf '%s'" %fd
textLine = self.execProg(execStr)
if not (textLine is None):
if textLine is False:
self.printERROR(_("Can not exec") + " " + str(execStr) +\
" ...")
return False
@ -1434,7 +1434,7 @@ class client(share, commandServer, encrypt):
"""
home = os.path.join(homeDir, "")
execStr = "mount"
textLines = self.execProg(execStr,False,False)
textLines = self.execProg(execStr)
# Пропускаемые директории для сканирования
skipPaths = []
if textLines:
@ -1643,19 +1643,19 @@ class client(share, commandServer, encrypt):
map(lambda x: x.split(" ")[1],\
open("/proc/mounts").readlines()))
def execProg(self, cmdStrProg, inStr=False, retFull=True, envProg={}):
def execProg(self, cmdStrProg, inStr=False, envProg={}):
"""Выполняет внешнюю программу
Параметры:
cmdStrProg внешняя программа
inStr данные передаваемые программе на страндартный вход.
Возвращаемые параметры:
строка которую выведет внешняя программа или False в случае ошибки
строки которые выведет внешняя программа или False в случае ошибки
"""
env_path = {"PATH":getpathenv()}
env = {}
env.update(os.environ.items() + env_path.items() + envProg.items())
retCode,programOut = runOsCommand(cmdStrProg,inStr,retFull,env)
retCode,programOut = runOsCommand(cmdStrProg,in_str=inStr,env_dict=env)
if not retCode:
return programOut
return False
@ -1666,21 +1666,21 @@ class client(share, commandServer, encrypt):
sleeps = [0.5, 2, 5]
# Проверяем на монтирование директорию
if isMount(path):
textLine = self.execProg("umount %s"%path)
if textLine is False:
textLines = self.execProg("umount %s"%path)
if textLines is False:
i = 0
flagError = False
while (i<len(sleeps) and textLine is False):
while (i<len(sleeps) and textLines is False):
# Задержка перед следующей попыткой
time.sleep(sleeps[i])
# Отмонтируем Samba ресурс
if isMount(path):
textLine = self.execProg("umount %s"%path)
textLines = self.execProg("umount %s"%path)
else:
textLine = None
textLines = True
break
i += 1
if textLine != None:
if textLines is False:
self.printERROR(_("Can not unmount path %s")%path + " ...")
return False
return True
@ -1723,8 +1723,8 @@ class client(share, commandServer, encrypt):
def getDefaultRunlevelDaemons(self):
"""Получаем всех демонов в default уровне"""
execStr = "rc-update show"
textLine = self.execProg(execStr, None, False)
if textLine == False:
textLine = self.execProg(execStr)
if textLine is False:
self.printERROR(_("ERROR") + ": " + execStr)
return False
else:
@ -1763,12 +1763,12 @@ class client(share, commandServer, encrypt):
if daemon in defaultDaemons:
execStr = "rc-update del %s default" %daemon
textLine = self.execProg(execStr)
if textLine:
return True
else:
if textLine is False:
self.printERROR(_("ERROR") + ": " + execStr)
self.printERROR(_("Can not delete from default runlevel"))
return False
else:
return True
return True
def delDomain(self):
@ -1823,12 +1823,12 @@ class client(share, commandServer, encrypt):
return True
execStr = "rc-update add %s default" %daemon
textLine = self.execProg(execStr)
if textLine:
return True
else:
if textLine is False:
self.printERROR(_("ERROR") + ": " + execStr)
self.printERROR(_("Can not add at default runlevel"))
return False
else:
return True
def restartDBus(self):
"""Перезапускаем службу D-Bus"""
@ -1878,15 +1878,15 @@ class client(share, commandServer, encrypt):
else:
domain = "%s.%s" %(domainName,netDomain)
execStr = "ping -c 2 -i 0.3 %s" %domain
resPing = self.execProg(execStr, False, False)
if not resPing:
resPing = self.execProg(execStr)
if resPing is False:
self.printERROR(_('Can not execute "%s"')%execStr)
return False
foudHost = False
foudHostSamba = False
foundHostSamba = False
foundMountRemote = False
reFoundHost = re.compile("(\d+)\% packet loss")
if resPing and type(resPing) == types.ListType and len(resPing)>=2:
if resPing and len(resPing)>=2:
pingStr = resPing[-2].strip()
reSearch = reFoundHost.search(pingStr)
if reSearch and reSearch.group(1) == "0":
@ -1895,14 +1895,13 @@ class client(share, commandServer, encrypt):
self.printERROR(_("Not found domain %s")%domain)
return False
reFoundHostSamba = re.compile("Server=\[Samba.+\]")
resSmbClient = self.execProg("smbclient -N -L %s" %domain,
False,False)
if resSmbClient and type(resSmbClient) == types.ListType:
resSmbClient = self.execProg("smbclient -N -L %s" %domain)
if not resSmbClient is False:
for string in resSmbClient:
if reFoundHostSamba.search(string):
foudHostSamba = True
foundHostSamba = True
break
if not foudHostSamba:
if not foundHostSamba:
self.printERROR(_("Not found Samba server in %s")%domain)
return False
remoteHost = self.clVars.Get("cl_remote_host")
@ -1928,8 +1927,8 @@ you need to remove it from the previous domain"))
os.makedirs(pathRemote)
mountStr = "mount -t cifs -o user=client //%s/remote %s"\
%(domain,pathRemote)
textLine = self.execProg(mountStr, None, True, {"PASSWD":pwdRemote})
if not (textLine is None):
textLine = self.execProg(mountStr, envProg={"PASSWD":pwdRemote})
if textLine is False:
self.printERROR(_("Can not mount Samba resource [%s]")%\
"remote" + " ...")
return False
@ -2127,8 +2126,8 @@ you need to remove it from the previous domain"))
os.makedirs(pathRemote)
mountStr = "mount -t cifs -o user=client //%s/remote %s"\
%(domain,pathRemote)
textLine = self.execProg(mountStr, None, True, {"PASSWD":pwdRemote})
if not (textLine is None):
textLine = self.execProg(mountStr, envProg={"PASSWD":pwdRemote})
if textLine is False:
self.printWARNING(_("Can not mount Samba resource [%s]")%\
"remote" + " ...")
beforeRemoteAuth = self.clVars.Get('os_remote_auth')

Loading…
Cancel
Save