def pulse(self, owner): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" base.AcquireProgress.pulse(self, owner) percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) shown = False tval = '%i%%' % percent end = "" if self.current_cps: eta = long(float(self.total_bytes - self.current_bytes) / self.current_cps) end = " %sB/s %s" % (apt_pkg.size_to_str(self.current_cps), apt_pkg.time_to_str(eta)) for worker in owner.workers: val = '' if not worker.current_item: if worker.status: val = ' [%s]' % worker.status if len(tval) + len(val) + len(end) >= self._width: break tval += val shown = True continue shown = True if worker.current_item.owner.id: val += " [%i %s" % (worker.current_item.owner.id, worker.current_item.shortdesc) else: val += ' [%s' % worker.current_item.description if worker.current_item.owner.mode: val += ' %s' % worker.current_item.owner.mode val += ' %sB' % apt_pkg.size_to_str(worker.current_size) # Add the total size and percent if worker.total_size and not worker.current_item.owner.complete: val += "/%sB %i%%" % (apt_pkg.size_to_str(worker.total_size), worker.current_size*100.0/worker.total_size) val += ']' if len(tval) + len(val) + len(end) >= self._width: # Display as many items as screen width break else: tval += val if not shown: tval += _(" [Working]") if self.current_cps: tval += (self._width - len(end) - len(tval)) * ' ' + end self._write(tval, False) return True
def stop(self): """Invoked when the Acquire process stops running.""" base.AcquireProgress.stop(self) # Trick for getting a translation from apt self._write((_("Fetched %sB in %s (%sB/s)\n") % ( apt_pkg.size_to_str(self.fetched_bytes), apt_pkg.time_to_str(self.elapsed_time), apt_pkg.size_to_str(self.current_cps))).rstrip("\n")) # Delete the signal again. import signal signal.signal(signal.SIGWINCH, self._signal)
def pulse(self): """Called periodically to update the user interface. Return True to continue or False to cancel. """ FetchProgress.pulse(self) if self.currentCPS > 0: s = "[%2.f%%] %sB/s %s" % (self.percent, apt_pkg.size_to_str(int(self.currentCPS)), apt_pkg.time_to_str(int(self.eta))) else: s = "%2.f%% [Working]" % (self.percent) print "\r%s" % (s), sys.stdout.flush() return True
def pulse(self): """Called periodically to update the user interface. Return True to continue or False to cancel. """ FetchProgress.pulse(self) if self.currentCPS > 0: s = "[%2.f%%] %sB/s %s" % ( self.percent, apt_pkg.size_to_str(int( self.currentCPS)), apt_pkg.time_to_str(int(self.eta))) else: s = "%2.f%% [Working]" % (self.percent) print "\r%s" % (s), sys.stdout.flush() return True
def pulse(self, owner): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" apt.progress.base.AcquireProgress.pulse(self, owner) self.percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) end = "" if self.current_cps: eta = long(float(self.total_bytes - self.current_bytes) / self.current_cps) end = " %sB/s %s" % (apt_pkg.size_to_str(self.current_cps), apt_pkg.time_to_str(eta)) global_event.emit("update-list-update", self.percent, self.status_message, end) return True
def pulse(self, owner): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" apt.progress.base.AcquireProgress.pulse(self, owner) self.percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) end = "" if self.current_cps: eta = long( float(self.total_bytes - self.current_bytes) / self.current_cps) end = " %sB/s %s" % (apt_pkg.size_to_str( self.current_cps), apt_pkg.time_to_str(eta)) global_event.emit("update-list-update", self.percent, self.status_message, end) return True
def pulse(self, owner): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" base.AcquireProgress.pulse(self, owner) percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) shown = False tval = '%i%%' % percent end = "" if self.current_cps: eta = long( float(self.total_bytes - self.current_bytes) / self.current_cps) end = " %sB/s %s" % (apt_pkg.size_to_str( self.current_cps), apt_pkg.time_to_str(eta)) for worker in owner.workers: val = '' if not worker.current_item: if worker.status: val = ' [%s]' % worker.status if len(tval) + len(val) + len(end) >= self._width: break tval += val shown = True continue shown = True if worker.current_item.owner.id: val += " [%i %s" % (worker.current_item.owner.id, worker.current_item.shortdesc) else: val += ' [%s' % worker.current_item.description if worker.current_item.owner.mode: val += ' %s' % worker.current_item.owner.mode val += ' %sB' % apt_pkg.size_to_str(worker.current_size) # Add the total size and percent if worker.total_size and not worker.current_item.owner.complete: val += "/%sB %i%%" % (apt_pkg.size_to_str( worker.total_size), worker.current_size * 100.0 / worker.total_size) val += ']' if len(tval) + len(val) + len(end) >= self._width: # Display as many items as screen width break else: tval += val if not shown: tval += _(" [Working]") if self.current_cps: tval += (self._width - len(end) - len(tval)) * ' ' + end self._write(tval, False) return True
def _download(self, pkgs, num_concurrent=3): if not pkgs: return True partial_dir = os.path.join(self.archive_dir, 'partial') cmdline = [self.opts.aria2c, '--metalink-file=-', '--file-allocation=none', '--auto-file-renaming=false', '--dir={0}'.format(partial_dir), '--max-concurrent-downloads={0}'.format(num_concurrent), '--no-conf', '--remote-time=true', '--auto-save-interval=0', '--continue', '--enable-http-pipelining=true', '--uri-selector=adaptive', '--download-result=full' ] if self.opts.hash_check: cmdline.append('--check-integrity=true') http_proxy = apt_pkg.config.find('Acquire::http::Proxy') https_proxy = apt_pkg.config.find('Acquire::https::Proxy', http_proxy) ftp_proxy = apt_pkg.config.find('Acquire::ftp::Proxy') if http_proxy: cmdline.append('='.join(['--http-proxy', http_proxy])) if https_proxy: cmdline.append('='.join(['--https-proxy', https_proxy])) if ftp_proxy: cmdline.append('='.join(['--ftp-proxy', ftp_proxy])) print('Download in progress...') time_start = time.time() proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={"LANGUAGE": "en_US"}, bufsize=1, universal_newlines=True) flags = fcntl(proc.stdout, F_GETFL) fcntl(proc.stdout, F_SETFL, flags | O_NONBLOCK) make_metalink(proc.stdin, pkgs, self.opts.hash_check) proc.stdin.close() download_results = False download_items = False download_list = list() downloading = 0 downloaded = -1 loop=0 maxloop = 60 while True: try: line = proc.stdout.readline() except OSError: proc.kill() break if line == None and proc.poll() != None: break line = line.strip() if line == '': loop += 1 if loop >= maxloop: proc.kill() break sleep(1) continue loop=0 if line.startswith('Download Results:'): download_results = True maxloop = 2 if download_results: if partial_dir in line: download_items = True download_list.append(line.replace(partial_dir + "/", '')) if 'ERR' in line: downloaded -= 1 else: if download_items: download_items = False download_list.sort(key = sort_filename) print(*download_list, sep = "\n") print(line) if 'ownload complete' in line: break elif 'Downloading ' in line and ' item(s)' in line: l = line.split() i = l.index('Downloading') downloading = int(l[i+1]) downloaded = 0 if self.opts.verbose: print('{0} {1} {2}'.format(l[i], downloading, l[i+2])) elif 'Download complete:' in line: downloaded += 1 if self.opts.verbose: l = line.split() print('{0}/{1} {2}'.format(downloaded, downloading, \ l[l.index('complete:')+1].replace(partial_dir + "/", ''))) print() link_success = True time_e = int(time.time() - time_start) print('Elapsed time: {0}'.format(apt_pkg.time_to_str(time_e))) print('Overall speed: {0}B/s'.format(apt_pkg.size_to_str(self.cache.required_download / time_e))) # Link archives/partial/*.deb to archives/ for pkg in pkgs: filename = get_filename(pkg.candidate) dst = os.path.join(self.archive_dir, filename) src = os.path.join(partial_dir, filename) ctrl_file = ''.join([src, '.aria2']) # If control file exists, we assume download is not complete. if os.path.exists(ctrl_file): continue try: # Making hard link because aria2c needs file in # partial directory to know download is complete # in the next invocation. os.rename(src, dst) except OSError as e: if e.errno != errno.ENOENT: print("Failed to move archive file", e) link_success = False downloaded -= 1 return link_success and downloading == downloaded