Modified the info command to be more compact and concise by default, old behavior(with tracker and save location info added) moved to -v switch, old verbose mode(files and peers) moved to -d switch
This commit is contained in:
parent
1391f20658
commit
ced1475233
|
@ -98,19 +98,20 @@ class Command(BaseCommand):
|
|||
option_list = BaseCommand.option_list + (
|
||||
make_option('-v', '--verbose', action='store_true', default=False, dest='verbose',
|
||||
help='shows more information per torrent'),
|
||||
make_option('-i', '--id', action='store_true', default=False, dest='tid',
|
||||
help='use internal id instead of torrent name'),
|
||||
make_option('-d', '--detailed', action='store_true', default=False, dest='detailed',
|
||||
help='shows detailed information about files and peers. '
|
||||
"Implies -v"),
|
||||
make_option('-s', '--state', action='store', dest='state',
|
||||
help="Only retrieve torrents in state STATE. "
|
||||
"Allowable values are: %s "%(", ".join(states))),
|
||||
)
|
||||
|
||||
usage = "Usage: info [-v | -i | -s <state>] [<torrent-id> [<torrent-id> ...]]\n"\
|
||||
usage = "Usage: info [-v | -d | -s <state>] [<torrent-id> [<torrent-id> ...]]\n"\
|
||||
" use -v to view more info and -d to view detailed information"\
|
||||
" about files and peers."\
|
||||
" info -s <state> will show only torrents in state <state>\n"\
|
||||
" You can give the first few characters of a torrent-id to identify the torrent."
|
||||
|
||||
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.console = component.get("ConsoleUI")
|
||||
# Compile a list of torrent_ids to request the status of
|
||||
|
@ -124,7 +125,7 @@ class Command(BaseCommand):
|
|||
def on_torrents_status(status):
|
||||
# Print out the information for each torrent
|
||||
for key, value in status.items():
|
||||
self.show_info(key, value, options["verbose"])
|
||||
self.show_info(key, value, options["verbose"], options["detailed"])
|
||||
|
||||
def on_torrents_status_fail(reason):
|
||||
self.console.write("{!error!}Error getting torrent info: %s" % reason)
|
||||
|
@ -144,18 +145,20 @@ class Command(BaseCommand):
|
|||
d.addErrback(on_torrents_status_fail)
|
||||
return d
|
||||
|
||||
def show_info(self, torrent_id, status, verbose=False):
|
||||
def show_info(self, torrent_id, status, verbose=False, detailed=False):
|
||||
"""
|
||||
Writes out the torrents information to the screen.
|
||||
|
||||
:param torrent_id: str, the torrent_id
|
||||
:param status: dict, the torrents status, this should have the same keys
|
||||
as status_keys
|
||||
:param verbose: bool, if true, we print out more information about the
|
||||
the torrent
|
||||
Format depends on switches given.
|
||||
"""
|
||||
self.console.set_batch_write(True)
|
||||
|
||||
if hasattr(self.console, "screen"):
|
||||
cols = self.console.screen.cols
|
||||
else:
|
||||
cols = 80
|
||||
|
||||
if verbose or detailed:
|
||||
self.console.write(" ")
|
||||
self.console.write("{!info!}Name: {!input!}%s" % (status["name"]))
|
||||
self.console.write("{!info!}ID: {!input!}%s" % (torrent_id))
|
||||
|
@ -177,22 +180,29 @@ class Command(BaseCommand):
|
|||
s += " {!info!}Availibility: {!input!}%.2f" % status["distributed_copies"]
|
||||
self.console.write(s)
|
||||
|
||||
s = "{!info!}Size: {!input!}%s/%s" % (common.fsize(status["total_done"]), common.fsize(status["total_size"]))
|
||||
total_done = common.fsize(status["total_done"])
|
||||
total_size = common.fsize(status["total_size"])
|
||||
if total_done == total_size:
|
||||
s = "{!info!}Size: {!input!}%s" % (total_size)
|
||||
else:
|
||||
s = "{!info!}Size: {!input!}%s/%s" % (total_done, total_size)
|
||||
s += " {!info!}Ratio: {!input!}%.3f" % status["ratio"]
|
||||
s += " {!info!}Uploaded: {!input!}%s" % common.fsize(status["ratio"] * status["total_done"])
|
||||
self.console.write(s)
|
||||
|
||||
if not status["is_finished"]:
|
||||
if hasattr(self.console, "screen"):
|
||||
cols = self.console.screen.cols
|
||||
else:
|
||||
cols = 80
|
||||
s = "{!info!}Tracker: {!input!}%s" % status["tracker"]
|
||||
self.console.write(s)
|
||||
|
||||
|
||||
if not status["is_finished"]:
|
||||
pbar = format_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 location: {!input!}%s" % status["save_path"]
|
||||
self.console.write(s)
|
||||
|
||||
if verbose:
|
||||
if detailed:
|
||||
self.console.write(" {!info!}::Files")
|
||||
for i, f in enumerate(status["files"]):
|
||||
s = " {!input!}%s (%s)" % (f["path"], common.fsize(f["size"]))
|
||||
|
@ -249,7 +259,57 @@ class Command(BaseCommand):
|
|||
s += "\n"
|
||||
|
||||
self.console.write(s[:-1])
|
||||
else:
|
||||
self.console.write(" ")
|
||||
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!}" + ("%.2f%%" % status["progress"]).ljust(7, " ")
|
||||
s+= " {!input!}%s" % (status["name"])
|
||||
|
||||
#Shorten the ID if it's necessary. Pretty hacky
|
||||
#I _REALLY_ should make a nice function for it that can partition and shorten stuff
|
||||
space_left = cols - len("[s] 100.00% " + status["name"] + " "*3) - 2
|
||||
if space_left >= len(torrent_id):
|
||||
#There's enough space, print it
|
||||
s += " {!cyan!}%s" % torrent_id
|
||||
else:
|
||||
#Shorten the ID
|
||||
a = int(space_left * 2/3.0)
|
||||
b = space_left - a
|
||||
if a < 8:
|
||||
b = b - (8-a)
|
||||
a = 8
|
||||
if b < 0:
|
||||
a+= b
|
||||
b = 0
|
||||
if a > 0:
|
||||
#Print the shortened ID
|
||||
s += " {!cyan!}%s" % (torrent_id[0:a] + ".." + torrent_id[-b-1:-1])
|
||||
else:
|
||||
#It has wrapped over to the second row anyway
|
||||
s += " {!cyan!}%s" % torrent_id
|
||||
self.console.write(s)
|
||||
|
||||
dl_info = "{!info!}DL: {!input!}"
|
||||
dl_info+= "%s" % common.fsize(status["total_done"])
|
||||
if status["total_done"] != status["total_size"]:
|
||||
dl_info+= "/%s" % common.fsize(status["total_size"])
|
||||
if status["download_payload_rate"] > 0:
|
||||
dl_info += " @ %s%s" % (down_color, common.fspeed(status["download_payload_rate"]))
|
||||
|
||||
ul_info = " {!info!}UL: {!input!}"
|
||||
ul_info+= "%s" % common.fsize(status["ratio"] * status["total_done"])
|
||||
if status["upload_payload_rate"] > 0:
|
||||
ul_info += " @ %s%s" % (up_color, common.fspeed(status["upload_payload_rate"]))
|
||||
|
||||
eta = ""
|
||||
if common.ftime(status["eta"]):
|
||||
eta = " {!info!}ETA: {!magenta!}%s" % common.ftime(status["eta"])
|
||||
|
||||
self.console.write(" " + dl_info + ul_info + eta)
|
||||
self.console.set_batch_write(False)
|
||||
|
||||
def complete(self, line):
|
||||
|
|
Loading…
Reference in New Issue