Add 'save_path' to add_torrent().

Save the 'save_path' in the torrent state.
This commit is contained in:
Andrew Resch 2007-10-04 22:21:47 +00:00
parent 8a0692fa4f
commit 17f62130fe
5 changed files with 579 additions and 545 deletions

View file

@ -182,12 +182,16 @@ class Core(dbus.service.Object):
gobject.idle_add(self._shutdown)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
in_signature="say", out_signature="b")
def add_torrent_file(self, filename, filedump):
in_signature="ssay", out_signature="b")
def add_torrent_file(self, filename, save_path, filedump):
"""Adds a torrent file to the libtorrent session
This requires the torrents filename and a dump of it's content
"""
torrent_id = self.torrents.add(filename, filedump)
if save_path == "":
save_path = None
torrent_id = self.torrents.add(filename, filedump=filedump,
save_path=save_path)
# Run the plugin hooks for 'post_torrent_add'
self.plugins.run_post_torrent_add(torrent_id)
@ -201,8 +205,8 @@ class Core(dbus.service.Object):
return False
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
in_signature="s", out_signature="b")
def add_torrent_url(self, url):
in_signature="ss", out_signature="b")
def add_torrent_url(self, url, save_path):
log.info("Attempting to add url %s", url)
# Get the actual filename of the torrent from the url provided.
@ -221,7 +225,7 @@ class Core(dbus.service.Object):
return False
# Add the torrent to session
return self.add_torrent_file(filename, filedump)
return self.add_torrent_file(filename, save_path, filedump)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
in_signature="s", out_signature="")

View file

@ -38,7 +38,7 @@ import deluge.common
class Torrent:
"""Torrent holds information about torrents added to the libtorrent session.
"""
def __init__(self, filename, handle, compact):
def __init__(self, filename, handle, compact, save_path):
# Set the filename
self.filename = filename
# Set the libtorrent handle
@ -49,6 +49,8 @@ class Torrent:
self.total_uploaded = 0
# Set the allocation mode
self.compact = compact
# Where the torrent is being saved to
self.save_path = save_path
# The tracker status
self.tracker_status = ""
@ -59,7 +61,8 @@ class Torrent:
def get_state(self):
"""Returns the state of this torrent for saving to the session state"""
status = self.handle.status()
return (self.torrent_id, self.filename, self.compact, status.paused)
return (self.torrent_id, self.filename, self.compact, status.paused,
self.save_path)
def get_eta(self):
"""Returns the ETA in seconds for this torrent"""

View file

@ -47,11 +47,12 @@ from deluge.core.torrent import Torrent
from deluge.log import LOG as log
class TorrentState:
def __init__(self, torrent_id, filename, compact, paused):
def __init__(self, torrent_id, filename, compact, paused, save_path):
self.torrent_id = torrent_id
self.filename = filename
self.compact = compact
self.paused = paused
self.save_path = save_path
class TorrentManagerState:
def __init__(self):
@ -117,7 +118,8 @@ class TorrentManager:
"""Returns a list of torrent_ids"""
return self.torrents.keys()
def add(self, filename, filedump=None, compact=None, paused=False):
def add(self, filename, filedump=None, compact=None, paused=False,
save_path=None):
"""Add a torrent to the manager and returns it's torrent_id"""
log.info("Adding torrent: %s", filename)
@ -160,6 +162,10 @@ class TorrentManager:
torrent_filedump = lt.bdecode(filedump)
handle = None
# Make sure we have a valid download_location
if save_path is None:
save_path = self.config["download_location"]
# Make sure we are adding it with the correct allocation method.
if compact is None:
compact = self.config["compact_allocation"]
@ -167,7 +173,7 @@ class TorrentManager:
try:
handle = self.session.add_torrent(
lt.torrent_info(torrent_filedump),
self.config["download_location"],
save_path,
resume_data=fastresume,
compact_mode=compact,
paused=paused)
@ -179,7 +185,8 @@ class TorrentManager:
return None
# Create a Torrent object
torrent = Torrent(filename, handle, compact)
torrent = Torrent(filename, handle, compact,
save_path)
# Add the torrent object to the dictionary
self.torrents[torrent.torrent_id] = torrent
@ -187,7 +194,7 @@ class TorrentManager:
handle.set_max_connections(self.max_connections)
handle.set_max_uploads(self.max_uploads)
log.debug("Attemping to save torrent file: %s", filename)
log.debug("Attempting to save torrent file: %s", filename)
# Test if the torrentfiles_location is accessible
if os.access(
os.path.join(self.config["torrentfiles_location"]), os.F_OK) \
@ -303,7 +310,7 @@ class TorrentManager:
# Try to add the torrents in the state to the session
for torrent_state in state.torrents:
self.add(torrent_state.filename, compact=torrent_state.compact,
paused=torrent_state.paused)
paused=torrent_state.paused, save_path=torrent_state.save_path)
def save_state(self):
"""Save the state of the TorrentManager to the torrents.state file"""

View file

@ -85,7 +85,7 @@ def add_torrent_file(torrent_files):
f = open(torrent_file, "rb")
# Get the filename because the core doesn't want a path.
(path, filename) = os.path.split(torrent_file)
result = core.add_torrent_file(filename, f.read())
result = core.add_torrent_file(filename, str(), f.read())
f.close()
if result is False:
# The torrent was not added successfully.
@ -96,7 +96,7 @@ def add_torrent_url(torrent_url):
core = get_core()
from deluge.common import is_url
if is_url(torrent_url):
result = core.add_torrent_url(torrent_url)
result = core.add_torrent_url(torrent_url, str())
if result is False:
# The torrent url was not added successfully.
log.warning("Torrent %s was not added successfully.", torrent_url)

File diff suppressed because it is too large Load diff