Fix per-torrent move on completed stuff - patch from Plisk

This commit is contained in:
Andrew Resch 2009-05-02 02:07:11 +00:00
parent 32fc0db2e5
commit 5b87af0e46
4 changed files with 30 additions and 14 deletions

View File

@ -564,14 +564,14 @@ class Core(component.Component):
return self.torrentmanager[torrent_id].set_remove_at_ratio(value) return self.torrentmanager[torrent_id].set_remove_at_ratio(value)
@export @export
def set_torrent_move_on_completed(self, torrent_id, value): def set_torrent_move_completed(self, torrent_id, value):
"""Sets the torrent to be moved when completed""" """Sets the torrent to be moved when completed"""
return self.torrentmanager[torrent_id].set_move_on_completed(value) return self.torrentmanager[torrent_id].set_move_completed(value)
@export @export
def set_torrent_move_on_completed_path(self, torrent_id, value): def set_torrent_move_completed_path(self, torrent_id, value):
"""Sets the path for the torrent to be moved when completed""" """Sets the path for the torrent to be moved when completed"""
return self.torrentmanager[torrent_id].set_move_on_completed_path(value) return self.torrentmanager[torrent_id].set_move_completed_path(value)
@export @export
def block_ip_range(self, range): def block_ip_range(self, range):

View File

@ -180,6 +180,7 @@ class Torrent:
# Various torrent options # Various torrent options
self.handle.resolve_countries(True) self.handle.resolve_countries(True)
self.set_options(self.options) self.set_options(self.options)
# Status message holds error info about the torrent # Status message holds error info about the torrent
@ -272,6 +273,12 @@ class Torrent:
def set_remove_at_ratio(self, remove_at_ratio): def set_remove_at_ratio(self, remove_at_ratio):
self.options["remove_at_ratio"] = remove_at_ratio self.options["remove_at_ratio"] = remove_at_ratio
def set_move_completed(self, move_completed):
self.options["move_completed"] = move_completed
def set_move_completed_path(self, move_completed_path):
self.options["move_completed_path"] = move_completed_path
def set_file_priorities(self, file_priorities): def set_file_priorities(self, file_priorities):
if len(file_priorities) != len(self.files): if len(file_priorities) != len(self.files):
log.debug("file_priorities len != num_files") log.debug("file_priorities len != num_files")

View File

@ -73,6 +73,8 @@ class TorrentState:
stop_ratio=2.00, stop_ratio=2.00,
stop_at_ratio=False, stop_at_ratio=False,
remove_at_ratio=False, remove_at_ratio=False,
move_completed=False,
move_completed_path=None,
magnet=None, magnet=None,
time_added=-1 time_added=-1
): ):
@ -99,6 +101,8 @@ class TorrentState:
self.stop_ratio = stop_ratio self.stop_ratio = stop_ratio
self.stop_at_ratio = stop_at_ratio self.stop_at_ratio = stop_at_ratio
self.remove_at_ratio = remove_at_ratio self.remove_at_ratio = remove_at_ratio
self.move_completed = move_completed
self.move_completed_path = move_completed_path
class TorrentManagerState: class TorrentManagerState:
def __init__(self): def __init__(self):
@ -296,6 +300,8 @@ class TorrentManager(component.Component):
options["compact_allocation"] = state.compact options["compact_allocation"] = state.compact
options["download_location"] = state.save_path options["download_location"] = state.save_path
options["auto_managed"] = state.auto_managed options["auto_managed"] = state.auto_managed
options["move_completed"] = state.move_completed
options["move_completed_path"] = state.move_completed_path
options["add_paused"] = state.paused options["add_paused"] = state.paused
if not state.magnet: if not state.magnet:
@ -477,10 +483,11 @@ class TorrentManager(component.Component):
# Try to use an old state # Try to use an old state
try: try:
if dir(state.torrents[0]) != dir(TorrentState()): state_tmp = TorrentState()
for attr in (set(dir(TorrentState())) - set(dir(state.torrents[0]))): if dir(state.torrents[0]) != dir(state_tmp):
for attr in (set(dir(state_tmp)) - set(dir(state.torrents[0]))):
for s in state.torrents: for s in state.torrents:
setattr(s, attr, getattr(TorrentState(), attr, None)) setattr(s, attr, getattr(state_tmp, attr, None))
except Exception, e: except Exception, e:
log.warning("Unable to update state file to a compatible version: %s", e) log.warning("Unable to update state file to a compatible version: %s", e)
@ -533,6 +540,8 @@ class TorrentManager(component.Component):
torrent.options["stop_ratio"], torrent.options["stop_ratio"],
torrent.options["stop_at_ratio"], torrent.options["stop_at_ratio"],
torrent.options["remove_at_ratio"], torrent.options["remove_at_ratio"],
torrent.options["move_completed"],
torrent.options["move_completed_path"],
torrent.magnet, torrent.magnet,
torrent.time_added torrent.time_added
) )

View File

@ -165,13 +165,13 @@ class OptionsTab(Tab):
if self.chk_remove_at_ratio.get_active() != self.prev_status["remove_at_ratio"]: if self.chk_remove_at_ratio.get_active() != self.prev_status["remove_at_ratio"]:
client.core.set_torrent_remove_at_ratio(self.prev_torrent_id, self.chk_remove_at_ratio.get_active()) client.core.set_torrent_remove_at_ratio(self.prev_torrent_id, self.chk_remove_at_ratio.get_active())
if self.chk_move_completed.get_active() != self.prev_status["move_on_completed"]: if self.chk_move_completed.get_active() != self.prev_status["move_on_completed"]:
client.core.set_torrent_move_on_completed(self.prev_torrent_id, self.chk_move_completed.get_active()) client.core.set_torrent_move_completed(self.prev_torrent_id, self.chk_move_completed.get_active())
if self.chk_move_completed.get_active(): if self.chk_move_completed.get_active():
if client.is_localhost(): if client.is_localhost():
path = self.filechooser_move_completed.get_current_folder() path = self.filechooser_move_completed.get_current_folder()
else: else:
path = self.entry_move_completed.get_text() path = self.entry_move_completed.get_text()
client.core.set_torrent_move_on_completed_path(self.prev_torrent_id, path) client.core.set_torrent_move_completed_path(self.prev_torrent_id, path)
def _on_button_edit_trackers_clicked(self, button): def _on_button_edit_trackers_clicked(self, button):