def __refresh_rows(self): self.formatted_rows = [] for row in self.raw_rows: filename = row[0] size = row[1] time = row[2] if row[4]: if size != -1: size_str = "%i items" % size else: size_str = " unknown" try: filename = filename.decode("utf8") except: pass cols = [filename, size_str, common.fdate(time)] widths = [self.cols - 35, 12, 23] self.formatted_rows.append( format_utils.format_row(cols, widths)) else: #Size of .torrent file itself couldn't matter less so we'll leave it out try: filename = filename.decode("utf8") except: pass cols = [filename, common.fdate(time)] widths = [self.cols - 23, 23] self.formatted_rows.append( format_utils.format_row(cols, widths))
def __refresh_rows(self): self.formatted_rows = [] for row in self.raw_rows: filename = row[0] size = row[1] time = row[2] if row[4]: if size != -1: size_str = "%i items" % size else: size_str = " unknown" try: filename = filename.decode("utf8") except: pass cols = [filename, size_str, common.fdate(time)] widths = [self.cols - 35, 12, 23] self.formatted_rows.append(format_utils.format_row(cols, widths)) else: # Size of .torrent file itself couldn't matter less so we'll leave it out try: filename = filename.decode("utf8") except: pass cols = [filename, common.fdate(time)] widths = [self.cols - 23, 23] self.formatted_rows.append(format_utils.format_row(cols, widths))
def cell_data_date_or_never(column, cell, model, row, data): """Display value as date, eg 05/05/08 or Never""" value = model.get_value(row, data) if func_last_value['cell_data_date_or_never'] == value: return func_last_value['cell_data_date_or_never'] = value date_str = common.fdate(value, date_only=True) if value > 0 else _('Never') cell.set_property('text', date_str)
def cell_data_date(column, cell, model, row, data, key): """Display value as date, eg 05/05/08""" date = model.get_value(row, data) if func_last_value[key] == date: return func_last_value[key] = date date_str = common.fdate(date, date_only=True) if date > 0 else '' cell.set_property('text', date_str)
def test_fdate(self): self.assertTrue(fdate(-1) == '')
def render_header(self, off): status = self.torrent_state up_color = colors.state_color["Seeding"] down_color = colors.state_color["Downloading"] #Name s = "{!info!}Name: {!input!}%s" % status["name"] self.add_string(off, s); off += 1 #Print DL info and ETA if status["download_payload_rate"] > 0: s = "%sDownloading: {!input!}" % down_color else: s = "{!info!}Downloaded: {!input!}" s+= common.fsize(status["all_time_download"]) if status["progress"] != 100.0: s+= "/%s" % common.fsize(status["total_wanted"]) if status["download_payload_rate"] > 0: s+= " {!yellow!}@ %s%s" % (down_color, common.fsize(status["download_payload_rate"])) s+= "{!info!} ETA: {!input!}%s" % format_utils.format_time(status["eta"]) self.add_string(off, s); off += 1 #Print UL info and ratio if status["upload_payload_rate"] > 0: s = "%sUploading: {!input!}" % up_color else: s = "{!info!}Uploaded: {!input!}" s+= common.fsize(status["total_uploaded"]) if status["upload_payload_rate"] > 0: s+= " {!yellow!}@ %s%s" % (up_color, common.fsize(status["upload_payload_rate"])) ratio_str = format_utils.format_float(status["ratio"]) if ratio_str == "-": ratio_str = "inf" s+= " {!info!}Ratio: {!input!}%s" % ratio_str self.add_string(off, s); off += 1 #Seeder/leecher info s = "{!info!}Seeders:{!green!} %s {!input!}(%s)" % (status["num_seeds"], status["total_seeds"]) self.add_string(off, s); off += 1 s = "{!info!}Leechers:{!red!} %s {!input!}(%s)" % (status["num_peers"], status["total_peers"]) self.add_string(off, s); off += 1 #Tracker if status["message"] == "OK": color = "{!green!}" else: color = "{!red!}" s = "{!info!}Tracker: {!magenta!}%s{!input!} says \"%s%s{!input!}\"" % (status["tracker_host"], color, status["message"]) self.add_string(off, s); off += 1 #Pieces and availability s = "{!info!}Pieces: {!yellow!}%s {!input!}x {!yellow!}%s" % (status["num_pieces"], common.fsize(status["piece_length"])) if status["distributed_copies"]: s+= " {!info!}Availability: {!input!}%s" % format_utils.format_float(status["distributed_copies"]) self.add_string(off, s); off += 1 #Time added s = "{!info!}Added: {!input!}%s" % common.fdate(status["time_added"]) self.add_string(off, s); off += 1 #Time active s = "{!info!}Time active: {!input!}%s" % ( common.ftime(status["active_time"]) ) if status["seeding_time"]: s+= ", {!cyan!}%s{!input!} seeding" % ( common.ftime(status["seeding_time"]) ) self.add_string(off, s); off += 1 #Save Path s = "{!info!}Save path: {!input!}%s" % status["save_path"] self.add_string(off, s); off += 1 #Owner if status["owner"]: s = "{!info!}Owner: {!input!}%s" % status["owner"] return off
('queue', lambda i, s: i != -1 and str(i) or '#'), ('state', None), ('name', lambda i, s: u' %s *%s* ' % (s['state'] if s['state'].lower() not in EMOJI else EMOJI[s['state'].lower()], i)), ('total_wanted', lambda i, s: '(%s) ' % fsize(i)), ('progress', lambda i, s: '%s\n' % fpcnt(i / 100)), ('num_seeds', None), ('num_peers', None), ('total_seeds', None), ('total_peers', lambda i, s: '%s / %s seeds\n' % tuple( map(fpeer, (s['num_seeds'], s['num_peers']), (s['total_seeds'], s['total_peers'])))), ('download_payload_rate', None), ('upload_payload_rate', lambda i, s: '%s : %s\n' % tuple( map(fspeed, (s['download_payload_rate'], i)))), ('eta', lambda i, s: i > 0 and '*ETA:* %s ' % ftime(i) or ''), ('time_added', lambda i, s: '*Added:* %s' % fdate(i))) INFOS = [i[0] for i in INFO_DICT] def is_int(s): try: int(s) return True except ValueError: return False def format_torrent_info(torrent): status = torrent.get_status(INFOS) log.debug(prelog())
def render_header(self, off): status = self.torrent_state up_color = colors.state_color["Seeding"] down_color = colors.state_color["Downloading"] #Name s = "{!info!}Name: {!input!}%s" % status["name"] self.add_string(off, s) off += 1 #Print DL info and ETA if status["download_payload_rate"] > 0: s = "%sDownloading: {!input!}" % down_color else: s = "{!info!}Downloaded: {!input!}" s += common.fsize(status["all_time_download"]) if status["progress"] != 100.0: s += "/%s" % common.fsize(status["total_wanted"]) if status["download_payload_rate"] > 0: s += " {!yellow!}@ %s%s" % ( down_color, common.fsize(status["download_payload_rate"])) s += "{!info!} ETA: {!input!}%s" % format_utils.format_time( status["eta"]) self.add_string(off, s) off += 1 #Print UL info and ratio if status["upload_payload_rate"] > 0: s = "%sUploading: {!input!}" % up_color else: s = "{!info!}Uploaded: {!input!}" s += common.fsize(status["total_uploaded"]) if status["upload_payload_rate"] > 0: s += " {!yellow!}@ %s%s" % ( up_color, common.fsize(status["upload_payload_rate"])) ratio_str = format_utils.format_float(status["ratio"]) if ratio_str == "-": ratio_str = "inf" s += " {!info!}Ratio: {!input!}%s" % ratio_str self.add_string(off, s) off += 1 #Seeder/leecher info s = "{!info!}Seeders:{!green!} %s {!input!}(%s)" % ( status["num_seeds"], status["total_seeds"]) self.add_string(off, s) off += 1 s = "{!info!}Leechers:{!red!} %s {!input!}(%s)" % ( status["num_peers"], status["total_peers"]) self.add_string(off, s) off += 1 #Tracker if status["message"] == "OK": color = "{!green!}" else: color = "{!red!}" s = "{!info!}Tracker: {!magenta!}%s{!input!} says \"%s%s{!input!}\"" % ( status["tracker_host"], color, status["message"]) self.add_string(off, s) off += 1 #Pieces and availability s = "{!info!}Pieces: {!yellow!}%s {!input!}x {!yellow!}%s" % ( status["num_pieces"], common.fsize(status["piece_length"])) if status["distributed_copies"]: s += " {!info!}Availability: {!input!}%s" % format_utils.format_float( status["distributed_copies"]) self.add_string(off, s) off += 1 #Time added s = "{!info!}Added: {!input!}%s" % common.fdate(status["time_added"]) self.add_string(off, s) off += 1 #Time active s = "{!info!}Time active: {!input!}%s" % (common.ftime( status["active_time"])) if status["seeding_time"]: s += ", {!cyan!}%s{!input!} seeding" % (common.ftime( status["seeding_time"])) self.add_string(off, s) off += 1 #Save Path s = "{!info!}Save path: {!input!}%s" % status["save_path"] self.add_string(off, s) off += 1 #Owner if status["owner"]: s = "{!info!}Owner: {!input!}%s" % status["owner"] return off
def fdate_or_dash(value): """Display value as date, eg 05/05/08 or dash""" if value > 0.0: return fdate(value) else: return '-'
def fdate_or_never(value): """Display value as date, eg 05/05/08 or Never""" return fdate(value, date_only=True) if value > 0 else _('Never')
(s['state'] if s['state'].lower() not in EMOJI else EMOJI[s['state'].lower()], i)), ('total_wanted', lambda i, s: '(%s) ' % fsize(i)), ('progress', lambda i, s: '%s\n' % fpcnt(i/100)), ('num_seeds', None), ('num_peers', None), ('total_seeds', None), ('total_peers', lambda i, s: '%s / %s seeds\n' % tuple(map(fpeer, (s['num_seeds'], s['num_peers']), (s['total_seeds'], s['total_peers'])))), ('download_payload_rate', None), ('upload_payload_rate', lambda i, s: '%s : %s\n' % tuple(map(fspeed, (s['download_payload_rate'], i)))), ('eta', lambda i, s: i > 0 and '*ETA:* %s ' % ftime(i) or ''), ('time_added', lambda i, s: '*Added:* %s' % fdate(i))) INFOS = [i[0] for i in INFO_DICT] def is_int(s): try: int(s) return True except ValueError: return False def format_torrent_info(torrent): status = torrent.get_status(INFOS) log.debug(prelog())