Fix up info command

This commit is contained in:
Andrew Resch 2009-04-24 18:50:54 +00:00
parent 4939b8c72e
commit 972393d9ea
1 changed files with 64 additions and 39 deletions

View File

@ -24,6 +24,7 @@
# #
from optparse import make_option from optparse import make_option
import sys
from deluge.ui.console.main import BaseCommand from deluge.ui.console.main import BaseCommand
import deluge.ui.console.colors as colors import deluge.ui.console.colors as colors
@ -55,9 +56,29 @@ status_keys = ["state",
"file_progress", "file_progress",
"peers", "peers",
"is_seed", "is_seed",
"is_finished"
] ]
def format_progressbar(progress, width):
"""
Returns a string of a progress bar.
:param progress: float, a value between 0-100
:returns: str, a progress bar based on width
"""
w = width - 2 # we use a [] for the beginning and end
s = "["
p = int(round((progress/100) * w))
s += "#" * p
s += "~" * (w - p)
s += "]"
return s
class Command(BaseCommand): class Command(BaseCommand):
"""Show information about the torrents""" """Show information about the torrents"""
@ -116,50 +137,54 @@ class Command(BaseCommand):
self.console.write(s) self.console.write(s)
if status["state"] in ("Seeding", "Downloading", "Queued"):
s = "{{info}}Seeds: {{input}}%s (%s)" % (status["num_seeds"], status["total_seeds"]) s = "{{info}}Seeds: {{input}}%s (%s)" % (status["num_seeds"], status["total_seeds"])
s += " {{info}}Peers: {{input}}%s (%s)" % (status["num_peers"], status["total_peers"]) s += " {{info}}Peers: {{input}}%s (%s)" % (status["num_peers"], status["total_peers"])
s += " {{info}}Ratio: {{input}}%.3f" % status["ratio"]
s += " {{info}}Availibility: {{input}}%.2f" % status["distributed_copies"] s += " {{info}}Availibility: {{input}}%.2f" % status["distributed_copies"]
self.console.write(s) self.console.write(s)
s = "{{info}}Size: {{input}}%s/%s" % (common.fsize(status["total_done"]), common.fsize(status["total_size"]))
s += " {{info}}Ratio: {{input}}%.3f" % status["ratio"]
self.console.write(s)
""" def __show_info(self, torrent, verbose): if not status["is_finished"]:
def _got_torrent_status(state): pbar = format_progressbar(status["progress"], self.console.screen.cols - (13 + len("%.2f%%" % status["progress"])))
s = "{{info}}Progress: {{input}}%.2f%% %s" % (status["progress"], pbar)
self.console.write(s)
if verbose or not state['is_seed']:
print templates.info_transfers("Completed", common.fsize(state['total_done']) + "/" + common.fsize(state['total_size']))
print templates.info_transfers("Status", state['state'])
if verbose or state['state'] == 'Downloading':
print templates.info_transfers("Download Speed", common.fspeed(state['download_payload_rate']))
if verbose or state['state'] in ('Downloading', 'Seeding'):
print templates.info_transfers("Upload Speed", common.fspeed(state['upload_payload_rate']))
print templates.info_transfers("Share Ratio", "%.1f" % state['ratio'])
if state['state'] == ('Downloading'):
print templates.info_transfers("ETA", common.ftime(state['eta']))
if verbose: if verbose:
print templates.info_network("Seeders", "%s (%s)" % (state['num_seeds'], state['total_seeds'])) self.console.write(" {{info}}::Files")
print templates.info_network("Peers", "%s (%s)" % (state['num_peers'], state['total_peers'])) for i, f in enumerate(status["files"]):
print templates.info_network("Availability", "%.1f" % state['distributed_copies']) s = " {{input}}%s (%s)" % (f["path"], common.fsize(f["size"]))
print templates.info_files_header("Files") s += " {{info}}Progress: {{input}}%.2f%%" % (status["file_progress"][i] * 100)
for i, file in enumerate(state['files']): s += " {{info}}Priority:"
status = "" fp = common.FILE_PRIORITY[status["file_priorities"][i]].replace("Priority", "")
if not state['is_seed']: if fp == "Do Not Download":
if state['file_priorities'][i] == 0: s += "{{error}}"
status = " - Do not download"
else: else:
status = " - %1.f%% completed" % (state['file_progress'][i] * 100) s += "{{success}}"
print "\t* %s (%s)%s" % (file['path'], common.fsize(file['size']), status)
print templates.info_peers_header("Peers") s += " %s" % (fp)
if len(state['peers']) == 0: self.console.write(s)
print "\t* None"
for peer in state['peers']: self.console.write(" {{info}}::Peers")
client_str = unicode(peer['client']) if len(status["peers"]) == 0:
client_str += unicode(peer['seed']) if peer['seed'] else '' self.console.write(" None")
print templates.info_peers(str(peer['ip']), unicode(client_str), else:
str(common.fspeed(peer['up_speed'])), str(common.fspeed(peer['down_speed']))) s = ""
print "" for peer in status["peers"]:
client.core.get_torrent_status(torrent, status_keys).addCallback(_got_torrent_status) if peer["seed"]:
""" s += "%sSeed{{input}}" % colors.state_color["Seeding"]
else:
s += "%sPeer{{input}}" % colors.state_color["Downloading"]
s += " " + peer["country"]
s += " " + peer["ip"]
s += "\t" + peer["client"].encode(sys.getdefaultencoding(), "replace")
s += "{{input}}\t%s\t%s" % (common.fspeed(peer["up_speed"]), common.fspeed(peer["down_speed"]))
s += "\n"
self.console.write(s[:-1])