diff --git a/ChangeLog b/ChangeLog index df7a83232..46956e581 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,7 @@ * Authentication no longer requires a username/password. If one or both of these is missing, an authentication error will be sent to the client which sould then ask the username/password to the user. + * Implemented sequential downloads. ==== GtkUI ==== * Fix uncaught exception when closing deluge in classic mode diff --git a/deluge/core/core.py b/deluge/core/core.py index 716fdbcc3..d70160759 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -564,6 +564,11 @@ class Core(component.Component): """Sets a higher priority to the first and last pieces""" return self.torrentmanager[torrent_id].set_prioritize_first_last(value) + @export + def set_torrent_sequential_download(self, torrent_id, value): + """Toggle sequencial pieces download""" + return self.torrentmanager[torrent_id].set_sequential_download(value) + @export def set_torrent_auto_managed(self, torrent_id, value): """Sets the auto managed flag for queueing purposes""" diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index ba1d2294b..743d3ea6a 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -63,6 +63,7 @@ DEFAULT_PREFS = { "torrentfiles_location": deluge.common.get_default_download_dir(), "plugins_location": os.path.join(deluge.configmanager.get_config_dir(), "plugins"), "prioritize_first_last_pieces": False, + "sequential_download": False, "random_port": True, "dht": True, "upnp": True, diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index d9e9b7bc5..5db3a4c67 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -55,22 +55,23 @@ class TorrentOptions(dict): def __init__(self): config = ConfigManager("core.conf").config options_conf_map = { - "max_connections": "max_connections_per_torrent", - "max_upload_slots": "max_upload_slots_per_torrent", - "max_upload_speed": "max_upload_speed_per_torrent", - "max_download_speed": "max_download_speed_per_torrent", - "prioritize_first_last_pieces": "prioritize_first_last_pieces", - "compact_allocation": "compact_allocation", - "download_location": "download_location", - "auto_managed": "auto_managed", - "stop_at_ratio": "stop_seed_at_ratio", - "stop_ratio": "stop_seed_ratio", - "remove_at_ratio": "remove_seed_at_ratio", - "move_completed": "move_completed", - "move_completed_path": "move_completed_path", - "add_paused": "add_paused", - "shared": "shared" - } + "max_connections": "max_connections_per_torrent", + "max_upload_slots": "max_upload_slots_per_torrent", + "max_upload_speed": "max_upload_speed_per_torrent", + "max_download_speed": "max_download_speed_per_torrent", + "prioritize_first_last_pieces": "prioritize_first_last_pieces", + "sequential_download": "sequential_download", + "compact_allocation": "compact_allocation", + "download_location": "download_location", + "auto_managed": "auto_managed", + "stop_at_ratio": "stop_seed_at_ratio", + "stop_ratio": "stop_seed_ratio", + "remove_at_ratio": "remove_seed_at_ratio", + "move_completed": "move_completed", + "move_completed_path": "move_completed_path", + "add_paused": "add_paused", + "shared": "shared" + } for opt_k, conf_k in options_conf_map.iteritems(): self[opt_k] = config[conf_k] self["file_priorities"] = [] @@ -212,7 +213,9 @@ class Torrent(object): "max_download_speed": self.set_max_download_speed, "max_upload_slots": self.handle.set_max_uploads, "max_upload_speed": self.set_max_upload_speed, - "prioritize_first_last_pieces": self.set_prioritize_first_last + "prioritize_first_last_pieces": self.set_prioritize_first_last, + "sequential_download": self.set_sequential_download + } for (key, value) in options.items(): if OPTIONS_FUNCS.has_key(key): @@ -273,6 +276,10 @@ class Torrent(object): priorities[piece] = prioritize and 7 or 1 self.handle.prioritize_pieces(priorities) + def set_sequential_download(self, set_sequencial): + self.options["sequential_download"] = set_sequencial + self.handle.set_sequential_download(set_sequencial) + def set_auto_managed(self, auto_managed): self.options["auto_managed"] = auto_managed if not (self.handle.is_paused() and not self.handle.is_auto_managed()): @@ -638,6 +645,7 @@ class Torrent(object): "owner": self.owner, "paused": self.status.paused, "prioritize_first_last": self.options["prioritize_first_last_pieces"], + "sequential_download": self.options["sequential_download"], "progress": progress, "shared": self.options["shared"], "remove_at_ratio": self.options["remove_at_ratio"], @@ -776,6 +784,7 @@ class Torrent(object): self.handle.set_upload_limit(int(self.max_upload_speed * 1024)) self.handle.set_download_limit(int(self.max_download_speed * 1024)) self.handle.prioritize_files(self.file_priorities) + self.handle.set_sequential_download(self.options["sequential_download"]) self.handle.resolve_countries(True) def pause(self): @@ -842,10 +851,10 @@ class Torrent(object): # Attempt to convert utf8 path to unicode # Note: Inconsistent encoding for 'dest', needs future investigation try: - dest_u = unicode(dest, "utf-8") + dest_u = unicode(dest, "utf-8") except TypeError: - # String is already unicode - dest_u = dest + # String is already unicode + dest_u = dest if not os.path.exists(dest_u): try: @@ -853,7 +862,9 @@ class Torrent(object): os.makedirs(dest_u) except IOError, e: log.exception(e) - log.error("Could not move storage for torrent %s since %s does not exist and could not create the directory.", self.torrent_id, dest_u) + log.error("Could not move storage for torrent %s since %s does " + "not exist and could not create the directory.", + self.torrent_id, dest_u) return False try: self.handle.move_storage(dest_u) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 0a597b5c1..8c9ac415d 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -74,6 +74,7 @@ class TorrentState: max_upload_speed=-1.0, max_download_speed=-1.0, prioritize_first_last=False, + sequential_download=False, file_priorities=None, queue=None, auto_managed=True, @@ -109,6 +110,7 @@ class TorrentState: self.max_upload_speed = max_upload_speed self.max_download_speed = max_download_speed self.prioritize_first_last = prioritize_first_last + self.sequential_download = sequential_download self.file_priorities = file_priorities self.auto_managed = auto_managed self.stop_ratio = stop_ratio @@ -362,6 +364,7 @@ class TorrentManager(component.Component): options["max_upload_speed"] = state.max_upload_speed options["max_download_speed"] = state.max_download_speed options["prioritize_first_last_pieces"] = state.prioritize_first_last + options["sequential_download"] = state.sequential_download options["file_priorities"] = state.file_priorities options["compact_allocation"] = state.compact options["download_location"] = state.save_path @@ -669,6 +672,7 @@ class TorrentManager(component.Component): torrent.options["max_upload_speed"], torrent.options["max_download_speed"], torrent.options["prioritize_first_last_pieces"], + torrent.options["sequential_download"], torrent.options["file_priorities"], torrent.get_queue_position(), torrent.options["auto_managed"],