Use torrent state name instead of number if available

This commit is contained in:
Andrew Resch 2010-07-02 18:09:21 -07:00
parent 504751424f
commit 3cd30ea96a
1 changed files with 14 additions and 12 deletions

View File

@ -82,7 +82,7 @@ class Torrent(object):
self.config = ConfigManager("core.conf") self.config = ConfigManager("core.conf")
self.rpcserver = component.get("RPCServer") self.rpcserver = component.get("RPCServer")
# This dict holds previous status dicts returned for this torrent # This dict holds previous status dicts returned for this torrent
# We use this to return dicts that only contain changes from the previous # We use this to return dicts that only contain changes from the previous
# {session_id: status_dict, ...} # {session_id: status_dict, ...}
@ -90,7 +90,7 @@ class Torrent(object):
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
self.prev_status_cleanup_loop = LoopingCall(self.cleanup_prev_status) self.prev_status_cleanup_loop = LoopingCall(self.cleanup_prev_status)
self.prev_status_cleanup_loop.start(10) self.prev_status_cleanup_loop.start(10)
# Set the libtorrent handle # Set the libtorrent handle
self.handle = handle self.handle = handle
# Set the torrent_id for this torrent # Set the torrent_id for this torrent
@ -341,7 +341,10 @@ class Torrent(object):
# Set self.state to the ltstate right away just incase we don't hit some # Set self.state to the ltstate right away just incase we don't hit some
# of the logic below # of the logic below
self.state = str(ltstate) if ltstate in LTSTATE:
self.state = LTSTATE[ltstate]
else:
self.state = str(ltstate)
log.debug("set_state_based_on_ltstate: %s", deluge.common.LT_TORRENT_STATE[ltstate]) log.debug("set_state_based_on_ltstate: %s", deluge.common.LT_TORRENT_STATE[ltstate])
log.debug("session.is_paused: %s", component.get("Core").session.is_paused()) log.debug("session.is_paused: %s", component.get("Core").session.is_paused())
@ -543,18 +546,18 @@ class Torrent(object):
def get_status(self, keys, diff=False): def get_status(self, keys, diff=False):
""" """
Returns the status of the torrent based on the keys provided Returns the status of the torrent based on the keys provided
:param keys: the keys to get the status on :param keys: the keys to get the status on
:type keys: list of str :type keys: list of str
:param diff: if True, will return a diff of the changes since the last :param diff: if True, will return a diff of the changes since the last
call to get_status based on the session_id call to get_status based on the session_id
:type diff: bool :type diff: bool
:returns: a dictionary of the status keys and their values :returns: a dictionary of the status keys and their values
:rtype: dict :rtype: dict
""" """
# Create the full dictionary # Create the full dictionary
self.status = self.handle.status() self.status = self.handle.status()
if self.handle.has_metadata(): if self.handle.has_metadata():
@ -699,7 +702,7 @@ class Torrent(object):
status_dict[key] = full_status[key] status_dict[key] = full_status[key]
elif key in fns: elif key in fns:
status_dict[key] = fns[key]() status_dict[key] = fns[key]()
session_id = self.rpcserver.get_session_id() session_id = self.rpcserver.get_session_id()
if diff: if diff:
if session_id in self.prev_status: if session_id in self.prev_status:
@ -711,7 +714,7 @@ class Torrent(object):
status_diff[key] = value status_diff[key] = value
else: else:
status_diff[key] = value status_diff[key] = value
self.prev_status[session_id] = status_dict self.prev_status[session_id] = status_dict
return status_diff return status_diff
@ -889,14 +892,13 @@ class Torrent(object):
wait_on_folder[2].append(f["index"]) wait_on_folder[2].append(f["index"])
self.handle.rename_file(f["index"], f["path"].replace(folder, new_folder, 1).encode("utf-8")) self.handle.rename_file(f["index"], f["path"].replace(folder, new_folder, 1).encode("utf-8"))
self.waiting_on_folder_rename.append(wait_on_folder) self.waiting_on_folder_rename.append(wait_on_folder)
def cleanup_prev_status(self): def cleanup_prev_status(self):
""" """
This method gets called to check the validity of the keys in the prev_status This method gets called to check the validity of the keys in the prev_status
dict. If the key is no longer valid, the dict will be deleted. dict. If the key is no longer valid, the dict will be deleted.
""" """
for key in self.prev_status.keys(): for key in self.prev_status.keys():
if not self.rpcserver.is_session_valid(key): if not self.rpcserver.is_session_valid(key):
del self.prev_status[key] del self.prev_status[key]