From f94178fe916587050a17b2cbe3f2526a29143919 Mon Sep 17 00:00:00 2001 From: fishros Date: Sat, 5 Feb 2022 21:33:34 +0800 Subject: [PATCH] =?UTF-8?q?[fix]:=E4=BF=AE=E5=A4=8DCmdTask=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=94=B6=E9=9B=86=E4=B8=8D=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install | 4 ++-- tools/base.py | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/install b/install index 8228b3e..971f433 100644 --- a/install +++ b/install @@ -5,6 +5,6 @@ if [ $UID -eq 0 ];then apt-get install sudo fi sudo python3 /tmp/fishinstall/install.py -rm -rf /tmp/fishinstall/ -rm fishros +sudo rm -rf /tmp/fishinstall/ +sudo rm fishros . ~/.bashrc \ No newline at end of file diff --git a/tools/base.py b/tools/base.py index 6622771..2c74229 100644 --- a/tools/base.py +++ b/tools/base.py @@ -749,9 +749,9 @@ def __init__(self,timeout=10,scale=20) -> None: self.i = 0 def update(self,log=""): - length = 30 - if len(log)>length: log = log[:length] - log = log+" " + # length = 60 + # if len(log)>length: log = log[:length] + # log = log+" " if (self.i%4) == 0: print('\r[/]{}'.format(log),end="") elif(self.i%4) == 1: @@ -761,6 +761,7 @@ def update(self,log=""): elif (self.i%4) == 3: print('\r[-]{}'.format(log),end="") sys.stdout.flush() + self.i += 1 # update time # self.dur = time.perf_counter() -self.start # self.i = int(self.dur/(self.timeout/self.scale)) @@ -772,7 +773,7 @@ def update(self,log=""): # print("\r{:^3.0f}%[{}->{}]{:.2f}s {}".format(c,a,b,self.dur,log),end = "") def finsh(self,log=""): - length = 30 + length = 60 if len(log)>length: log = log[:length] log = log+" " print('\r[-]{}'.format(log),end="") @@ -802,13 +803,22 @@ def __run_command(command,timeout=10): # sub.communicate bar = Progress(timeout=timeout) bar.update() - for line in sub.stdout.readlines(): + + while sub.poll()==None: + line = sub.stdout.readline() line = line.decode("utf-8").strip("\n") + out.append(line) bar.update(line) time.sleep(0.01) + + lines = sub.stdout.readlines() + for line in lines: + line = line.decode("utf-8").strip("\n") out.append(line) - - time.sleep(1) + bar.update(line) + time.sleep(0.01) + + if sub.poll()==None: sub.kill() print("\033[31mTimeOut!:{}".format(timeout))