Fix #270 autoadd folder

This commit is contained in:
Andrew Resch 2008-06-14 00:32:52 +00:00
parent d7957f82e7
commit 5936aeebb6
3 changed files with 24 additions and 20 deletions

View File

@ -91,9 +91,7 @@ class AutoAdd(component.Component):
continue
# The torrent looks good, so lets add it to the session
component.get("TorrentManager").add(
os.path.split(filepath)[1],
filedump)
component.get("TorrentManager").add(filedump=filedump)
os.remove(filepath)

View File

@ -325,21 +325,8 @@ class Core(
log.warn("Unable to decode torrent file: %s", e)
return None
torrent_id = self.torrents.add(torrent_info=torrent_info, options=options)
# Here we need to save a copy of the filedump for state purposes
# and also if the user wishes to save a copy of the torrent elsewhere.
if torrent_id:
# Write the .torrent file to the state directory
try:
save_file = open(os.path.join(self.config["state_location"],
torrent_id + ".torrent"),
"wb")
save_file.write(filedump)
save_file.close()
except IOError, e:
log.warning("Unable to save torrent file: %s", e)
torrent_id = self.torrents.add(filedump=filedump, options=options)
# Run the plugin hooks for 'post_torrent_add'
self.plugins.run_post_torrent_add(torrent_id)

View File

@ -203,15 +203,23 @@ class TorrentManager(component.Component):
return fastresume
def add(self, torrent_info=None, state=None, options=None, save_state=True):
def add(self, torrent_info=None, state=None, options=None, save_state=True,
filedump=None):
"""Add a torrent to the manager and returns it's torrent_id"""
if torrent_info is None and state is None:
if torrent_info is None and state is None and filedump is None:
log.debug("You must specify a valid torrent_info or a torrent state object!")
return
log.debug("torrentmanager.add")
add_torrent_params = {}
if filedump is not None:
try:
torrent_info = lt.torrent_info(lt.bdecode(filedump))
except Exception, e:
log.error("Unable to decode torrent file!: %s", e)
if torrent_info is None:
# We have no torrent_info so we need to add the torrent with information
# from the state object.
@ -312,6 +320,17 @@ class TorrentManager(component.Component):
handle.resume()
handle.auto_managed(options["auto_managed"])
# Write the .torrent file to the state directory
if filedump:
try:
save_file = open(os.path.join(self.config["state_location"],
torrent.torrent_id + ".torrent"),
"wb")
save_file.write(filedump)
save_file.close()
except IOError, e:
log.warning("Unable to save torrent file: %s", e)
if save_state:
# Save the session state
self.save_state()