我目前正在生成一个带有结构框架的python脚本,它应该从远程服务器收集备份并将其本地存储在运行结构的客户端上。
现在,由于备份文件大于400MB,因此传输它需要相当长的时间。这就是我的问题所在:
结构get() - 函数是否有任何类型的进度条?或者更确切地说,是否可以以某种方式添加进度条?
这是我的一段代码:
def collect_backup():
env.warn_only=True
run('uptime')
print "Copying scrips to be run..."
filename, remotepath = _getlatest()
print "Copy complete."
print "Collecting backup..."
localpath = _collect(filename, remotepath)
def _collect(filename, remotepath):
a=remotepath + filename
localpath="/home/bcns/backups/"
####Here's the get() I was talking about
get(a, localpath)
return(localpath)
“filename”和“remotepath”变量在另一个函数中设置。
答案 0 :(得分:-1)
以下网站有很多很棒的信息:
http://thelivingpearl.com/2012/12/31/creating-progress-bars-with-python/
以下是带有线程的控制台编程栏的解决方案:
import sys
import time
import threading
class progress_bar_loading(threading.Thread):
def run(self):
global stop
global kill
print 'Loading.... ',
sys.stdout.flush()
i = 0
while stop != True:
if (i%4) == 0:
sys.stdout.write('\b/')
elif (i%4) == 1:
sys.stdout.write('\b-')
elif (i%4) == 2:
sys.stdout.write('\b\\')
elif (i%4) == 3:
sys.stdout.write('\b|')
sys.stdout.flush()
time.sleep(0.2)
i+=1
if kill == True:
print '\b\b\b\b ABORT!',
else:
print '\b\b done!',
kill = False
stop = False
p = progress_bar_loading()
p.start()
try:
#anything you want to run.
time.sleep(1)
stop = True
except KeyboardInterrupt or EOFError:
kill = True
stop = True
希望这有助于或至少让你开始。