updated to unrar 0.3

This commit is contained in:
davide-romanini 2015-03-01 16:14:01 +01:00
parent d84110ccb2
commit 54011ae5a6

View File

@ -55,50 +55,6 @@ from filenameparser import FileNameParser
sys.path.insert(0, os.path.abspath(".")) 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: class MetaDataStyle:
CBI = 0 CBI = 0
CIX = 1 CIX = 1
@ -170,7 +126,7 @@ class ZipArchiver:
def getArchiveFilenameList(self): def getArchiveFilenameList(self):
try: try:
zf = zipfile.ZipFile(self.path, 'r') zOf = zipfile.ZipFile(self.path, 'r')
namelist = zf.namelist() namelist = zf.namelist()
zf.close() zf.close()
return namelist return namelist
@ -378,7 +334,7 @@ class RarArchiver:
#tmp_folder = tempfile.mkdtemp() #tmp_folder = tempfile.mkdtemp()
#tmp_file = os.path.join(tmp_folder, archive_file) #tmp_file = os.path.join(tmp_folder, archive_file)
#rarc.extract(archive_file, tmp_folder) #rarc.extract(archive_file, tmp_folder)
data = rarc.open(archive_file) data = rarc.open(archive_file).read()
#data = open(tmp_file).read() #data = open(tmp_file).read()
entries = [(rarc.getinfo(archive_file), data)] entries = [(rarc.getinfo(archive_file), data)]
@ -505,8 +461,7 @@ class RarArchiver:
while tries < 7: while tries < 7:
try: try:
tries = tries + 1 tries = tries + 1
#rarc = UnRAR2.RarFile( self.path ) rarc = rarfile.RarFile( self.path )
rarc = OpenableRarFile(self.path)
except (OSError, IOError) as e: except (OSError, IOError) as e:
print >> sys.stderr, u"getRARObj(): [{0}] {1} attempt#{2}".format( print >> sys.stderr, u"getRARObj(): [{0}] {1} attempt#{2}".format(