diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index f9f80ca7a..851bdebfc 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -82,7 +82,7 @@ class Torrent(object): self.config = ConfigManager("core.conf") self.rpcserver = component.get("RPCServer") - + # This dict holds previous status dicts returned for this torrent # We use this to return dicts that only contain changes from the previous # {session_id: status_dict, ...} @@ -90,7 +90,7 @@ class Torrent(object): from twisted.internet.task import LoopingCall self.prev_status_cleanup_loop = LoopingCall(self.cleanup_prev_status) self.prev_status_cleanup_loop.start(10) - + # Set the libtorrent handle self.handle = handle # 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 # 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("session.is_paused: %s", component.get("Core").session.is_paused()) @@ -543,18 +546,18 @@ class Torrent(object): def get_status(self, keys, diff=False): """ Returns the status of the torrent based on the keys provided - + :param keys: the keys to get the status on :type keys: list of str :param diff: if True, will return a diff of the changes since the last call to get_status based on the session_id :type diff: bool - + :returns: a dictionary of the status keys and their values :rtype: dict - + """ - + # Create the full dictionary self.status = self.handle.status() if self.handle.has_metadata(): @@ -699,7 +702,7 @@ class Torrent(object): status_dict[key] = full_status[key] elif key in fns: status_dict[key] = fns[key]() - + session_id = self.rpcserver.get_session_id() if diff: if session_id in self.prev_status: @@ -711,7 +714,7 @@ class Torrent(object): status_diff[key] = value else: status_diff[key] = value - + self.prev_status[session_id] = status_dict return status_diff @@ -889,14 +892,13 @@ class Torrent(object): wait_on_folder[2].append(f["index"]) 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) - + def cleanup_prev_status(self): """ 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. - + """ for key in self.prev_status.keys(): if not self.rpcserver.is_session_valid(key): del self.prev_status[key] -