def exec_axel(conduit, remote, local, size, conn=None, text=None): """ Run axel binary to download""" if not size or size == -1: # we need size here. if not, we do nothing conduit.info(3, "axel got unknown size") return False # new thread to run axel conf = conduit.getConf() axel_debug = False if conf.debuglevel >= 3: axel_debug = True axel = Axel(debug=axel_debug, remote=remote, local=local, conn=conn) axel.start() # make axel outout look like yum output tm = TextMeter() size = int(size) filename = os.path.basename(local) if not text: text = filename # compose text console output tm.start(filename=filename, size=size, text=str(text)) #axel.start() lastSize = curSize = 0 slow_count = 0 while True: live = axel.isAlive() if curSize >= size or not live: if live: conduit.info(3, "axel is unexpectedly still alive") break try: curSize = os.path.getsize(local) except OSError, e: # maybe axel still don't generate local file # just continue to the following time call curSize = 0 pass # update the text bar every one second tm.update(curSize) time.sleep(0.5) # too slow, Less than 1000 bytes/sec transferred # the last 30 second if (curSize - lastSize) < 1000: slow_count += 1 if slow_count == 60: conduit.info( 3, "Operation too slow. Less than 1000 \ bytes/sec transferred the last 30 seconds") axel.stop() break lastSize = curSize
def exec_axel(conduit, remote, local, size, conn=None, text=None): """ Run axel binary to download""" if not size or size == -1: # we need size here. if not, we do nothing conduit.info(3, "axel got unknown size") return False # new thread to run axel conf = conduit.getConf() axel_debug = False if conf.debuglevel >= 3: axel_debug = True axel = Axel(debug=axel_debug, remote=remote, local=local, conn=conn) axel.start() # make axel outout look like yum output tm = TextMeter() size = int(size) filename = os.path.basename(local) if not text: text = filename # compose text console output tm.start(filename=filename, size=size, text=str(text)) #axel.start() lastSize = curSize = 0 slow_count = 0 while True: live = axel.isAlive() if curSize >= size or not live: if live: conduit.info(3, "axel is unexpectedly still alive") break try: curSize = os.path.getsize(local) except OSError, e: # maybe axel still don't generate local file # just continue to the following time call curSize = 0 pass # update the text bar every one second tm.update(curSize) time.sleep(0.5) # too slow, Less than 1000 bytes/sec transferred # the last 30 second if (curSize - lastSize) < 1000: slow_count += 1 if slow_count == 60: conduit.info(3, "Operation too slow. Less than 1000 \ bytes/sec transferred the last 30 seconds") axel.stop() break lastSize = curSize
return ret def get_size(filename): return os.path.getsize(os.path.join(PWD, filename)) # MAIN a = Axel() a.start() time.sleep(2) # start tm = TextMeter() tm.start(filename=FILENAME, text=FILENAME) cur = get_size(FILENAME) while True: if cur >= SIZE: print "Done" break cur = get_size(FILENAME) print "size: %d" % cur tm.update(cur) time.sleep(1) tm.end(SIZE) a.join()
def get_size(filename): return os.path.getsize(os.path.join(PWD,filename)) # MAIN a = Axel() a.start() time.sleep(2) # start tm = TextMeter() tm.start(filename=FILENAME, text=FILENAME) cur = get_size(FILENAME) while True: if cur >= SIZE: print "Done" break cur = get_size(FILENAME) print "size: %d" %cur tm.update(cur) time.sleep(1) tm.end(SIZE) a.join()