mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-05 07:58:38 +00:00
* Show peer information for the 'info' command.
* The first few characters from a torrent id can be used to identify a torrent for all the commands.
This commit is contained in:
parent
3201b59c4a
commit
f24c8504e2
1 changed files with 50 additions and 18 deletions
|
@ -53,6 +53,8 @@ status_keys = ["state",
|
||||||
"files",
|
"files",
|
||||||
"file_priorities",
|
"file_priorities",
|
||||||
"file_progress",
|
"file_progress",
|
||||||
|
"peers",
|
||||||
|
"is_seed",
|
||||||
]
|
]
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
|
@ -68,6 +70,22 @@ class Command:
|
||||||
def help(self):
|
def help(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def match_torrents(self, array):
|
||||||
|
torrents = []
|
||||||
|
def _got_session_state(tors):
|
||||||
|
if not array or len(array) == 0:
|
||||||
|
for tor in tors:
|
||||||
|
torrents.append(tor)
|
||||||
|
return
|
||||||
|
for match in array:
|
||||||
|
for tor in tors:
|
||||||
|
if match == tor[0:len(match)]:
|
||||||
|
torrents.append(tor)
|
||||||
|
break
|
||||||
|
client.get_session_state(_got_session_state)
|
||||||
|
client.force_call()
|
||||||
|
return torrents
|
||||||
|
|
||||||
class CommandAdd(Command):
|
class CommandAdd(Command):
|
||||||
"""Command to add a torrent."""
|
"""Command to add a torrent."""
|
||||||
def execute(self, cmd):
|
def execute(self, cmd):
|
||||||
|
@ -171,17 +189,10 @@ class CommandHelp(Command):
|
||||||
|
|
||||||
class CommandInfo(Command):
|
class CommandInfo(Command):
|
||||||
def execute(self, cmd):
|
def execute(self, cmd):
|
||||||
torrents = []
|
brief = (len(cmd) < 2)
|
||||||
def _got_session_state(tors):
|
torrents = self.match_torrents(cmd[1:])
|
||||||
for tor in tors:
|
|
||||||
torrents.append(tor)
|
|
||||||
client.get_session_state(_got_session_state)
|
|
||||||
client.force_call()
|
|
||||||
for tor in torrents:
|
for tor in torrents:
|
||||||
if len(cmd) < 2:
|
self.show_info(tor, brief)
|
||||||
self.show_info(tor, True)
|
|
||||||
elif cmd[1] == tor[0:len(cmd[1])]:
|
|
||||||
self.show_info(tor, False)
|
|
||||||
|
|
||||||
def usage(self):
|
def usage(self):
|
||||||
print "Usage: info [<torrent-id> [<torrent-id> ...]]"
|
print "Usage: info [<torrent-id> [<torrent-id> ...]]"
|
||||||
|
@ -196,12 +207,16 @@ class CommandInfo(Command):
|
||||||
print "*** ID:", torrent
|
print "*** ID:", torrent
|
||||||
print "*** Name:", state['name']
|
print "*** Name:", state['name']
|
||||||
print "*** Path:", state['save_path']
|
print "*** Path:", state['save_path']
|
||||||
|
if not state['is_seed']:
|
||||||
print "*** Completed:", common.fsize(state['total_done']) + "/" + common.fsize(state['total_size'])
|
print "*** Completed:", common.fsize(state['total_done']) + "/" + common.fsize(state['total_size'])
|
||||||
print "*** Status:", state['state']
|
print "*** Status:", state['state']
|
||||||
if state['state'] in [3, 4, 5, 6]:
|
|
||||||
|
state['state_i'] = common.TORRENT_STATE.index(state['state'])
|
||||||
|
if state['state_i'] == 2: # Downloading
|
||||||
print "*** Download Speed:", common.fspeed(state['download_payload_rate'])
|
print "*** Download Speed:", common.fspeed(state['download_payload_rate'])
|
||||||
|
if state['state_i'] in [2, 3]: # Downloading, or Seeding
|
||||||
print "*** Upload Speed:", common.fspeed(state['upload_payload_rate'])
|
print "*** Upload Speed:", common.fspeed(state['upload_payload_rate'])
|
||||||
if state['state'] in [3, 4]:
|
if state['state_i'] == 2: # Downloading
|
||||||
print "*** ETA:", "%s" % common.ftime(state['eta'])
|
print "*** ETA:", "%s" % common.ftime(state['eta'])
|
||||||
|
|
||||||
if brief == False:
|
if brief == False:
|
||||||
|
@ -211,7 +226,21 @@ class CommandInfo(Command):
|
||||||
print "*** Availability:", "%.1f" % state['distributed_copies']
|
print "*** Availability:", "%.1f" % state['distributed_copies']
|
||||||
print "*** Files:"
|
print "*** Files:"
|
||||||
for i, file in enumerate(state['files']):
|
for i, file in enumerate(state['files']):
|
||||||
print "\t*", file['path'], "(%s)" % common.fsize(file['size']), "-", "%.1f%% completed" % (state['file_progress'][i] * 100)
|
status = ""
|
||||||
|
if not state['is_seed']:
|
||||||
|
if state['file_priorities'][i] == 0:
|
||||||
|
status = " - Do not download"
|
||||||
|
else:
|
||||||
|
status = " - %1.f%% completed" % (state['file_progress'][i] * 100)
|
||||||
|
print "\t* %s (%s)%s" % (file['path'], common.fsize(file['size']), status)
|
||||||
|
|
||||||
|
print "*** Peers:"
|
||||||
|
if len(state['peers']) == 0:
|
||||||
|
print "\t* None"
|
||||||
|
for peer in state['peers']:
|
||||||
|
print "\t* %-21s %-25s Up: %-12s Down: %-12s" % \
|
||||||
|
(peer['ip'], peer['client'] + ["", " (seed)"][not not peer['seed']],
|
||||||
|
common.fspeed(peer['up_speed']), common.fspeed(peer['down_speed']))
|
||||||
print ""
|
print ""
|
||||||
client.get_torrent_status(_got_torrent_status, torrent, status_keys)
|
client.get_torrent_status(_got_torrent_status, torrent, status_keys)
|
||||||
|
|
||||||
|
@ -221,7 +250,8 @@ class CommandPause(Command):
|
||||||
self.usage()
|
self.usage()
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
client.pause_torrent(cmd[1:])
|
torrents = self.match_torrents(cmd[1:])
|
||||||
|
client.pause_torrent(torrents)
|
||||||
except Exception, msg:
|
except Exception, msg:
|
||||||
print "Error:", str(msg), "\n"
|
print "Error:", str(msg), "\n"
|
||||||
|
|
||||||
|
@ -238,7 +268,8 @@ class CommandResume(Command):
|
||||||
self.usage()
|
self.usage()
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
client.resume_torrent(cmd[1:])
|
torrents = self.match_torrents(cmd[1:])
|
||||||
|
client.resume_torrent(torrents)
|
||||||
except Exception, msg:
|
except Exception, msg:
|
||||||
print "Error:", str(msg), "\n"
|
print "Error:", str(msg), "\n"
|
||||||
|
|
||||||
|
@ -255,7 +286,8 @@ class CommandRemove(Command):
|
||||||
self.usage()
|
self.usage()
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
client.remove_torrent(cmd, False, False)
|
torrents = self.match_torrents(cmd[1:])
|
||||||
|
client.remove_torrent(torrents, False, False)
|
||||||
except Exception, msg:
|
except Exception, msg:
|
||||||
print "*** Error:", str(msg), "\n"
|
print "*** Error:", str(msg), "\n"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue