Add option to create torrent name sub-folders in extract folder

Fix issue where the plugin would not stop extracting files after being disabled
This commit is contained in:
Andrew Resch 2009-10-19 02:10:43 +00:00
commit f55bc6c9d8
4 changed files with 57 additions and 15 deletions

View file

@ -13,7 +13,11 @@
* Add a --fork option to allow forking the webui to the background * Add a --fork option to allow forking the webui to the background
==== Misc ==== ==== Misc ====
* Add man pages for deluge-console and deluge-gtk * Add man pages for deluge-console, deluge-gtk and deluge-web
==== Extractor ====
* Fix issue where the plugin would not stop extracting files after being disabled
* Add option to create torrent name sub-folders in extract folder
=== Deluge 1.2.0_rc1 (07 October 2009) === === Deluge 1.2.0_rc1 (07 October 2009) ===
==== Core ==== ==== Core ====

View file

@ -48,7 +48,8 @@ import deluge.configmanager
from deluge.core.rpcserver import export from deluge.core.rpcserver import export
DEFAULT_PREFS = { DEFAULT_PREFS = {
"extract_path": "" "extract_path": "",
"use_name_folder": True
} }
# The first format is the source file, the second is the dest path # 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) component.get("EventManager").register_event_handler("TorrentFinishedEvent", self._on_torrent_finished)
def disable(self): def disable(self):
pass component.get("EventManager").deregister_event_handler("TorrentFinishedEvent", self._on_torrent_finished)
def update(self): def update(self):
pass pass
@ -97,11 +98,22 @@ class Core(CorePluginBase):
# Now that we have the cmd, lets run it to extract the files # Now that we have the cmd, lets run it to extract the files
fp = os.path.join(save_path, f["path"]) 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): def on_extract_success(result, torrent_id):
# XXX: Emit an event # XXX: Emit an event
log.debug("Extract was successful for %s", torrent_id) log.debug("Extract was successful for %s", torrent_id)
@ -115,14 +127,14 @@ class Core(CorePluginBase):
d.addCallback(on_extract_success, torrent_id) d.addCallback(on_extract_success, torrent_id)
d.addErrback(on_extract_failed, torrent_id) d.addErrback(on_extract_failed, torrent_id)
@export() @export
def set_config(self, config): def set_config(self, config):
"sets the config dictionary" "sets the config dictionary"
for key in config.keys(): for key in config.keys():
self.config[key] = config[key] self.config[key] = config[key]
self.config.save() self.config.save()
@export() @export
def get_config(self): def get_config(self):
"returns the config dictionary" "returns the config dictionary"
return self.config.config return self.config.config

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Wed May 6 12:45:11 2009 -->
<glade-interface> <glade-interface>
<!-- interface-requires gtk+ 2.6 -->
<!-- interface-naming-policy toplevel-contextual -->
<widget class="GtkWindow" id="window1"> <widget class="GtkWindow" id="window1">
<child> <child>
<widget class="GtkVBox" id="extractor_prefs_box"> <widget class="GtkVBox" id="extractor_prefs_box">
@ -11,7 +11,7 @@
<widget class="GtkFrame" id="frame1"> <widget class="GtkFrame" id="frame1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property> <property name="shadow_type">none</property>
<child> <child>
<widget class="GtkVBox" id="vbox1"> <widget class="GtkVBox" id="vbox1">
<property name="visible">True</property> <property name="visible">True</property>
@ -29,6 +29,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -36,9 +37,12 @@
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<widget class="GtkFileChooserButton" id="folderchooser_path"> <widget class="GtkFileChooserButton" id="folderchooser_path">
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property> <property name="action">select-folder</property>
<property name="title" translatable="yes">Select A Folder</property> <property name="title" translatable="yes">Select A Folder</property>
</widget> </widget>
<packing>
<property name="position">0</property>
</packing>
</child> </child>
<child> <child>
<widget class="GtkEntry" id="entry_path"> <widget class="GtkEntry" id="entry_path">
@ -57,6 +61,22 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="chk_use_name">
<property name="label" translatable="yes">Create torrent name sub-folder</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip" translatable="yes">This option will create a sub-folder using the torrent's name within the selected extract folder and put the extracted files there.</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing> </packing>
</child> </child>
</widget> </widget>
@ -72,6 +92,9 @@
</packing> </packing>
</child> </child>
</widget> </widget>
<packing>
<property name="position">0</property>
</packing>
</child> </child>
</widget> </widget>
</child> </child>

View file

@ -70,7 +70,8 @@ class GtkUI(GtkPluginBase):
path = self.glade.get_widget("entry_path").get_text() path = self.glade.get_widget("entry_path").get_text()
config = { config = {
"extract_path": path "extract_path": path,
"use_name_folder": self.glade.get_widget("chk_use_name").get_active()
} }
client.extractor.set_config(config) client.extractor.set_config(config)
@ -89,4 +90,6 @@ class GtkUI(GtkPluginBase):
else: else:
self.glade.get_widget("entry_path").set_text(config["extract_path"]) 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) client.extractor.get_config().addCallback(on_get_config)