[#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 and the actual command output. * Bump version to 0.5.
This commit is contained in:
parent
1a11e085b2
commit
cbb7415a18
|
@ -37,9 +37,10 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import errno
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from twisted.internet.utils import getProcessValue
|
from twisted.internet.utils import getProcessOutputAndValue
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
from deluge.plugins.pluginbase import CorePluginBase
|
from deluge.plugins.pluginbase import CorePluginBase
|
||||||
|
@ -142,40 +143,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("EXTRACTOR: Can't extract file with unknown file type: %s" % f["path"])
|
log.debug("EXTRACTOR: 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["save_path"], os.path.normpath(f["path"]))
|
fpath = os.path.join(tid_status["save_path"], 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, ex:
|
||||||
os.makedirs(dest)
|
if not (ex.errno == errno.EEXIST and os.path.isdir(dest)):
|
||||||
except Exception, e:
|
log.error("EXTRACTOR: Error creating destination folder: %s", ex)
|
||||||
log.error("EXTRACTOR: Error creating destination folder: %s", e)
|
break
|
||||||
return
|
|
||||||
|
|
||||||
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("EXTRACTOR: Extract successful: %s (%s)", fpath, torrent_id)
|
if not result[2]:
|
||||||
|
log.info("EXTRACTOR: Extract successful: %s (%s)", fpath, torrent_id)
|
||||||
|
else:
|
||||||
|
log.error("EXTRACTOR: 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("EXTRACTOR: Extracting %s from %s with %s %s to %s", fpath, torrent_id, cmd[0], cmd[1], dest)
|
||||||
log.error("EXTRACTOR: 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("EXTRACTOR: 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):
|
||||||
|
|
|
@ -42,7 +42,7 @@ from setuptools import 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.4"
|
__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"
|
||||||
|
|
Loading…
Reference in New Issue