Allow custom unrar path. fix #3460
This commit is contained in:
@@ -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']))
|
log.info('Archive %s found. Extracting...', os.path.basename(archive['file']))
|
||||||
try:
|
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))
|
extr_path = os.path.join(from_folder, os.path.relpath(os.path.dirname(archive['file']), folder))
|
||||||
self.makeDir(extr_path)
|
self.makeDir(extr_path)
|
||||||
for packedinfo in rar_handle.infolist():
|
for packedinfo in rar_handle.infolist():
|
||||||
@@ -1282,6 +1282,11 @@ config = [{
|
|||||||
'description': 'Extract rar files if found.',
|
'description': 'Extract rar files if found.',
|
||||||
'default': False,
|
'default': False,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'advanced': True,
|
||||||
|
'name': 'unrar_path',
|
||||||
|
'description': 'Custom path to unrar bin',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'name': 'cleanup',
|
'name': 'cleanup',
|
||||||
'type': 'bool',
|
'type': 'bool',
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class RarInfo(object):
|
|||||||
|
|
||||||
class RarFile(RarFileImplementation):
|
class RarFile(RarFileImplementation):
|
||||||
|
|
||||||
def __init__(self, archiveName, password=None):
|
def __init__(self, archiveName, password=None, custom_path = None):
|
||||||
"""Instantiate the archive.
|
"""Instantiate the archive.
|
||||||
|
|
||||||
archiveName is the name of the RAR file.
|
archiveName is the name of the RAR file.
|
||||||
@@ -99,7 +99,7 @@ class RarFile(RarFileImplementation):
|
|||||||
This is a test.
|
This is a test.
|
||||||
"""
|
"""
|
||||||
self.archiveName = archiveName
|
self.archiveName = archiveName
|
||||||
RarFileImplementation.init(self, password)
|
RarFileImplementation.init(self, password, custom_path)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.destruct()
|
self.destruct()
|
||||||
|
|||||||
+6
-5
@@ -46,11 +46,12 @@ if os.path.isfile(osx_unrar) and 'darwin' in platform.platform().lower():
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def call_unrar(params):
|
def call_unrar(params, custom_path = None):
|
||||||
"Calls rar/unrar command line executable, returns stdout pipe"
|
"Calls rar/unrar command line executable, returns stdout pipe"
|
||||||
global rar_executable_cached
|
global rar_executable_cached
|
||||||
if rar_executable_cached is None:
|
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:
|
try:
|
||||||
subprocess.Popen([command], stdout = subprocess.PIPE)
|
subprocess.Popen([command], stdout = subprocess.PIPE)
|
||||||
rar_executable_cached = command
|
rar_executable_cached = command
|
||||||
@@ -70,10 +71,10 @@ def call_unrar(params):
|
|||||||
|
|
||||||
class RarFileImplementation(object):
|
class RarFileImplementation(object):
|
||||||
|
|
||||||
def init(self, password = None):
|
def init(self, password = None, custom_path = None):
|
||||||
global rar_executable_version
|
global rar_executable_version
|
||||||
self.password = password
|
self.password = password
|
||||||
|
self.custom_path = custom_path
|
||||||
|
|
||||||
stdoutdata, stderrdata = self.call('v', []).communicate()
|
stdoutdata, stderrdata = self.call('v', []).communicate()
|
||||||
|
|
||||||
@@ -129,7 +130,7 @@ class RarFileImplementation(object):
|
|||||||
def call(self, cmd, options = [], files = []):
|
def call(self, cmd, options = [], files = []):
|
||||||
options2 = options + ['p' + self.escaped_password()]
|
options2 = options + ['p' + self.escaped_password()]
|
||||||
soptions = ['-' + x for x in options2]
|
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):
|
def infoiter(self):
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ def generate_password_provider(password):
|
|||||||
|
|
||||||
class RarFileImplementation(object):
|
class RarFileImplementation(object):
|
||||||
|
|
||||||
def init(self, password=None):
|
def init(self, password=None, custom_path = None):
|
||||||
self.password = password
|
self.password = password
|
||||||
archiveData = RAROpenArchiveDataEx(ArcNameW=self.archiveName, OpenMode=RAR_OM_EXTRACT)
|
archiveData = RAROpenArchiveDataEx(ArcNameW=self.archiveName, OpenMode=RAR_OM_EXTRACT)
|
||||||
self._handle = RAROpenArchiveEx(ctypes.byref(archiveData))
|
self._handle = RAROpenArchiveEx(ctypes.byref(archiveData))
|
||||||
|
|||||||
Reference in New Issue
Block a user