Implement 'stop seed at desired ratio'.

This commit is contained in:
Andrew Resch 2008-03-10 04:32:13 +00:00
parent e305e04e31
commit 07dd3506e1
2 changed files with 30 additions and 8 deletions

View File

@ -157,7 +157,7 @@ class Torrent:
self.state = state self.state = state
# Update the torrentqueue on any state changes # Update the torrentqueue on any state changes
self.torrentqueue._update() self.torrentqueue.update_queue()
def get_eta(self): def get_eta(self):
"""Returns the ETA in seconds for this torrent""" """Returns the ETA in seconds for this torrent"""
@ -319,6 +319,11 @@ class Torrent:
if self.state == "Paused": if self.state == "Paused":
if self.handle.is_seed(): if self.handle.is_seed():
# If the torrent has already reached it's 'stop_seed_ratio' then do not do anything
if self.config["stop_seed_at_ratio"]:
if self.get_ratio() >= self.config["stop_seed_ratio"]:
return
# If the torrent is a seed and there are already the max number of seeds # If the torrent is a seed and there are already the max number of seeds
# active, then just change it to a Queued state. # active, then just change it to a Queued state.
if self.torrentqueue.get_num_seeding() >= self.config["max_active_seeding"]: if self.torrentqueue.get_num_seeding() >= self.config["max_active_seeding"]:

View File

@ -57,8 +57,25 @@ class TorrentQueue(component.Component):
self.config.register_set_function("max_active_downloading", self.config.register_set_function("max_active_downloading",
self._on_set_max_active_downloading, False) self._on_set_max_active_downloading, False)
def _update(self): def update(self):
# If we're not checking share ratios, just return
if not self.config["stop_seed_at_ratio"]:
return
stop_ratio = self.config["stop_seed_ratio"]
for torrent_id in self.torrents.get_torrent_list():
if self.torrents[torrent_id].get_ratio() >= stop_ratio:
# This torrent is at or exceeding the stop ratio so we need to
# pause or remove it from the session.
if self.config["remove_seed_at_ratio"]:
self.torrents.remove(torrent_id, False, False)
else:
self.torrents[torrent_id].pause()
def update_queue(self):
# Updates the queueing order and max active states # Updates the queueing order and max active states
# This only gets called when necessary
self.update_state_lists() self.update_state_lists()
self.update_order() self.update_order()
self.update_max_active() self.update_max_active()
@ -239,7 +256,7 @@ class TorrentQueue(component.Component):
# Pop and insert the torrent_id at index - 1 # Pop and insert the torrent_id at index - 1
self.queue.insert(index - 1, self.queue.pop(index)) self.queue.insert(index - 1, self.queue.pop(index))
self._update() self.update_queue()
return True return True
def top(self, torrent_id): def top(self, torrent_id):
@ -257,7 +274,7 @@ class TorrentQueue(component.Component):
return False return False
self.queue.insert(0, self.queue.pop(index)) self.queue.insert(0, self.queue.pop(index))
self._update() self.update_queue()
return True return True
def down(self, torrent_id): def down(self, torrent_id):
@ -276,7 +293,7 @@ class TorrentQueue(component.Component):
# Pop and insert the torrent_id at index + 1 # Pop and insert the torrent_id at index + 1
self.queue.insert(index + 1, self.queue.pop(index)) self.queue.insert(index + 1, self.queue.pop(index))
self._update() self.update_queue()
return True return True
def bottom(self, torrent_id): def bottom(self, torrent_id):
@ -295,11 +312,11 @@ class TorrentQueue(component.Component):
# Pop and append the torrent_id # Pop and append the torrent_id
self.append(self.queue.pop(index)) self.append(self.queue.pop(index))
self._update() self.update_queue()
return True return True
def _on_set_max_active_seeding(self, key, value): def _on_set_max_active_seeding(self, key, value):
self._update() self.update_queue()
def _on_set_max_active_downloading(self, key, value): def _on_set_max_active_downloading(self, key, value):
self._update() self.update_queue()