diff --git a/pym/cl_client.py b/pym/cl_client.py index 9a06438..aaeffab 100644 --- a/pym/cl_client.py +++ b/pym/cl_client.py @@ -61,11 +61,18 @@ org.kde.kdialog.ProgressDialog' self.max = max self.title = title if os.system('which kdialog >/dev/null') == 0: - self.execenv["LOGINKDIALOG"] = str(os.getpid()) + self.label ="LOGINKDIALOG=%d" % os.getpid() + env = {} + env.update(os.environ.items() + self.execenv.items() +\ + [tuple(self.label.split("="))]) pipe = subprocess.Popen('/usr/bin/kdialog --progressbar "%s" %d'\ %(" "*(len(title)+20), self.max), - stdout=subprocess.PIPE,close_fds=True, - env=self.execenv, shell=True) + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True, + env=env, shell=True) + pipe.stdin.close() if pipe.poll() != 0: time.sleep(0.5) if pipe.poll() == 0: @@ -73,19 +80,29 @@ org.kde.kdialog.ProgressDialog' while not "org.kde.kdialog" in self.kdialog: s = pipe.stdout.readline() if s == "": + pipe.stdout.close() + pipe.stderr.close() self.shutdownDialog() + break self.kdialog = s.strip() self.setTitle(self.title) + pipe.stdout.close() + pipe.stderr.close() else: + pipe.stdout.close() + pipe.stderr.close() self.shutdownDialog() def shutdownDialog(self): '''Принудительно уничтожить процесс kdialog''' self.kdialog = None - pipe = subprocess.Popen("/bin/ps axeo pid,cmd", stdout=subprocess.PIPE, + pipe = subprocess.Popen("/bin/ps axeo pid,cmd", + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, close_fds=True, shell=True) if self.label != None: - for s in pipe.stdout: + for s in pipe.stdout.readlines(): if self.label in s: try: os.kill( int(s.split()[0]), 9 ) @@ -96,25 +113,34 @@ org.kde.kdialog.ProgressDialog' def setValue(self,value): '''Установить текущее значения для прогресса''' if self.kdialog and value <= self.max: - os.system(self.execenv+ - '/usr/bin/qdbus %s %s value %d >/dev/null' % (\ - self.kdialog,self.suffixSet, value)); + env = "" + if self.execenv: + env = " ".join(map(lambda x: '%s="%s"'%(x[0],x[1]),\ + self.execenv)) + " " + os.system(env + '/usr/bin/qdbus %s %s value %d >/dev/null'\ + %(self.kdialog,self.suffixSet, value)) def setMaximum(self,max): '''Установить максимальное значения для прогресса''' self.max = max if self.kdialog: - os.system(self.execenv+ - '/usr/bin/qdbus %s %s maximum %d >/dev/null' % (\ - self.kdialog,self.suffixSet, self.max)); + env = "" + if self.execenv: + env = " ".join(map(lambda x: '%s="%s"'%(x[0],x[1]),\ + self.execenv)) + " " + os.system(env + '/usr/bin/qdbus %s %s maximum %d >/dev/null'\ + %(self.kdialog,self.suffixSet, self.max)) def setTitle(self,title): '''Установить описания прогресса''' self.title = title if self.kdialog: - os.system(self.execenv+ - '/usr/bin/qdbus %s setLabelText "%s" >/dev/null' % \ - (self.kdialog,self.title)) + env = "" + if self.execenv: + env = " ".join(map(lambda x: '%s="%s"'%(x[0],x[1]),\ + self.execenv)) + " " + os.system(env + '/usr/bin/qdbus %s setLabelText "%s" >/dev/null'\ + %(self.kdialog,self.title)) def close(self): '''Закрыть прогресс''' @@ -164,7 +190,9 @@ class RsyncProgressBar(ProgressBar): def runsilent(self): '''Запустить rsync без progressbar''' - self.pipe = subprocess.Popen(self.rsyncstr, stdout=subprocess.PIPE, + self.pipe = subprocess.Popen(self.rsyncstr, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, close_fds=True, shell=True) while True: s = self.pipe.stdout.readline() @@ -177,7 +205,9 @@ class RsyncProgressBar(ProgressBar): def run(self): '''Запустить rsync с progressbar''' self.openDialog(self.title,0) - self.pipe = subprocess.Popen(self.rsyncstr, stdout=subprocess.PIPE, + self.pipe = subprocess.Popen(self.rsyncstr, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, close_fds=True, shell=True) oldpercent = 0 while True: