Author: andar

Revision: 5847

Log:
        Add option to create torrent name sub-folders in extract folder
Fix issue where the plugin would not stop extracting files after being disabled

Diff:
Modified: branches/1.2_RC/ChangeLog
===================================================================
--- branches/1.2_RC/ChangeLog   2009-10-14 15:53:31 UTC (rev 5846)
+++ branches/1.2_RC/ChangeLog   2009-10-19 02:10:43 UTC (rev 5847)
@@ -13,8 +13,12 @@
        * Add a --fork option to allow forking the webui to the background
 
 ==== 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) ===
 ==== Core ====
        * Implement new RPC protocol DelugeRPC replacing XMLRPC

Modified: branches/1.2_RC/deluge/plugins/extractor/extractor/core.py
===================================================================
--- branches/1.2_RC/deluge/plugins/extractor/extractor/core.py  2009-10-14 
15:53:31 UTC (rev 5846)
+++ branches/1.2_RC/deluge/plugins/extractor/extractor/core.py  2009-10-19 
02:10:43 UTC (rev 5847)
@@ -48,7 +48,8 @@
 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 @@
         
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 @@
 
             # 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 @@
             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

Modified: 
branches/1.2_RC/deluge/plugins/extractor/extractor/data/extractor_prefs.glade
===================================================================
--- 
branches/1.2_RC/deluge/plugins/extractor/extractor/data/extractor_prefs.glade   
    2009-10-14 15:53:31 UTC (rev 5846)
+++ 
branches/1.2_RC/deluge/plugins/extractor/extractor/data/extractor_prefs.glade   
    2009-10-19 02:10:43 UTC (rev 5847)
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Wed May  6 12:45:11 2009 -->
+<?xml version="1.0"?>
 <glade-interface>
+  <!-- interface-requires gtk+ 2.6 -->
+  <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkWindow" id="window1">
     <child>
       <widget class="GtkVBox" id="extractor_prefs_box">
@@ -11,7 +11,7 @@
           <widget class="GtkFrame" id="frame1">
             <property name="visible">True</property>
             <property name="label_xalign">0</property>
-            <property name="shadow_type">GTK_SHADOW_NONE</property>
+            <property name="shadow_type">none</property>
             <child>
               <widget class="GtkVBox" id="vbox1">
                 <property name="visible">True</property>
@@ -29,6 +29,7 @@
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
+                        <property name="position">0</property>
                       </packing>
                     </child>
                     <child>
@@ -36,9 +37,12 @@
                         <property name="visible">True</property>
                         <child>
                           <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>
                           </widget>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
                         </child>
                         <child>
                           <widget class="GtkEntry" id="entry_path">
@@ -57,8 +61,24 @@
                   <packing>
                     <property name="expand">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>
+                </child>
               </widget>
             </child>
             <child>
@@ -72,6 +92,9 @@
               </packing>
             </child>
           </widget>
+          <packing>
+            <property name="position">0</property>
+          </packing>
         </child>
       </widget>
     </child>

Modified: branches/1.2_RC/deluge/plugins/extractor/extractor/gtkui.py
===================================================================
--- branches/1.2_RC/deluge/plugins/extractor/extractor/gtkui.py 2009-10-14 
15:53:31 UTC (rev 5846)
+++ branches/1.2_RC/deluge/plugins/extractor/extractor/gtkui.py 2009-10-19 
02:10:43 UTC (rev 5847)
@@ -70,7 +70,8 @@
             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 @@
                 
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)

Modified: trunk/deluge/plugins/extractor/extractor/core.py
===================================================================
--- trunk/deluge/plugins/extractor/extractor/core.py    2009-10-14 15:53:31 UTC 
(rev 5846)
+++ trunk/deluge/plugins/extractor/extractor/core.py    2009-10-19 02:10:43 UTC 
(rev 5847)
@@ -48,7 +48,8 @@
 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 @@
         
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 @@
 
             # 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 @@
             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

Modified: trunk/deluge/plugins/extractor/extractor/data/extractor_prefs.glade
===================================================================
--- trunk/deluge/plugins/extractor/extractor/data/extractor_prefs.glade 
2009-10-14 15:53:31 UTC (rev 5846)
+++ trunk/deluge/plugins/extractor/extractor/data/extractor_prefs.glade 
2009-10-19 02:10:43 UTC (rev 5847)
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Wed May  6 12:45:11 2009 -->
+<?xml version="1.0"?>
 <glade-interface>
+  <!-- interface-requires gtk+ 2.6 -->
+  <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkWindow" id="window1">
     <child>
       <widget class="GtkVBox" id="extractor_prefs_box">
@@ -11,7 +11,7 @@
           <widget class="GtkFrame" id="frame1">
             <property name="visible">True</property>
             <property name="label_xalign">0</property>
-            <property name="shadow_type">GTK_SHADOW_NONE</property>
+            <property name="shadow_type">none</property>
             <child>
               <widget class="GtkVBox" id="vbox1">
                 <property name="visible">True</property>
@@ -29,6 +29,7 @@
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
+                        <property name="position">0</property>
                       </packing>
                     </child>
                     <child>
@@ -36,9 +37,12 @@
                         <property name="visible">True</property>
                         <child>
                           <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>
                           </widget>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
                         </child>
                         <child>
                           <widget class="GtkEntry" id="entry_path">
@@ -57,8 +61,24 @@
                   <packing>
                     <property name="expand">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>
+                </child>
               </widget>
             </child>
             <child>
@@ -72,6 +92,9 @@
               </packing>
             </child>
           </widget>
+          <packing>
+            <property name="position">0</property>
+          </packing>
         </child>
       </widget>
     </child>

Modified: trunk/deluge/plugins/extractor/extractor/gtkui.py
===================================================================
--- trunk/deluge/plugins/extractor/extractor/gtkui.py   2009-10-14 15:53:31 UTC 
(rev 5846)
+++ trunk/deluge/plugins/extractor/extractor/gtkui.py   2009-10-19 02:10:43 UTC 
(rev 5847)
@@ -70,7 +70,8 @@
             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 @@
                 
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)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to