Добавлена совместимость с python 2.6

git-svn-id: http://svn.calculate.ru/calculate2/calculate-client/trunk@2506 c91db197-33c1-4113-bf15-f8a5c547ca64
develop
asamoukin 15 years ago
parent 5c4d73cce2
commit ec95a45dfa

@ -30,7 +30,7 @@ import _cl_keys
import time import time
import stat import stat
import popen2 import subprocess
import time import time
Version = "calculate-client 2.1.2" Version = "calculate-client 2.1.2"
@ -47,7 +47,7 @@ class printNoColor:
class ProgressBar: class ProgressBar:
suffixSet = 'org.freedesktop.DBus.Properties.Set \ suffixSet = 'org.freedesktop.DBus.Properties.Set \
org.kde.kdialog.ProgressDialog' org.kde.kdialog.ProgressDialog'
execenv = 'HOME="/root" ' execenv = {"HOME":"/root"}
max = 100 max = 100
kdialog = None kdialog = None
label = None label = None
@ -61,16 +61,17 @@ org.kde.kdialog.ProgressDialog'
self.max = max self.max = max
self.title = title self.title = title
if os.system('which kdialog >/dev/null') == 0: if os.system('which kdialog >/dev/null') == 0:
self.label ="LOGINKDIALOG=%d" % os.getpid() self.execenv["LOGINKDIALOG"] = str(os.getpid())
pipe = popen2.Popen4(self.execenv + " %s " % self.label +\ pipe = subprocess.Popen('/usr/bin/kdialog --progressbar "%s" %d'\
'/usr/bin/kdialog --progressbar "%s" %d' % (\ %(" "*(len(title)+20), self.max),
" "*(len(title)+20),self.max)) stdout=subprocess.PIPE,close_fds=True,
env=self.execenv, shell=True)
if pipe.poll() != 0: if pipe.poll() != 0:
time.sleep(0.5) time.sleep(0.5)
if pipe.poll() == 0: if pipe.poll() == 0:
self.kdialog = pipe.fromchild.readline().strip() self.kdialog = pipe.stdout.readline().strip()
while not "org.kde.kdialog" in self.kdialog: while not "org.kde.kdialog" in self.kdialog:
s = fout.fromchild.readline() s = pipe.stdout.readline()
if s == "": if s == "":
self.shutdownDialog() self.shutdownDialog()
self.kdialog = s.strip() self.kdialog = s.strip()
@ -81,8 +82,10 @@ org.kde.kdialog.ProgressDialog'
def shutdownDialog(self): def shutdownDialog(self):
'''Принудительно уничтожить процесс kdialog''' '''Принудительно уничтожить процесс kdialog'''
self.kdialog = None self.kdialog = None
pipe = subprocess.Popen("/bin/ps axeo pid,cmd", stdout=subprocess.PIPE,
close_fds=True, shell=True)
if self.label != None: if self.label != None:
for s in os.popen('/bin/ps axeo pid,cmd'): for s in pipe.stdout:
if self.label in s: if self.label in s:
try: try:
os.kill( int(s.split()[0]), 9 ) os.kill( int(s.split()[0]), 9 )
@ -161,9 +164,10 @@ class RsyncProgressBar(ProgressBar):
def runsilent(self): def runsilent(self):
'''Запустить rsync без progressbar''' '''Запустить rsync без progressbar'''
self.pipe = popen2.Popen4(self.rsyncstr) self.pipe = subprocess.Popen(self.rsyncstr, stdout=subprocess.PIPE,
close_fds=True, shell=True)
while True: while True:
s = self.pipe.fromchild.readline() s = self.pipe.stdout.readline()
if len(s) == 0: if len(s) == 0:
break break
q = self.receiverre.search(s) q = self.receiverre.search(s)
@ -173,10 +177,11 @@ class RsyncProgressBar(ProgressBar):
def run(self): def run(self):
'''Запустить rsync с progressbar''' '''Запустить rsync с progressbar'''
self.openDialog(self.title,0) self.openDialog(self.title,0)
self.pipe = popen2.Popen4(self.rsyncstr) self.pipe = subprocess.Popen(self.rsyncstr, stdout=subprocess.PIPE,
close_fds=True, shell=True)
oldpercent = 0 oldpercent = 0
while True: while True:
s = self.pipe.fromchild.readline() s = self.pipe.stdout.readline()
if len(s) == 0: if len(s) == 0:
break break
q = self.senderre.search(s) q = self.senderre.search(s)

Loading…
Cancel
Save