def __fill_progress(self, fs, progs): if not progs: return 0 tb = 0 for f in fs: if f[3]: # dir, has some children bd = self.__fill_progress(f[3], progs) f[5] = format_progress(bd // f[2] * 100) else: # file, update own prog and add to total bd = f[2] * progs[f[1]] f[5] = format_progress(progs[f[1]] * 100) tb += bd return tb
def __fill_progress(self, fs, progs): if not progs: return 0 tb = 0 for f in fs: if f[3]: # dir, has some children bd = self.__fill_progress(f[3], progs) f[5] = format_progress(bd // f[2] * 100) else: # file, update own prog and add to total bd = f[2] * progs[f[1]] f[5] = format_progress(progs[f[1]] * 100) tb += bd return tb
def build_file_list(self, torrent_files, progress, priority): """Split file list from torrent state into a directory tree. Returns: Tuple: A list of lists in the form: [file/dir_name, index, size, children, expanded, progress, priority] Dictionary: Map of file index for fast updating of progress and priorities. """ file_list = [] file_dict = {} # directory index starts from total file count. dir_idx = len(torrent_files) for torrent_file in torrent_files: cur = file_list paths = torrent_file['path'].split('/') for path in paths: if not cur or path != cur[-1][0]: child_list = [] if path == paths[-1]: file_progress = format_progress( progress[torrent_file['index']] * 100) entry = [ path, torrent_file['index'], torrent_file['size'], child_list, False, file_progress, priority[torrent_file['index']], ] file_dict[torrent_file['index']] = entry else: entry = [path, dir_idx, -1, child_list, False, 0, -1] file_dict[dir_idx] = entry dir_idx += 1 cur.append(entry) cur = child_list else: cur = cur[-1][3] self.__build_sizes(file_list) self.__fill_progress(file_list, progress) return file_list, file_dict
def build_file_list(self, torrent_files, progress, priority): """ Split file list from torrent state into a directory tree. Returns: Tuple: A list of lists in the form: [file/dir_name, index, size, children, expanded, progress, priority] Dictionary: Map of file index for fast updating of progress and priorities. """ file_list = [] file_dict = {} # directory index starts from total file count. dir_idx = len(torrent_files) for torrent_file in torrent_files: cur = file_list paths = torrent_file['path'].split('/') for path in paths: if not cur or path != cur[-1][0]: child_list = [] if path == paths[-1]: file_progress = format_progress(progress[torrent_file['index']] * 100) entry = [path, torrent_file['index'], torrent_file['size'], child_list, False, file_progress, priority[torrent_file['index']]] file_dict[torrent_file['index']] = entry else: entry = [path, dir_idx, -1, child_list, False, 0, -1] file_dict[dir_idx] = entry dir_idx += 1 cur.append(entry) cur = child_list else: cur = cur[-1][3] self.__build_sizes(file_list) self.__fill_progress(file_list, progress) return file_list, file_dict
def show_info(self, torrent_id, status, verbose=False, detailed=False): """ Writes out the torrents information to the screen. Format depends on switches given. """ self.console.set_batch_write(True) if hasattr(self.console, 'screen'): cols = self.console.screen.cols else: cols = 80 sep = ' ' if verbose or detailed: self.console.write('{!info!}Name: {!input!}%s' % (status['name'])) self.console.write('{!info!}ID: {!input!}%s' % (torrent_id)) s = '{!info!}State: %s%s' % ( colors.state_color[status['state']], status['state'], ) # Only show speed if active if status['state'] in ('Seeding', 'Downloading'): if status['state'] != 'Seeding': s += sep s += '{!info!}Down Speed: {!input!}%s' % fspeed( status['download_payload_rate'], shortform=True) s += sep s += '{!info!}Up Speed: {!input!}%s' % fspeed( status['upload_payload_rate'], shortform=True) self.console.write(s) if status['state'] in ('Seeding', 'Downloading', 'Queued'): s = '{!info!}Seeds: {!input!}%s (%s)' % ( status['num_seeds'], status['total_seeds'], ) s += sep s += '{!info!}Peers: {!input!}%s (%s)' % ( status['num_peers'], status['total_peers'], ) s += sep s += ('{!info!}Availability: {!input!}%.2f' % status['distributed_copies']) s += sep s += '{!info!}Seed Rank: {!input!}%s' % f_seedrank_dash( status['seed_rank'], status['seeding_time']) self.console.write(s) total_done = fsize(status['total_done'], shortform=True) total_size = fsize(status['total_size'], shortform=True) if total_done == total_size: s = '{!info!}Size: {!input!}%s' % (total_size) else: s = '{!info!}Size: {!input!}%s/%s' % (total_done, total_size) s += sep s += '{!info!}Downloaded: {!input!}%s' % fsize( status['all_time_download'], shortform=True) s += sep s += '{!info!}Uploaded: {!input!}%s' % fsize( status['total_uploaded'], shortform=True) s += sep s += '{!info!}Share Ratio: {!input!}%.2f' % status['ratio'] self.console.write(s) s = '{!info!}ETA: {!input!}%s' % format_time(status['eta']) s += sep s += '{!info!}Seeding: {!input!}%s' % format_time( status['seeding_time']) s += sep s += '{!info!}Active: {!input!}%s' % format_time( status['active_time']) self.console.write(s) s = '{!info!}Last Transfer: {!input!}%s' % format_time( status['time_since_transfer']) s += sep s += '{!info!}Complete Seen: {!input!}%s' % format_date_never( status['last_seen_complete']) self.console.write(s) s = '{!info!}Tracker: {!input!}%s' % status['tracker_host'] self.console.write(s) self.console.write('{!info!}Tracker status: {!input!}%s' % status['tracker_status']) if not status['is_finished']: pbar = f_progressbar( status['progress'], cols - (13 + len('%.2f%%' % status['progress']))) s = '{!info!}Progress: {!input!}%.2f%% %s' % ( status['progress'], pbar) self.console.write(s) s = '{!info!}Download Folder: {!input!}%s' % status[ 'download_location'] self.console.write(s + '\n') if detailed: self.console.write('{!info!}Files in torrent') self.show_file_info(torrent_id, status) self.console.write('{!info!}Connected peers') self.show_peer_info(torrent_id, status) else: up_color = colors.state_color['Seeding'] down_color = colors.state_color['Downloading'] s = '%s%s' % ( colors.state_color[status['state']], '[' + status['state'][0] + ']', ) s += ' {!info!}' + format_progress(status['progress']).rjust( 6, ' ') s += ' {!input!}%s' % (status['name']) # Shorten the ID if it's necessary. Pretty hacky # XXX: should make a nice function for it that can partition and shorten stuff space_left = cols - strwidth('[S] 99.99% ' + status['name']) if self.console.interactive and space_left >= len(sep + torrent_id): # Not enough line space so shorten the hash (for interactive mode). torrent_id = shorten_hash(torrent_id, space_left) s += sep s += '{!cyan!}%s' % torrent_id self.console.write(s) dl_info = '{!info!}DL: {!input!}' dl_info += '%s' % ftotal_sized(status['all_time_download'], status['total_payload_download']) if status['download_payload_rate'] > 0: dl_info += ' @ %s%s' % ( down_color, fspeed(status['download_payload_rate'], shortform=True), ) ul_info = ' {!info!}UL: {!input!}' ul_info += '%s' % ftotal_sized(status['total_uploaded'], status['total_payload_upload']) if status['upload_payload_rate'] > 0: ul_info += ' @ %s%s' % ( up_color, fspeed(status['upload_payload_rate'], shortform=True), ) eta = ' {!info!}ETA: {!magenta!}%s' % format_time(status['eta']) self.console.write(' ' + dl_info + ul_info + eta + '\n') self.console.set_batch_write(False)
def show_info(self, torrent_id, status, verbose=False, detailed=False): """ Writes out the torrents information to the screen. Format depends on switches given. """ self.console.set_batch_write(True) if hasattr(self.console, 'screen'): cols = self.console.screen.cols else: cols = 80 sep = ' ' if verbose or detailed: self.console.write('{!info!}Name: {!input!}%s' % (status['name'])) self.console.write('{!info!}ID: {!input!}%s' % (torrent_id)) s = '{!info!}State: %s%s' % (colors.state_color[status['state']], status['state']) # Only show speed if active if status['state'] in ('Seeding', 'Downloading'): if status['state'] != 'Seeding': s += sep s += '{!info!}Down Speed: {!input!}%s' % fspeed( status['download_payload_rate'], shortform=True) s += sep s += '{!info!}Up Speed: {!input!}%s' % fspeed( status['upload_payload_rate'], shortform=True) self.console.write(s) if status['state'] in ('Seeding', 'Downloading', 'Queued'): s = '{!info!}Seeds: {!input!}%s (%s)' % (status['num_seeds'], status['total_seeds']) s += sep s += '{!info!}Peers: {!input!}%s (%s)' % (status['num_peers'], status['total_peers']) s += sep s += '{!info!}Availability: {!input!}%.2f' % status['distributed_copies'] s += sep s += '{!info!}Seed Rank: {!input!}%s' % f_seedrank_dash( status['seed_rank'], status['seeding_time']) self.console.write(s) total_done = fsize(status['total_done'], shortform=True) total_size = fsize(status['total_size'], shortform=True) if total_done == total_size: s = '{!info!}Size: {!input!}%s' % (total_size) else: s = '{!info!}Size: {!input!}%s/%s' % (total_done, total_size) s += sep s += '{!info!}Downloaded: {!input!}%s' % fsize(status['all_time_download'], shortform=True) s += sep s += '{!info!}Uploaded: {!input!}%s' % fsize(status['total_uploaded'], shortform=True) s += sep s += '{!info!}Share Ratio: {!input!}%.2f' % status['ratio'] self.console.write(s) s = '{!info!}ETA: {!input!}%s' % format_time(status['eta']) s += sep s += '{!info!}Seeding: {!input!}%s' % format_time(status['seeding_time']) s += sep s += '{!info!}Active: {!input!}%s' % format_time(status['active_time']) self.console.write(s) s = '{!info!}Last Transfer: {!input!}%s' % format_time(status['time_since_transfer']) s += sep s += '{!info!}Complete Seen: {!input!}%s' % format_date_never( status['last_seen_complete']) self.console.write(s) s = '{!info!}Tracker: {!input!}%s' % status['tracker_host'] self.console.write(s) self.console.write('{!info!}Tracker status: {!input!}%s' % status['tracker_status']) if not status['is_finished']: pbar = f_progressbar(status['progress'], cols - (13 + len('%.2f%%' % status['progress']))) s = '{!info!}Progress: {!input!}%.2f%% %s' % (status['progress'], pbar) self.console.write(s) s = '{!info!}Download Folder: {!input!}%s' % status['download_location'] self.console.write(s + '\n') if detailed: self.console.write('{!info!}Files in torrent') self.show_file_info(torrent_id, status) self.console.write('{!info!}Connected peers') self.show_peer_info(torrent_id, status) else: up_color = colors.state_color['Seeding'] down_color = colors.state_color['Downloading'] s = '%s%s' % (colors.state_color[status['state']], '[' + status['state'][0] + ']') s += ' {!info!}' + format_progress(status['progress']).rjust(6, ' ') s += ' {!input!}%s' % (status['name']) # Shorten the ID if it's necessary. Pretty hacky # XXX: should make a nice function for it that can partition and shorten stuff space_left = cols - strwidth('[S] 99.99% ' + status['name']) if self.console.interactive and space_left >= len(sep + torrent_id): # Not enough line space so shorten the hash (for interactive mode). torrent_id = shorten_hash(torrent_id, space_left) s += sep s += '{!cyan!}%s' % torrent_id self.console.write(s) dl_info = '{!info!}DL: {!input!}' dl_info += '%s' % ftotal_sized(status['all_time_download'], status['total_payload_download']) if status['download_payload_rate'] > 0: dl_info += ' @ %s%s' % (down_color, fspeed( status['download_payload_rate'], shortform=True)) ul_info = ' {!info!}UL: {!input!}' ul_info += '%s' % ftotal_sized(status['total_uploaded'], status['total_payload_upload']) if status['upload_payload_rate'] > 0: ul_info += ' @ %s%s' % (up_color, fspeed( status['upload_payload_rate'], shortform=True)) eta = ' {!info!}ETA: {!magenta!}%s' % format_time(status['eta']) self.console.write(' ' + dl_info + ul_info + eta + '\n') self.console.set_batch_write(False)