From f50acce5f5c7428acc2c6fc9c8b1b5d7b0b6f50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D1=83=D0=BA=D0=B8=D0=BD=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Fri, 4 Sep 2009 18:31:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=BB=D0=BE=D0=BB=D0=BD=D1=8F=D1=8E=D1=89=D0=B8=D0=B5=20=D0=B2?= =?UTF-8?q?=D0=BD=D0=B5=D1=88=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/cl_client.py | 76 +++++++++++++++++++------------------------ pym/cl_fill_client.py | 22 ++++++++----- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/pym/cl_client.py b/pym/cl_client.py index bb01a0b..c5c1bc2 100644 --- a/pym/cl_client.py +++ b/pym/cl_client.py @@ -73,8 +73,12 @@ org.kde.kdialog.ProgressDialog' close_fds=True, env=env, shell=True) pipe.stdin.close() - if pipe.poll() != 0: - time.sleep(0.5) + if pipe.poll() == None: + # задержка полсекунды + for t in range(50): + time.sleep(0.01) + if pipe.poll() != None: + break if pipe.poll() == 0: self.kdialog = pipe.stdout.readline().strip() while not "org.kde.kdialog" in self.kdialog: @@ -743,27 +747,22 @@ conjunction with the 'login' or 'logout'") os.lchown(linkCh[1], uid, gid) return True - def execProg(self, cmdStrProg, inStr=False, retFull=True): + def execProg(self, cmdStrProg, inStr=False, retFull=True, envProg={}): """Выполняет внешнюю программу Параметры: cmdStrProg внешняя программа inStr данные передаваемые программе на страндартный вход. Возвращаемые параметры: - строка которую выведет внешняя программа + строка которую выведет внешняя программа или False в случае ошибки """ - return cl_utils.runOsCommand(cmdStrProg, inStr, retFull) - - #def getUidAndGidUser(self, userName): - #strRes = self.execProg("id %s" %userName) - #reFind = re.compile("uid=(\d+)\(.+gid=(\d+)\(") - #res = reFind.search(strRes) - #if res: - #return res.group(1), res.group(2) - #else: - #self.printERROR(_("User %s not found")\ - #%str(userName)) - #return False + env_path = {"PATH":cl_utils.getpathenv()} + env = {} + env.update(os.environ.items() + env_path.items() + envProg.items()) + retCode,programOut = cl_utils.runOsCommand(cmdStrProg,inStr,retFull,env) + if not retCode: + return programOut + return False def getUserPasswdInfo(self, userName): """получаем uid и gid пользователя из /etc/passwd""" @@ -787,8 +786,7 @@ conjunction with the 'login' or 'logout'") """Прописывает демона в автозагрузку""" execStr = "rc-update add %s default" %daemon textLine = self.execProg(execStr) - if "added to runlevel" in textLine or\ - "already installed in runlevel" in textLine: + if textLine: return True else: self.printERROR(_("ERROR") + ": " + execStr) @@ -799,12 +797,7 @@ conjunction with the 'login' or 'logout'") """Удаляет демона из автозагрузки""" execStr = "rc-update del %s default" %daemon textLine = self.execProg(execStr) - if "removed from the following runlevels" in textLine or\ - "not found in any of the specified runlevels" in textLine: - return True - #Для openrc - elif "removed from runlevel" in textLine or\ - "is not in the runlevel" in textLine: + if textLine: return True else: self.printERROR(_("ERROR") + ": " + execStr) @@ -901,6 +894,8 @@ conjunction with the 'login' or 'logout'") def killRsync(self): """Убивает все процессы rsync и cl-sync --login""" listProcess = self.execProg("ps ax",False,False) + if not listProcess: + return False killPid = [] flagError = False for process in listProcess: @@ -1056,11 +1051,9 @@ conjunction with the 'login' or 'logout'") return False if not os.path.exists(pathRemote): os.makedirs(pathRemote) - #Экранируем символы - escPwdRemote = re.sub("(\W)", r"\\\1",pwdRemote) - mountStr = "PASSWD=%s mount -t cifs -o user=client \ -//%s/remote %s" %(escPwdRemote,domain,pathRemote) - textLine = self.execProg(mountStr) + mountStr = "mount -t cifs -o user=client //%s/remote %s"\ + %(domain,pathRemote) + textLine = self.execProg(mountStr, None, True, {"PASSWD":pwdRemote}) if not (textLine == None): self.printWARNING(_("Can not mount Samba resource [%s]")%\ "remote" + " ...") @@ -1230,7 +1223,11 @@ manager") + " ..." domain = domainName else: domain = "%s.%s" %(domainName,netDomain) - resPing = self.execProg("ping -c 2 -i 0.3 %s" %domain,False,False) + execStr = "ping -c 2 -i 0.3 %s" %domain + resPing = self.execProg(execStr, False, False) + if not resPing: + self.printERROR(_('Can not execute "%s"')%execStr) + return False foudHost = False foudHostSamba = False foundMountRemote = False @@ -1277,11 +1274,9 @@ manager") + " ..." pwdRemote = userPwd if not os.path.exists(pathRemote): os.makedirs(pathRemote) - # Экранируем символы - escPwdRemote = re.sub("(\W)", r"\\\1",pwdRemote) - mountStr = "PASSWD=%s mount -t cifs -o user=client \ -//%s/remote %s" %(escPwdRemote,domain,pathRemote) - textLine = self.execProg(mountStr) + mountStr = "mount -t cifs -o user=client //%s/remote %s"\ + %(domain,pathRemote) + textLine = self.execProg(mountStr, None, True, {"PASSWD":pwdRemote}) if not (textLine == None): self.printERROR(_("Can not mount Samba resource [%s]")%\ "remote" + " ...") @@ -1655,21 +1650,18 @@ or ld_bind_dn or ld_bind_pw") def mountSambaRes(self,userName,userPwd,uid,gid,res,path, mountUidList=['ftp','share']): """Монтирует Samba ресурсы""" - #Экранируем символы - escUserPwd = re.sub("(\W)", r"\\\1",userPwd) if res in mountUidList: # Монтируем директории c uid - mountStr="PASSWD=%s mount -t cifs -o user=%s,uid=%s,gid=%s"\ - %(escUserPwd,userName,uid,gid) +\ + mountStr="mount -t cifs -o user=%s,uid=%s,gid=%s"\ + %(userName,uid,gid) +\ " //%s/%s %s" %(self.clVars.Get("cl_remote_host"), res, path) else: # Монтируем директории - mountStr="PASSWD=%s mount -t cifs -o user=%s"%(escUserPwd, - userName)+\ + mountStr="mount -t cifs -o user=%s"%(userName)+\ " //%s/%s %s" %(self.clVars.Get("cl_remote_host"), res, path) - textLine = self.execProg(mountStr) + textLine = self.execProg(mountStr, None, True, {"PASSWD":userPwd}) return textLine def removeDir(self, rmDirOrScanObjs): diff --git a/pym/cl_fill_client.py b/pym/cl_fill_client.py index f23a949..345c2b6 100644 --- a/pym/cl_fill_client.py +++ b/pym/cl_fill_client.py @@ -39,7 +39,9 @@ class fillVars(object, cl_base.glob_attr): def getX11Resolution(self): """возвращает текущее разрешение экрана (ширина, высота), X запущен""" - lines=self._runos("%s xdpyinfo"%self.path_env) + lines=self._runos("xdpyinfo") + if not lines: + return "" reRes = re.compile("dimensions:\s+(\d+)x(\d+)\s+pixels") searchRes=False for line in lines: @@ -49,7 +51,7 @@ class fillVars(object, cl_base.glob_attr): if searchRes: return (searchRes.group(1), searchRes.group(2)) else: - return False + return "" def get_hr_x11_height(self): """Получить высоту экрана в пикселах""" @@ -125,13 +127,13 @@ class fillVars(object, cl_base.glob_attr): def get_hr_laptop(self): """Если компьютер ноутбук, то его производитель""" - formfactor = self._runos("%s hal-get-property --udi\ - /org/freedesktop/Hal/devices/computer --key system.formfactor"\ - %self.path_env) + formfactor = self._runos("hal-get-property --udi \ +/org/freedesktop/Hal/devices/computer --key system.formfactor") + if not formfactor: + return "" if formfactor == 'laptop': - vendor = self._runos("%s hal-get-property --udi\ - /org/freedesktop/Hal/devices/computer --key system.hardware.vendor"\ - %self.path_env) + vendor = self._runos("hal-get-property --udi \ +/org/freedesktop/Hal/devices/computer --key system.hardware.vendor") if vendor: vendor = vendor.split(" ")[0] else: @@ -141,7 +143,9 @@ class fillVars(object, cl_base.glob_attr): def get_hr_video(self): """Производитель видеокарты""" - lines=self._runos("%s lspci"%self.path_env) + lines=self._runos("lspci") + if not lines: + return "" reVGA = re.compile("vga",re.I) foundVGA = False for line in lines: