Allow custom unrar path. fix #3460

This commit is contained in:
Ruud
2014-06-30 22:38:18 +02:00
parent 33ad4c22c7
commit 169ddeef5d
4 changed files with 27 additions and 21 deletions

View File

@@ -1140,7 +1140,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
log.info('Archive %s found. Extracting...', os.path.basename(archive['file']))
try:
rar_handle = RarFile(archive['file'])
rar_handle = RarFile(archive['file'], custom_path = self.conf('unrar_path'))
extr_path = os.path.join(from_folder, os.path.relpath(os.path.dirname(archive['file']), folder))
self.makeDir(extr_path)
for packedinfo in rar_handle.infolist():
@@ -1282,6 +1282,11 @@ config = [{
'description': 'Extract rar files if found.',
'default': False,
},
{
'advanced': True,
'name': 'unrar_path',
'description': 'Custom path to unrar bin',
},
{
'name': 'cleanup',
'type': 'bool',

View File

@@ -86,7 +86,7 @@ class RarInfo(object):
class RarFile(RarFileImplementation):
def __init__(self, archiveName, password=None):
def __init__(self, archiveName, password=None, custom_path = None):
"""Instantiate the archive.
archiveName is the name of the RAR file.
@@ -99,7 +99,7 @@ class RarFile(RarFileImplementation):
This is a test.
"""
self.archiveName = archiveName
RarFileImplementation.init(self, password)
RarFileImplementation.init(self, password, custom_path)
def __del__(self):
self.destruct()

View File

@@ -46,11 +46,12 @@ if os.path.isfile(osx_unrar) and 'darwin' in platform.platform().lower():
except:
pass
def call_unrar(params):
def call_unrar(params, custom_path = None):
"Calls rar/unrar command line executable, returns stdout pipe"
global rar_executable_cached
if rar_executable_cached is None:
for command in ('unrar', 'rar', osx_unrar):
for command in (custom_path, 'unrar', 'rar', osx_unrar):
if not command: continue
try:
subprocess.Popen([command], stdout = subprocess.PIPE)
rar_executable_cached = command
@@ -70,10 +71,10 @@ def call_unrar(params):
class RarFileImplementation(object):
def init(self, password = None):
def init(self, password = None, custom_path = None):
global rar_executable_version
self.password = password
self.custom_path = custom_path
stdoutdata, stderrdata = self.call('v', []).communicate()
@@ -129,7 +130,7 @@ class RarFileImplementation(object):
def call(self, cmd, options = [], files = []):
options2 = options + ['p' + self.escaped_password()]
soptions = ['-' + x for x in options2]
return call_unrar([cmd] + soptions + ['--', self.archiveName] + files)
return call_unrar([cmd] + soptions + ['--', self.archiveName] + files, self.custom_path)
def infoiter(self):

View File

@@ -237,7 +237,7 @@ def generate_password_provider(password):
class RarFileImplementation(object):
def init(self, password=None):
def init(self, password=None, custom_path = None):
self.password = password
archiveData = RAROpenArchiveDataEx(ArcNameW=self.archiveName, OpenMode=RAR_OM_EXTRACT)
self._handle = RAROpenArchiveEx(ctypes.byref(archiveData))