Add 'tracker_host' torrent status key
This commit is contained in:
parent
a731da429b
commit
9930a311e7
|
@ -34,6 +34,7 @@
|
|||
"""Internal Torrent class"""
|
||||
|
||||
import os
|
||||
from urlparse import urlparse
|
||||
|
||||
import deluge.libtorrent as lt
|
||||
import deluge.common
|
||||
|
@ -378,6 +379,21 @@ class Torrent:
|
|||
|
||||
return ret
|
||||
|
||||
def get_tracker_host(self):
|
||||
"""Returns just the hostname of the currently connected tracker"""
|
||||
if not self.status:
|
||||
self.status = self.handle.status()
|
||||
|
||||
if self.status.current_tracker:
|
||||
url = urlparse(self.status.current_tracker)
|
||||
if hasattr(url, "hostname"):
|
||||
host = (url.hostname or 'unknown?')
|
||||
parts = host.split(".")
|
||||
if len(parts) > 2:
|
||||
host = ".".join(parts[-2:])
|
||||
return host
|
||||
return ""
|
||||
|
||||
def get_status(self, keys):
|
||||
"""Returns the status of the torrent based on the keys provided"""
|
||||
# Create the full dictionary
|
||||
|
@ -445,6 +461,7 @@ class Torrent:
|
|||
"queue": self.handle.queue_position,
|
||||
"is_seed": self.handle.is_seed,
|
||||
"peers": self.get_peers,
|
||||
"tracker_host": self.get_tracker_host
|
||||
}
|
||||
|
||||
self.status = None
|
||||
|
|
|
@ -100,20 +100,6 @@ def cell_data_queue(column, cell, model, row, data):
|
|||
else:
|
||||
cell.set_property("text", value + 1)
|
||||
|
||||
def cell_data_tracker(column, cell, model, row, data):
|
||||
value = model.get_value(row, data)
|
||||
if value:
|
||||
url = urlparse(value)
|
||||
if hasattr(url, "hostname"):
|
||||
host = (url.hostname or 'unknown?')
|
||||
parts = host.split(".")
|
||||
if len(parts) > 2:
|
||||
host = ".".join(parts[-2:])
|
||||
cell.set_property("text", host)
|
||||
return
|
||||
|
||||
cell.set_property("text", "")
|
||||
|
||||
class TorrentView(listview.ListView, component.Component):
|
||||
"""TorrentView handles the listing of torrents."""
|
||||
def __init__(self):
|
||||
|
@ -179,11 +165,8 @@ class TorrentView(listview.ListView, component.Component):
|
|||
listview.cell_data_ratio,
|
||||
[float],
|
||||
status_field=["distributed_copies"])
|
||||
self.add_text_column(_("Tracker"), status_field=["tracker_host"])
|
||||
|
||||
self.add_func_column(_("Tracker"),
|
||||
cell_data_tracker,
|
||||
[str],
|
||||
status_field=["tracker"])
|
||||
# Set default sort column to #
|
||||
self.liststore.set_sort_column_id(self.get_column_index("#"), gtk.SORT_ASCENDING)
|
||||
|
||||
|
|
Loading…
Reference in New Issue