From 9c491c13ccd3f97062e2f1493a33fb55d117ef5b Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 19 Oct 2009 02:10:43 +0000 Subject: [PATCH] Add option to create torrent name sub-folders in extract folder Fix issue where the plugin would not stop extracting files after being disabled --- deluge/plugins/extractor/extractor/core.py | 28 +++++++++++----- .../extractor/data/extractor_prefs.glade | 33 ++++++++++++++++--- deluge/plugins/extractor/extractor/gtkui.py | 5 ++- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/deluge/plugins/extractor/extractor/core.py b/deluge/plugins/extractor/extractor/core.py index 8b20a2683..f7c888e17 100644 --- a/deluge/plugins/extractor/extractor/core.py +++ b/deluge/plugins/extractor/extractor/core.py @@ -48,7 +48,8 @@ import deluge.configmanager from deluge.core.rpcserver import export DEFAULT_PREFS = { - "extract_path": "" + "extract_path": "", + "use_name_folder": True } # The first format is the source file, the second is the dest path @@ -69,7 +70,7 @@ class Core(CorePluginBase): component.get("EventManager").register_event_handler("TorrentFinishedEvent", self._on_torrent_finished) def disable(self): - pass + component.get("EventManager").deregister_event_handler("TorrentFinishedEvent", self._on_torrent_finished) def update(self): pass @@ -97,11 +98,22 @@ class Core(CorePluginBase): # Now that we have the cmd, lets run it to extract the files fp = os.path.join(save_path, f["path"]) - if os.path.exists(self.config["extract_path"]): - dest = self.config["extract_path"] - else: - dest = None + + # Get the destination path + dest = self.config["extract_path"] + if self.config["use_name_folder"]: + name = component.get("TorrentManager")[torrent_id].get_status(["name"])["name"] + dest = os.path.join(dest, name) + # Create the destination folder if it doesn't exist + if not os.path.exists(dest): + try: + os.makedirs(dest) + except Exception, e: + log.error("Error creating destination folder: %s", e) + return + + log.debug("Extracting to %s", dest) def on_extract_success(result, torrent_id): # XXX: Emit an event log.debug("Extract was successful for %s", torrent_id) @@ -115,14 +127,14 @@ class Core(CorePluginBase): d.addCallback(on_extract_success, torrent_id) d.addErrback(on_extract_failed, torrent_id) - @export() + @export def set_config(self, config): "sets the config dictionary" for key in config.keys(): self.config[key] = config[key] self.config.save() - @export() + @export def get_config(self): "returns the config dictionary" return self.config.config diff --git a/deluge/plugins/extractor/extractor/data/extractor_prefs.glade b/deluge/plugins/extractor/extractor/data/extractor_prefs.glade index ee6d536b0..c6827e4cd 100644 --- a/deluge/plugins/extractor/extractor/data/extractor_prefs.glade +++ b/deluge/plugins/extractor/extractor/data/extractor_prefs.glade @@ -1,7 +1,7 @@ - - - + + + @@ -11,7 +11,7 @@ True 0 - GTK_SHADOW_NONE + none True @@ -29,6 +29,7 @@ False False + 0 @@ -36,9 +37,12 @@ True - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER + select-folder Select A Folder + + 0 + @@ -57,6 +61,22 @@ False False + 0 + + + + + Create torrent name sub-folder + True + True + False + This option will create a sub-folder using the torrent's name within the selected extract folder and put the extracted files there. + True + + + False + False + 1 @@ -72,6 +92,9 @@ + + 0 + diff --git a/deluge/plugins/extractor/extractor/gtkui.py b/deluge/plugins/extractor/extractor/gtkui.py index 8f0da11d0..9e3bf617b 100644 --- a/deluge/plugins/extractor/extractor/gtkui.py +++ b/deluge/plugins/extractor/extractor/gtkui.py @@ -70,7 +70,8 @@ class GtkUI(GtkPluginBase): path = self.glade.get_widget("entry_path").get_text() config = { - "extract_path": path + "extract_path": path, + "use_name_folder": self.glade.get_widget("chk_use_name").get_active() } client.extractor.set_config(config) @@ -88,5 +89,7 @@ class GtkUI(GtkPluginBase): self.glade.get_widget("folderchooser_path").set_current_folder(config["extract_path"]) else: self.glade.get_widget("entry_path").set_text(config["extract_path"]) + + self.glade.get_widget("chk_use_name").set_active(config["use_name_folder"]) client.extractor.get_config().addCallback(on_get_config)