Ticket #3380: deluge-2.0.3+on_pre_torrent_remove-Extractor_plugin.patch
File deluge-2.0.3+on_pre_torrent_remove-Extractor_plugin.patch, 8.4 KB (added by , 4 years ago) |
---|
-
plugins/Extractor-0.7.egg/deluge_extractor/core.py
old new 16 16 import errno 17 17 import logging 18 18 import os 19 import shutil 20 import traceback 19 21 20 22 from twisted.internet.utils import getProcessOutputAndValue 21 23 from twisted.python.procutils import which … … 28 30 29 31 log = logging.getLogger(__name__) 30 32 31 DEFAULT_PREFS = {'extract_path': '', 'use_name_folder': True }33 DEFAULT_PREFS = {'extract_path': '', 'use_name_folder': True, 'auto_delete': False} 32 34 33 35 if windows_check(): 34 36 win_7z_exes = [ … … 110 112 component.get('EventManager').register_event_handler( 111 113 'TorrentFinishedEvent', self._on_torrent_finished 112 114 ) 115 component.get('EventManager').register_event_handler( 116 'PreTorrentRemovedEvent', self._on_pre_torrent_removed 117 ) 113 118 114 119 def disable(self): 115 120 component.get('EventManager').deregister_event_handler( 116 121 'TorrentFinishedEvent', self._on_torrent_finished 117 122 ) 123 component.get('EventManager').deregister_event_handler( 124 'PreTorrentRemovedEvent', self._on_pre_torrent_removed 125 ) 118 126 119 127 def update(self): 120 128 pass 121 129 130 def _check_torrent_file(self, f): 131 checkfl, file_ext = False, None 132 file_root, file_ext = os.path.splitext(f['path']) 133 file_ext_sec = os.path.splitext(file_root)[1] 134 if file_ext_sec and file_ext_sec + file_ext in EXTRACT_COMMANDS: 135 checkfl, file_ext = True, file_ext_sec + file_ext 136 elif file_ext not in EXTRACT_COMMANDS or file_ext_sec == '.tar': 137 log.debug('Cannot extract file with unknown file type: %s', f['path']) 138 elif file_ext == '.rar' and 'part' in file_ext_sec: 139 part_num = file_ext_sec.split('part')[1] 140 if part_num.isdigit() and int(part_num) != 1: 141 log.debug('Skipping remaining multi-part rar files: %s', f['path']) 142 else: 143 checkfl = True 144 else: 145 checkfl = True 146 return checkfl, file_ext 147 148 def _check_torrent_files(self, tid): 149 files = tid.get_files() 150 for f in files: 151 checkfl, file_ext = self._check_torrent_file(f) 152 if not checkfl: 153 continue 154 else: 155 return True 156 return False 157 122 158 def _on_torrent_finished(self, torrent_id): 123 159 """ 124 160 This is called when a torrent finishes and checks if any files to extract. 125 161 """ 126 162 tid = component.get('TorrentManager').torrents[torrent_id] 127 163 tid_status = tid.get_status(['download_location', 'name']) 128 129 164 files = tid.get_files() 130 165 for f in files: 131 file_root, file_ext = os.path.splitext(f['path']) 132 file_ext_sec = os.path.splitext(file_root)[1] 133 if file_ext_sec and file_ext_sec + file_ext in EXTRACT_COMMANDS: 134 file_ext = file_ext_sec + file_ext 135 elif file_ext not in EXTRACT_COMMANDS or file_ext_sec == '.tar': 136 log.debug('Cannot extract file with unknown file type: %s', f['path']) 166 checkfl, file_ext = self._check_torrent_file(f) 167 if not checkfl: 137 168 continue 138 elif file_ext == '.rar' and 'part' in file_ext_sec:139 part_num = file_ext_sec.split('part')[1]140 if part_num.isdigit() and int(part_num) != 1:141 log.debug('Skipping remaining multi-part rar files: %s', f['path'])142 continue143 144 169 cmd = EXTRACT_COMMANDS[file_ext] 145 170 fpath = os.path.join( 146 171 tid_status['download_location'], os.path.normpath(f['path']) … … 179 204 ) 180 205 d.addCallback(on_extract, torrent_id, fpath) 181 206 207 def _on_pre_torrent_removed(self, torrent_id): 208 """ 209 This is called when a torrent is removed. 210 """ 211 if self.config['auto_delete']: 212 tid = component.get('TorrentManager').torrents[torrent_id] 213 tid_status = tid.get_status(['download_location', 'name']) 214 if self._check_torrent_files(tid): 215 dest = os.path.normpath(self.config['extract_path']) 216 dest = os.path.join(dest, tid_status['name']) 217 if os.path.isdir(dest): 218 def on_rmtree_error(function, path, excinfo): 219 log.error( 220 'Removing previously extracted files for torrent %s in %s failed: %s', 221 torrent_id, 222 dest, 223 traceback.format_exception(*excinfo), 224 ) 225 226 log.debug( 227 'Removing previously extracted files for torrent %s in %s', 228 torrent_id, 229 dest, 230 ) 231 shutil.rmtree(dest, onerror=on_rmtree_error) 232 182 233 @export 183 234 def set_config(self, config): 184 235 """Sets the config dictionary.""" -
plugins/Extractor-0.7.egg/deluge_extractor/data/extractor.js
old new 56 56 boxLabel: _('Create torrent name sub-folder'), 57 57 }); 58 58 59 this.auto_delete = fieldset.add({ 60 xtype: 'checkbox', 61 name: 'auto_delete', 62 height: 22, 63 hideLabel: true, 64 boxLabel: _('Auto-delete previously extracted files on deletion'), 65 }); 66 59 67 this.on('show', this.updateConfig, this); 60 68 }, 61 69 … … 65 73 66 74 config['extract_path'] = this.extract_path.getValue(); 67 75 config['use_name_folder'] = this.use_name_folder.getValue(); 76 config['auto_delete'] = this.auto_delete.getValue(); 68 77 69 78 deluge.client.extractor.set_config(config); 70 79 }, … … 78 87 success: function(config) { 79 88 this.extract_path.setValue(config['extract_path']); 80 89 this.use_name_folder.setValue(config['use_name_folder']); 90 this.auto_delete.setValue(config['auto_delete']); 81 91 }, 82 92 scope: this, 83 93 }); -
plugins/Extractor-0.7.egg/deluge_extractor/data/extractor_prefs.ui
old new 100 100 <property name="position">1</property> 101 101 </packing> 102 102 </child> 103 <child> 104 <object class="GtkCheckButton" id="chk_auto_delete"> 105 <property name="label" translatable="yes">Auto-delete previously extracted files on deletion</property> 106 <property name="visible">True</property> 107 <property name="can_focus">True</property> 108 <property name="receives_default">False</property> 109 <property name="tooltip_text" translatable="yes">This option will automatically delete previously extracted files on torrent deletion.</property> 110 <property name="draw_indicator">True</property> 111 </object> 112 <packing> 113 <property name="expand">False</property> 114 <property name="fill">False</property> 115 <property name="position">1</property> 116 </packing> 117 </child> 103 118 </object> 104 119 </child> 105 120 <child type="label"> -
plugins/Extractor-0.7.egg/deluge_extractor/gtkui.py
old new 69 69 config = { 70 70 'extract_path': path, 71 71 'use_name_folder': self.builder.get_object('chk_use_name').get_active(), 72 'auto_delete': self.builder.get_object('chk_auto_delete').get_active(), 72 73 } 73 74 74 75 client.extractor.set_config(config) … … 92 93 self.builder.get_object('chk_use_name').set_active( 93 94 config['use_name_folder'] 94 95 ) 96 self.builder.get_object('chk_auto_delete').set_active( 97 config['auto_delete'] 98 ) 95 99 96 100 client.extractor.get_config().addCallback(on_get_config)