Changeset 3770
- Timestamp:
- 08/28/08 04:40:49 (4 months ago)
- Location:
- trunk/deluge/core
- Files:
-
- 3 modified
-
core.py (modified) (1 diff)
-
torrent.py (modified) (14 diffs)
-
torrentmanager.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/deluge/core/core.py
r3753 r3770 521 521 self.torrents[torrent_id].force_recheck() 522 522 523 def export_set_torrent_options(self, torrent_ids, options): 524 """Sets the torrent options for torrent_ids""" 525 for torrent_id in torrent_ids: 526 self.torrents[torrent_id].set_options(options) 527 523 528 def export_set_torrent_trackers(self, torrent_id, trackers): 524 529 """Sets a torrents tracker list. trackers will be [{"url", "tier"}]""" -
trunk/deluge/core/torrent.py
r3727 r3770 42 42 from deluge.configmanager import ConfigManager 43 43 from deluge.log import LOG as log 44 from deluge.core.preferencesmanager import DEFAULT_PREFS 44 45 import deluge.xmlrpclib 45 46 46 47 TORRENT_STATE = deluge.common.TORRENT_STATE 48 49 OPTIONS = { 50 "max_download_speed": DEFAULT_PREFS["max_download_speed_per_torrent"], 51 "max_upload_speed": DEFAULT_PREFS["max_upload_speed_per_torrent"], 52 "max_connections": DEFAULT_PREFS["max_connections_per_torrent"], 53 "max_upload_slots": DEFAULT_PREFS["max_upload_slots_per_torrent"], 54 "prioritize_first_last_pieces": DEFAULT_PREFS["prioritize_first_last_pieces"], 55 "auto_managed": DEFAULT_PREFS["auto_managed"], 56 "stop_at_ratio": DEFAULT_PREFS["stop_seed_at_ratio"], 57 "stop_ratio": DEFAULT_PREFS["stop_seed_ratio"], 58 "remove_at_ratio": DEFAULT_PREFS["remove_seed_at_ratio"], 59 "move_completed": DEFAULT_PREFS["move_completed"], 60 "move_completed_path": DEFAULT_PREFS["move_completed_path"], 61 "file_priorities": [], 62 "compact_allocation": DEFAULT_PREFS["compact_allocation"], 63 "download_location": DEFAULT_PREFS["download_location"], 64 "add_paused": DEFAULT_PREFS["add_paused"] 65 } 47 66 48 67 class Torrent: … … 70 89 # Files dictionary 71 90 self.files = self.get_files() 72 # Set the default file priorities to normal 73 self.file_priorities = [1]* len(self.files) 74 91 75 92 # Default total_uploaded to 0, this may be changed by the state 76 93 self.total_uploaded = 0 77 94 78 # Set default auto_managed value 79 self.auto_managed = options["auto_managed"] 80 if not handle.is_paused(): 81 handle.auto_managed(self.auto_managed) 82 95 # Set the default options 96 self.options = OPTIONS 97 self.options.update(options) 98 83 99 # We need to keep track if the torrent is finished in the state to prevent 84 100 # some weird things on state load. 85 101 self.is_finished = False 86 102 87 # Queueing options88 self.stop_at_ratio = False89 self.stop_ratio = 2.0090 self.remove_at_ratio = False91 92 self.move_on_completed = False93 self.move_on_completed_path = deluge.common.get_default_download_dir()94 95 103 # Load values from state if we have it 96 if state is not None:104 if state: 97 105 # This is for saving the total uploaded between sessions 98 106 self.total_uploaded = state.total_uploaded … … 103 111 self.is_finished = state.is_finished 104 112 # Set the per-torrent queue options 105 self. set_stop_at_ratio(state.stop_at_ratio)106 self. set_stop_ratio(state.stop_ratio)107 self. set_remove_at_ratio(state.remove_at_ratio)113 self.options["stop_at_ratio"] = state.stop_at_ratio 114 self.options["stop_ratio"] = state.stop_ratio 115 self.options["remove_at_ratio"] = state.remove_at_ratio 108 116 else: 109 117 # Tracker list … … 117 125 118 126 # Various torrent options 119 self.set_max_connections(options["max_connections_per_torrent"])120 self.set_max_upload_slots(options["max_upload_slots_per_torrent"])121 self.set_max_upload_speed(options["max_upload_speed_per_torrent"])122 self.set_max_download_speed(options["max_download_speed_per_torrent"])123 self.set_prioritize_first_last(options["prioritize_first_last_pieces"])124 127 self.handle.resolve_countries(True) 125 if options.has_key("file_priorities"): 126 self.set_file_priorities(options["file_priorities"]) 127 128 # Set the allocation mode 129 self.compact = options["compact_allocation"] 130 # Where the torrent is being saved to 131 self.save_path = options["download_location"] 128 self.set_options(self.options) 129 132 130 # Status message holds error info about the torrent 133 131 self.statusmsg = "OK" … … 141 139 log.debug("Torrent object created.") 142 140 143 def set_tracker_status(self, status): 144 """Sets the tracker status""" 145 self.tracker_status = status 146 141 ## Options methods ## 142 def set_options(self, options): 143 OPTIONS_FUNCS = { 144 # Functions used for setting options 145 "max_download_speed": self.set_max_download_speed, 146 "max_upload_speed": self.set_max_upload_speed, 147 "max_connections": self.handle.set_max_connections, 148 "max_upload_slots": self.handle.set_max_uploads, 149 "prioritize_first_last_pieces": self.set_prioritize_first_last, 150 "auto_managed": self.set_auto_managed, 151 "file_priorities": self.set_file_priorities, 152 "download_location": self.set_save_path, 153 } 154 for (key, value) in options.items(): 155 if OPTIONS_FUNCS.has_key(key): 156 OPTIONS_FUNCS[key](value) 157 158 self.options.update(options) 159 160 def get_options(self): 161 return self.options 162 147 163 def set_max_connections(self, max_connections): 148 self. max_connections= int(max_connections)149 self.handle.set_max_connections( self.max_connections)164 self.options["max_connections"] = int(max_connections) 165 self.handle.set_max_connections(max_connections) 150 166 151 167 def set_max_upload_slots(self, max_slots): 152 self. max_upload_slots= int(max_slots)153 self.handle.set_max_uploads( self.max_upload_slots)168 self.options["max_upload_slots"] = int(max_slots) 169 self.handle.set_max_uploads(max_slots) 154 170 155 171 def set_max_upload_speed(self, m_up_speed): 156 self. max_upload_speed= m_up_speed172 self.options["max_upload_speed"] = m_up_speed 157 173 if m_up_speed < 0: 158 174 v = -1 … … 163 179 164 180 def set_max_download_speed(self, m_down_speed): 165 self. max_download_speed= m_down_speed181 self.options["max_download_speed"] = m_down_speed 166 182 if m_down_speed < 0: 167 183 v = -1 … … 171 187 172 188 def set_prioritize_first_last(self, prioritize): 173 self. prioritize_first_last= prioritize174 if self.prioritize_first_last:189 self.options["prioritize_first_last_pieces"] = prioritize 190 if prioritize: 175 191 if self.handle.get_torrent_info().num_files() == 1: 176 192 # We only do this if one file is in the torrent … … 180 196 self.handle.prioritize_pieces(priorities) 181 197 182 def set_save_path(self, save_path):183 self.save_path = save_path184 185 198 def set_auto_managed(self, auto_managed): 186 self. auto_managed= auto_managed199 self.options["auto_managed"] = auto_managed 187 200 self.handle.auto_managed(auto_managed) 188 201 self.update_state() 189 202 190 203 def set_stop_ratio(self, stop_ratio): 191 self. stop_ratio= stop_ratio204 self.options["stop_ratio"] = stop_ratio 192 205 193 206 def set_stop_at_ratio(self, stop_at_ratio): 194 self. stop_at_ratio= stop_at_ratio207 self.options["stop_at_ratio"] = stop_at_ratio 195 208 196 209 def set_remove_at_ratio(self, remove_at_ratio): 197 self. remove_at_ratio= remove_at_ratio210 self.options["remove_at_ratio"] = remove_at_ratio 198 211 199 212 def set_file_priorities(self, file_priorities): … … 205 218 self.handle.prioritize_files(file_priorities) 206 219 207 if 0 in self. file_priorities:220 if 0 in self.options["file_priorities"]: 208 221 # We have previously marked a file 'Do Not Download' 209 222 # Check to see if we have changed any 0's to >0 and change state accordingly 210 for index, priority in enumerate(self. file_priorities):223 for index, priority in enumerate(self.options["file_priorities"]): 211 224 if priority == 0 and file_priorities[index] > 0: 212 225 # We have a changed 'Do Not Download' to a download priority … … 215 228 break 216 229 217 self. file_priorities= file_priorities230 self.options["file_priorities"] = file_priorities 218 231 219 232 # Set the first/last priorities if needed 220 self.set_prioritize_first_last(self. prioritize_first_last)221 233 self.set_prioritize_first_last(self.options["prioritize_first_last_pieces"]) 234 222 235 def set_trackers(self, trackers): 223 236 """Sets trackers""" … … 244 257 self.force_reannounce() 245 258 246 def set_move_on_completed(self, value): 247 self.move_on_completed = value 248 249 def set_move_on_completed_path(self, value): 250 self.move_on_completed_path = value 259 ### End Options methods ### 260 261 def set_save_path(self, save_path): 262 self.options["download_location"] = save_path 263 264 def set_tracker_status(self, status): 265 """Sets the tracker status""" 266 self.tracker_status = status 251 267 252 268 def update_state(self): … … 256 272 ltstate = int(self.handle.status().state) 257 273 258 log.debug("set_state_based_on_ltstate: %s", ltstate)274 log.debug("set_state_based_on_ltstate: %s", deluge.common.LT_TORRENT_STATE[ltstate]) 259 275 log.debug("session.is_paused: %s", component.get("Core").session.is_paused()) 260 276 if ltstate == LTSTATE["Queued"] or ltstate == LTSTATE["Checking"]: … … 453 469 "trackers": self.trackers, 454 470 "tracker_status": self.tracker_status, 455 "save_path": self. save_path,471 "save_path": self.options["download_location"], 456 472 "files": self.files, 457 "file_priorities": self. file_priorities,458 "compact": self. compact,459 "max_connections": self. max_connections,460 "max_upload_slots": self. max_upload_slots,461 "max_upload_speed": self. max_upload_speed,462 "max_download_speed": self. max_download_speed,463 "prioritize_first_last": self. prioritize_first_last,473 "file_priorities": self.options["file_priorities"], 474 "compact": self.options["compact_allocation"], 475 "max_connections": self.options["max_connections"], 476 "max_upload_slots": self.options["max_upload_slots"], 477 "max_upload_speed": self.options["max_upload_speed"], 478 "max_download_speed": self.options["max_download_speed"], 479 "prioritize_first_last": self.options["prioritize_first_last_pieces"], 464 480 "message": self.statusmsg, 465 481 "hash": self.torrent_id, … … 467 483 "seeding_time": self.status.seeding_time, 468 484 "seed_rank": self.status.seed_rank, 469 "is_auto_managed": self. auto_managed,470 "stop_ratio": self. stop_ratio,471 "stop_at_ratio": self. stop_at_ratio,472 "remove_at_ratio": self. remove_at_ratio,473 "move_on_completed": self. move_on_completed,474 "move_on_completed_path": self. move_on_completed_path485 "is_auto_managed": self.options["auto_managed"], 486 "stop_ratio": self.options["stop_ratio"], 487 "stop_at_ratio": self.options["stop_at_ratio"], 488 "remove_at_ratio": self.options["remove_at_ratio"], 489 "move_on_completed": self.options["move_completed"], 490 "move_on_completed_path": self.options["move_completed_path"] 475 491 } 476 492 -
trunk/deluge/core/torrentmanager.py
r3760 r3770 47 47 from deluge.configmanager import ConfigManager 48 48 from deluge.core.torrent import Torrent 49 from deluge.core.torrent import OPTIONS 49 50 import deluge.core.oldstateupgrader 50 51 … … 189 190 def update(self): 190 191 for torrent_id, torrent in self.torrents.items(): 191 if self.config["stop_seed_at_ratio"] or torrent. stop_at_ratio:192 if self.config["stop_seed_at_ratio"] or torrent.options["stop_at_ratio"]: 192 193 stop_ratio = self.config["stop_seed_ratio"] 193 if torrent. stop_at_ratio:194 stop_ratio = torrent. stop_ratio194 if torrent.options["stop_at_ratio"]: 195 stop_ratio = torrent.options["stop_ratio"] 195 196 if torrent.get_ratio() >= stop_ratio and torrent.is_finished: 196 if self.config["remove_seed_at_ratio"] or torrent. remove_at_ratio:197 if self.config["remove_seed_at_ratio"] or torrent.options["remove_at_ratio"]: 197 198 self.remove(torrent_id) 198 199 break … … 254 255 except Exception, e: 255 256 log.error("Unable to decode torrent file!: %s", e) 256 257 257 258 if torrent_info is None: 258 259 # We have no torrent_info so we need to add the torrent with information … … 260 261 261 262 # Populate the options dict from state 262 options = {}263 options["max_connections _per_torrent"] = state.max_connections264 options["max_upload_slots _per_torrent"] = state.max_upload_slots265 options["max_upload_speed _per_torrent"] = state.max_upload_speed266 options["max_download_speed _per_torrent"] = state.max_download_speed263 options = OPTIONS 264 options["max_connections"] = state.max_connections 265 options["max_upload_slots"] = state.max_upload_slots 266 options["max_upload_speed"] = state.max_upload_speed 267 options["max_download_speed"] = state.max_download_speed 267 268 options["prioritize_first_last_pieces"] = state.prioritize_first_last 268 269 options["file_priorities"] = state.file_priorities … … 283 284 # We have a torrent_info object so we're not loading from state. 284 285 # Check if options is None and load defaults 285 options_keys = [286 "compact_allocation",287 "max_connections_per_torrent",288 "max_upload_slots_per_torrent",289 "max_upload_speed_per_torrent",290 "max_download_speed_per_torrent",291 "prioritize_first_last_pieces",292 "download_location",293 "add_paused",294 "auto_managed"295 ]296 297 286 if options == None: 298 options = {} 299 for key in options_keys: 300 options[key] = self.config[key] 287 options = OPTIONS 301 288 else: 302 for key in options_keys:303 if not options.has_key(key):304 options[key] = self.config[key]289 o = OPTIONS 290 o.update(options) 291 options = o 305 292 306 293 add_torrent_params["ti"] = torrent_info … … 506 493 torrent.get_status(["total_uploaded"])["total_uploaded"], 507 494 torrent.trackers, 508 torrent. compact,495 torrent.options["compact_allocation"], 509 496 paused, 510 torrent. save_path,511 torrent. max_connections,512 torrent. max_upload_slots,513 torrent. max_upload_speed,514 torrent. max_download_speed,515 torrent. prioritize_first_last,516 torrent. file_priorities,497 torrent.options["download_location"], 498 torrent.options["max_connections"], 499 torrent.options["max_upload_slots"], 500 torrent.options["max_upload_speed"], 501 torrent.options["max_download_speed"], 502 torrent.options["prioritize_first_last_pieces"], 503 torrent.options["file_priorities"], 517 504 torrent.get_queue_position(), 518 torrent. auto_managed,505 torrent.options["auto_managed"], 519 506 torrent.is_finished, 520 torrent. stop_ratio,521 torrent. stop_at_ratio,522 torrent. remove_at_ratio507 torrent.options["stop_ratio"], 508 torrent.options["stop_at_ratio"], 509 torrent.options["remove_at_ratio"] 523 510 ) 524 511 state.torrents.append(torrent_state) … … 607 594 if not torrent.is_finished: 608 595 move_path = None 609 if torrent. move_on_completed:610 move_path = torrent. move_on_completed_path596 if torrent.options["move_completed"]: 597 move_path = torrent.options["move_completed_path"] 611 598 elif self.config["move_completed"]: 612 599 move_path = self.config["move_completed_path"]
