mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-05 16:08:40 +00:00
get_torrent_status() now takes a list of keys and only returns the
values for those keys.
This commit is contained in:
parent
bb299f4e97
commit
bcf70c3e0f
7 changed files with 882 additions and 865 deletions
|
@ -129,19 +129,15 @@ class Core(dbus.service.Object):
|
||||||
self.torrent_paused(torrent_id)
|
self.torrent_paused(torrent_id)
|
||||||
|
|
||||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
||||||
in_signature="s", out_signature="ay")
|
in_signature="sas",
|
||||||
def get_torrent_info(self, torrent_id):
|
|
||||||
# Pickle the info dictionary from the torrent and return it
|
|
||||||
info = self.torrents[torrent_id].get_info()
|
|
||||||
info = pickle.dumps(info)
|
|
||||||
return info
|
|
||||||
|
|
||||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
|
||||||
in_signature="s",
|
|
||||||
out_signature="ay")
|
out_signature="ay")
|
||||||
def get_torrent_status(self, torrent_id):
|
def get_torrent_status(self, torrent_id, keys):
|
||||||
|
# Convert the array of strings to a python list of strings
|
||||||
|
nkeys = []
|
||||||
|
for key in keys:
|
||||||
|
nkeys.append(str(key))
|
||||||
# Pickle the status dictionary from the torrent and return it
|
# Pickle the status dictionary from the torrent and return it
|
||||||
status = self.torrents[torrent_id].get_status()
|
status = self.torrents[torrent_id].get_status(nkeys)
|
||||||
status = pickle.dumps(status)
|
status = pickle.dumps(status)
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
|
@ -71,21 +71,15 @@ class Torrent:
|
||||||
|
|
||||||
return eta
|
return eta
|
||||||
|
|
||||||
def get_info(self):
|
def get_status(self, keys):
|
||||||
"""Returns the torrents info.. stuff that remains constant, such as
|
"""Returns the status of the torrent based on the keys provided"""
|
||||||
name."""
|
# Create the full dictionary
|
||||||
|
|
||||||
return {
|
|
||||||
"name": self.handle.torrent_info().name(),
|
|
||||||
"total_size": self.handle.torrent_info().total_size(),
|
|
||||||
"num_pieces": self.handle.status().num_pieces
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_status(self):
|
|
||||||
"""Returns the torrent status"""
|
|
||||||
status = self.handle.status()
|
status = self.handle.status()
|
||||||
|
|
||||||
return {
|
full_status = {
|
||||||
|
"name": self.handle.torrent_info().name(),
|
||||||
|
"total_size": self.handle.torrent_info().total_size(),
|
||||||
|
"num_pieces": self.handle.status().num_pieces,
|
||||||
"state": int(status.state),
|
"state": int(status.state),
|
||||||
"paused": status.paused,
|
"paused": status.paused,
|
||||||
"progress": status.progress,
|
"progress": status.progress,
|
||||||
|
@ -100,3 +94,12 @@ class Torrent:
|
||||||
"eta": self.get_eta(),
|
"eta": self.get_eta(),
|
||||||
"queue": self.queue[self.torrent_id]
|
"queue": self.queue[self.torrent_id]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Create the desired status dictionary and return it
|
||||||
|
status_dict = {}
|
||||||
|
|
||||||
|
for key in keys:
|
||||||
|
if key in full_status:
|
||||||
|
status_dict[key] = full_status[key]
|
||||||
|
|
||||||
|
return status_dict
|
||||||
|
|
|
@ -134,6 +134,9 @@ class TorrentManager:
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def resume(self, torrent_id):
|
||||||
|
pass
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
"""Save the state of the TorrentManager to the torrents.state file"""
|
"""Save the state of the TorrentManager to the torrents.state file"""
|
||||||
state = TorrentManagerState()
|
state = TorrentManagerState()
|
||||||
|
|
|
@ -134,9 +134,9 @@ def get_torrent_info(core, torrent_id):
|
||||||
info = pickle.loads(info)
|
info = pickle.loads(info)
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def get_torrent_status(core, torrent_id):
|
def get_torrent_status(core, torrent_id, keys):
|
||||||
"""Builds the status dictionary and returns it"""
|
"""Builds the status dictionary and returns it"""
|
||||||
status = core.get_torrent_status(torrent_id)
|
status = core.get_torrent_status(torrent_id, keys)
|
||||||
# Join the array of bytes into a string for pickle to read
|
# Join the array of bytes into a string for pickle to read
|
||||||
status = "".join(chr(b) for b in status)
|
status = "".join(chr(b) for b in status)
|
||||||
# De-serialize the object
|
# De-serialize the object
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,6 +25,7 @@
|
||||||
<property name="tooltip" translatable="yes">Resume selected torrents.</property>
|
<property name="tooltip" translatable="yes">Resume selected torrents.</property>
|
||||||
<property name="label" translatable="yes">Resu_me</property>
|
<property name="label" translatable="yes">Resu_me</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
|
<signal name="activate" handler="on_menuitem_resume_activate"/>
|
||||||
<child internal-child="image">
|
<child internal-child="image">
|
||||||
<widget class="GtkImage" id="menu-item-image13">
|
<widget class="GtkImage" id="menu-item-image13">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|
|
@ -153,11 +153,15 @@ class TorrentView:
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the view, this is likely called by a timer"""
|
"""Update the view, this is likely called by a timer"""
|
||||||
|
|
||||||
# This function is used for the foreach method of the treemodel
|
# This function is used for the foreach method of the treemodel
|
||||||
def update_row(model, path, row, user_data):
|
def update_row(model, path, row, user_data):
|
||||||
torrent_id = self.torrent_model.get_value(row, 0)
|
torrent_id = self.torrent_model.get_value(row, 0)
|
||||||
status = functions.get_torrent_status(self.core, torrent_id)
|
status_keys = ["queue", "progress", "state", "num_seeds",
|
||||||
|
"num_peers", "download_payload_rate", "upload_payload_rate",
|
||||||
|
"eta"]
|
||||||
|
status = functions.get_torrent_status(self.core, torrent_id,
|
||||||
|
status_keys)
|
||||||
|
|
||||||
# Set values for each column in the row
|
# Set values for each column in the row
|
||||||
self.torrent_model.set_value(row, TORRENT_VIEW_COL_QUEUE,
|
self.torrent_model.set_value(row, TORRENT_VIEW_COL_QUEUE,
|
||||||
status["queue"]+1)
|
status["queue"]+1)
|
||||||
|
@ -186,16 +190,18 @@ class TorrentView:
|
||||||
def add_row(self, torrent_id):
|
def add_row(self, torrent_id):
|
||||||
"""Adds a new torrent row to the treeview"""
|
"""Adds a new torrent row to the treeview"""
|
||||||
# Get the status and info dictionaries
|
# Get the status and info dictionaries
|
||||||
status = functions.get_torrent_status(self.core, torrent_id)
|
status_keys = ["queue", "name", "total_size", "progress", "state",
|
||||||
info = functions.get_torrent_info(self.core, torrent_id)
|
"num_seeds", "num_peers", "download_payload_rate",
|
||||||
|
"upload_payload_rate", "eta"]
|
||||||
|
status = functions.get_torrent_status(self.core, torrent_id,
|
||||||
|
status_keys)
|
||||||
# Insert the row with info provided from core
|
# Insert the row with info provided from core
|
||||||
self.torrent_model.insert(status["queue"], [
|
self.torrent_model.insert(status["queue"], [
|
||||||
torrent_id,
|
torrent_id,
|
||||||
status["queue"]+1,
|
status["queue"]+1,
|
||||||
None,
|
None,
|
||||||
info["name"],
|
status["name"],
|
||||||
info["total_size"],
|
status["total_size"],
|
||||||
status["progress"]*100,
|
status["progress"]*100,
|
||||||
status["state"],
|
status["state"],
|
||||||
status["num_seeds"],
|
status["num_seeds"],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue