From 2ced8ad18922f0e5cf877b99177f85cca970607a Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sun, 5 Jul 2009 00:09:49 +0000 Subject: [PATCH] Change add_torrent_magnets to add_torrent_magnet Have add_torrent_magnet return a torrent_id on successful add --- deluge/core/core.py | 18 ++++++++++-------- deluge/ui/gtkui/addtorrentdialog.py | 3 ++- deluge/ui/gtkui/ipcinterface.py | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index db5390b0f..e3638943a 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -293,15 +293,17 @@ class Core(component.Component): return d @export - def add_torrent_magnets(self, uris, options): - for uri in uris: - log.debug("Attempting to add by magnet uri: %s", uri) - try: - option = options[uris.index(uri)] - except IndexError: - option = None + def add_torrent_magnet(self, uri, options): + """ + Adds a torrent from a magnet link. - torrent_id = self.torrentmanager.add(magnet=uri, options=option) + :param uri: str, the magnet link + :param options: dict, the options to apply to the torrent on add + + """ + log.debug("Attempting to add by magnet uri: %s", uri) + + return self.torrentmanager.add(magnet=uri, options=options) @export def remove_torrent(self, torrent_ids, remove_data): diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 22d4f65df..5ecf753ed 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -751,7 +751,8 @@ class AddTorrentDialog(component.Component): base64.encodestring(open(f, "rb").read()), torrent_options[i]) if torrent_magnets: - client.core.add_torrent_magnets(torrent_magnets, torrent_magnet_options) + for i, m in enumerate(torrent_magnets): + client.core.add_torrent_magnet(m, torrent_magnet_options[i]) client.force_call(False) self.hide() diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index a27576673..01e9552db 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -152,7 +152,7 @@ def process_args(args): component.get("AddTorrentDialog").add_from_magnets([arg]) component.get("AddTorrentDialog").show(config["focus_add_dialog"]) else: - client.core.add_torrent_magnets([arg], []) + client.core.add_torrent_magnet(arg, {}) else: # Just a file log.debug("Attempting to add %s from external source..",