From 68030a102433035b6e72b0e573e62efcb75d07f0 Mon Sep 17 00:00:00 2001 From: davide-romanini Date: Sun, 1 Mar 2015 16:14:01 +0100 Subject: [PATCH] updated to unrar 0.3 --- comicapi/comicarchive.py | 51 +++------------------------------------- requirements.txt | 4 ++-- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index 30fb3e5..353277d 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -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( diff --git a/requirements.txt b/requirements.txt index fc0dc23..cf93ce2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file +PyPDF2==1.24