Private GIT

Skip to content
Snippets Groups Projects
Commit f458db75 authored by Dustyn Gibson's avatar Dustyn Gibson
Browse files

Update unrar2 to 2fe1e98

parent 95fbff94
No related branches found
No related tags found
No related merge requests found
f2570b5f7205f1433661a9508f464f691cf63389 0.97
d3595b2c9a1aec510f8ae1dcfef1eb8562a77fc0 0.99.1
d23822f936c663784c5edda09cd5a6effe1e882d 0.99.2
855a137f51581bd6d7a79264856020aa52fd0b66 0.99.3
160655e623388d65c35ac4c8e271b58566e8a489 0.99.4
8225eb999c02735d0aead538870c91270d41df0c 0.99.5
734f8f605597616bc102b60ca1e959d3a0ace5b6 0.99.6
......@@ -28,7 +28,3 @@ class InvalidRARArchive(Exception): pass
class FileOpenError(Exception): pass
class IncorrectRARPassword(Exception): pass
class InvalidRARArchiveUsage(Exception): pass
class FatalRARError(Exception): pass
class CRCRARError(Exception): pass
class NoFileToExtract(Exception): pass
class GenericRARError(Exception): pass
import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)
import os, sys
import unrar2 as UnRAR2
from unrar2.rar_exceptions import *
import UnRAR2
from UnRAR2.rar_exceptions import *
def cleanup(dir='test'):
......
......@@ -63,11 +63,8 @@ class RarFileImplementation(object):
global rar_executable_version
self.password = password
proc = self.call('v', [])
stdoutdata, stderrdata = proc.communicate()
# Use unrar return code if available
self._check_returncode(proc.returncode)
stdoutdata, stderrdata = self.call('v', []).communicate()
for line in stderrdata.splitlines():
if line.strip().startswith("Cannot open"):
......@@ -126,11 +123,7 @@ class RarFileImplementation(object):
def infoiter(self):
command = "v" if rar_executable_version == 4 else "l"
proc = self.call(command, ['c-'])
stdoutdata, stderrdata = proc.communicate()
# Use unrar return code if available
self._check_returncode(proc.returncode)
stdoutdata, stderrdata = self.call(command, ['c-']).communicate()
for line in stderrdata.splitlines():
if line.strip().startswith("Cannot open"):
......@@ -142,7 +135,7 @@ class RarFileImplementation(object):
while not line.startswith('-----------'):
if line.strip().endswith('is not RAR archive'):
raise InvalidRARArchive
if line.startswith("CRC failed") or line.startswith("Checksum error") or line.startswith("checksum error"):
if line.startswith("CRC failed") or line.startswith("Checksum error"):
raise IncorrectRARPassword
line = source.next()
line = source.next()
......@@ -217,46 +210,9 @@ class RarFileImplementation(object):
names.append(path)
proc = self.call(command, options, names)
stdoutdata, stderrdata = proc.communicate()
# Use unrar return code if available
self._check_returncode(proc.returncode)
if stderrdata.find("CRC failed")>=0 or stderrdata.find("Checksum error")>=0 or stderrdata.find("checksum error")>=0:
raise CRCRARError
if stderrdata.find("No files to extract")>=0:
raise NoFileToExtract
if stderrdata.find("Bad archive")>=0:
raise FatalRARError
return res
def _check_returncode(self, returncode):
# RAR exit code from unrarsrc-5.2.1.tar.gz/errhnd.hpp
RARX_SUCCESS = 0
RARX_WARNING = 1
RARX_FATAL = 2
RARX_CRC = 3
RARX_LOCK = 4
RARX_WRITE = 5
RARX_OPEN = 6
RARX_USERERROR = 7
RARX_MEMORY = 8
RARX_CREATE = 9
RARX_NOFILES = 10
RARX_BADPWD = 11
RARX_USERBREAK = 255
if returncode != RARX_SUCCESS:
if returncode == RARX_FATAL:
raise FatalRARError
elif returncode == RARX_CRC:
raise CRCRARError
elif returncode == RARX_BADPWD:
if stderrdata.find("CRC failed")>=0 or stderrdata.find("Checksum error")>=0:
raise IncorrectRARPassword
elif returncode == RARX_NOFILES:
raise NoFileToExtract
else:
raise GenericRARError
return res
def destruct(self):
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment