[#2785] [Extractor] Fix successful claimed extract leaving empty folder

* The main fix here is adding os.environ to the command call otherwise in some configurations
   the extraction would fail. Was unable to reproduce locally but users confirm this fix works.
 * Refactored the code to properly report errors if the extract command fails along with actual
   command output.
 * Bump version to 0.5.
This commit is contained in:
Calum Lind 2016-05-31 00:29:54 +01:00
parent 7e229ceb2f
commit 2d5dce4954
2 changed files with 21 additions and 27 deletions

View File

@ -11,10 +11,11 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
import errno
import logging import logging
import os import os
from twisted.internet.utils import getProcessValue from twisted.internet.utils import getProcessOutputAndValue
from twisted.python.procutils import which from twisted.python.procutils import which
import deluge.component as component import deluge.component as component
@ -120,40 +121,33 @@ class Core(CorePluginBase):
if file_ext_sec and file_ext_sec + file_ext in EXTRACT_COMMANDS: if file_ext_sec and file_ext_sec + file_ext in EXTRACT_COMMANDS:
file_ext = file_ext_sec + file_ext file_ext = file_ext_sec + file_ext
elif file_ext not in EXTRACT_COMMANDS or file_ext_sec == '.tar': elif file_ext not in EXTRACT_COMMANDS or file_ext_sec == '.tar':
log.warning("Can't extract file with unknown file type: %s", f["path"]) log.debug("Can't extract file with unknown file type: %s", f["path"])
continue continue
cmd = EXTRACT_COMMANDS[file_ext] cmd = EXTRACT_COMMANDS[file_ext]
# Now that we have the cmd, lets run it to extract the files
fpath = os.path.join(tid_status["download_location"], os.path.normpath(f["path"])) fpath = os.path.join(tid_status["download_location"], os.path.normpath(f["path"]))
# Get the destination path
dest = os.path.normpath(self.config["extract_path"]) dest = os.path.normpath(self.config["extract_path"])
if self.config["use_name_folder"]: if self.config["use_name_folder"]:
name = tid_status["name"] dest = os.path.join(dest, tid_status["name"])
dest = os.path.join(dest, name)
# Create the destination folder if it doesn't exist try:
if not os.path.exists(dest): os.makedirs(dest)
try: except OSError as ex:
os.makedirs(dest) if not (ex.errno == errno.EEXIST and os.path.isdir(dest)):
except OSError as ex:
log.error("Error creating destination folder: %s", ex) log.error("Error creating destination folder: %s", ex)
return break
def on_extract_success(result, torrent_id, fpath): def on_extract(result, torrent_id, fpath):
# XXX: Emit an event # Check command exit code.
log.info("Extract successful: %s (%s)", fpath, torrent_id) if not result[2]:
log.info("Extract successful: %s (%s)", fpath, torrent_id)
else:
log.error("Extract failed: %s (%s) %s", fpath, torrent_id, result[1])
def on_extract_failed(result, torrent_id, fpath): # Run the command and add callback.
# XXX: Emit an event log.debug("Extracting %s from %s with %s %s to %s", fpath, torrent_id, cmd[0], cmd[1], dest)
log.error("Extract failed: %s (%s)", fpath, torrent_id) d = getProcessOutputAndValue(cmd[0], cmd[1].split() + [str(fpath)], os.environ, str(dest))
d.addCallback(on_extract, torrent_id, fpath)
# Run the command and add some callbacks
log.debug("Extracting %s with %s %s to %s", fpath, cmd[0], cmd[1], dest)
d = getProcessValue(cmd[0], cmd[1].split() + [str(fpath)], {}, str(dest))
d.addCallback(on_extract_success, torrent_id, fpath)
d.addErrback(on_extract_failed, torrent_id, fpath)
@export @export
def set_config(self, config): def set_config(self, config):

View File

@ -16,7 +16,7 @@ from setuptools import find_packages, setup
__plugin_name__ = "Extractor" __plugin_name__ = "Extractor"
__author__ = "Andrew Resch" __author__ = "Andrew Resch"
__author_email__ = "andrewresch@gmail.com" __author_email__ = "andrewresch@gmail.com"
__version__ = "0.3" __version__ = "0.5"
__url__ = "http://deluge-torrent.org" __url__ = "http://deluge-torrent.org"
__license__ = "GPLv3" __license__ = "GPLv3"
__description__ = "Extract files upon torrent completion" __description__ = "Extract files upon torrent completion"