updated to unrar 0.3
This commit is contained in:
parent
983ad1fcf4
commit
68030a1024
@ -55,50 +55,6 @@ from filenameparser import FileNameParser
|
||||
|
||||
sys.path.insert(0, os.path.abspath("."))
|
||||
|
||||
|
||||
class OpenableRarFile(rarfile.RarFile):
|
||||
|
||||
def open(self, member):
|
||||
|
||||
# print "opening %s..." % member
|
||||
|
||||
# based on https://github.com/matiasb/python-unrar/pull/4/files
|
||||
res = []
|
||||
if isinstance(member, rarfile.RarInfo):
|
||||
member = member.filename
|
||||
archive = unrarlib.RAROpenArchiveDataEx(
|
||||
self.filename,
|
||||
mode=constants.RAR_OM_EXTRACT)
|
||||
handle = self._open(archive)
|
||||
found, buf = False, []
|
||||
|
||||
def _callback(msg, UserData, P1, P2):
|
||||
if msg == constants.UCM_PROCESSDATA:
|
||||
data = (ctypes.c_char * P2).from_address(P1).raw
|
||||
buf.append(data)
|
||||
return 1
|
||||
c_callback = unrarlib.UNRARCALLBACK(_callback)
|
||||
unrarlib.RARSetCallback(handle, c_callback, 1)
|
||||
try:
|
||||
rarinfo = self._read_header(handle)
|
||||
while rarinfo is not None:
|
||||
# print "checking rar archive %s against %s" % (
|
||||
# rarinfo.filename, member)
|
||||
if rarinfo.filename == member:
|
||||
self._process_current(handle, constants.RAR_TEST)
|
||||
found = True
|
||||
else:
|
||||
self._process_current(handle, constants.RAR_SKIP)
|
||||
rarinfo = self._read_header(handle)
|
||||
except unrarlib.UnrarException:
|
||||
raise rarfile.BadRarFile("Bad RAR archive data.")
|
||||
finally:
|
||||
self._close(handle)
|
||||
if not found:
|
||||
raise KeyError('There is no item named %r in the archive' % member)
|
||||
return ''.join(buf)
|
||||
|
||||
|
||||
class MetaDataStyle:
|
||||
CBI = 0
|
||||
CIX = 1
|
||||
@ -170,7 +126,7 @@ class ZipArchiver:
|
||||
|
||||
def getArchiveFilenameList(self):
|
||||
try:
|
||||
zf = zipfile.ZipFile(self.path, 'r')
|
||||
zOf = zipfile.ZipFile(self.path, 'r')
|
||||
namelist = zf.namelist()
|
||||
zf.close()
|
||||
return namelist
|
||||
@ -378,7 +334,7 @@ class RarArchiver:
|
||||
#tmp_folder = tempfile.mkdtemp()
|
||||
#tmp_file = os.path.join(tmp_folder, archive_file)
|
||||
#rarc.extract(archive_file, tmp_folder)
|
||||
data = rarc.open(archive_file)
|
||||
data = rarc.open(archive_file).read()
|
||||
#data = open(tmp_file).read()
|
||||
entries = [(rarc.getinfo(archive_file), data)]
|
||||
|
||||
@ -505,8 +461,7 @@ class RarArchiver:
|
||||
while tries < 7:
|
||||
try:
|
||||
tries = tries + 1
|
||||
#rarc = UnRAR2.RarFile( self.path )
|
||||
rarc = OpenableRarFile(self.path)
|
||||
rarc = rarfile.RarFile( self.path )
|
||||
|
||||
except (OSError, IOError) as e:
|
||||
print >> sys.stderr, u"getRARObj(): [{0}] {1} attempt#{2}".format(
|
||||
|
@ -1,5 +1,5 @@
|
||||
configparser
|
||||
beautifulsoup4 >= 4.1
|
||||
-e git+https://github.com/matiasb/python-unrar.git@1010cf5f6fcf09a9b1fe7c958faf0167fafaa7d9#egg=unrar-master
|
||||
unrar==0.3
|
||||
natsort==3.5.2
|
||||
PyPDF2==1.24
|
||||
PyPDF2==1.24
|
||||
|
Loading…
Reference in New Issue
Block a user