Python rarfile.Error() Examples
The following are 5
code examples of rarfile.Error().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rarfile
, or try the search function
.
Example #1
Source File: rar.py From ingestors with MIT License | 6 votes |
def unpack(self, file_path, temp_dir): # FIXME: need to figure out how to unpack multi-part files. try: with rarfile.RarFile(file_path) as rf: names = rf.namelist() encoding = self.detect_list_encoding(names) log.debug('Detected filename encoding: %s', encoding) for name in names: try: fh = rf.open(name) self.extract_member(temp_dir, name, fh, encoding=encoding) except Exception as ex: # TODO: should this be a fatal error? log.debug("Failed to unpack [%r]: %s", name, ex) except rarfile.NeedFirstVolume: raise ProcessingException('Cannot load splitted RAR files') except rarfile.Error as err: raise ProcessingException('Invalid RAR file: %s' % err)
Example #2
Source File: dumprar.py From Lector with GNU General Public License v3.0 | 5 votes |
def test(fn, psw): """Process one archive with error handling. """ try: test_real(fn, psw) except rf.NeedFirstVolume: xprint(" --- %s is middle part of multi-vol archive ---", fn) except rf.Error: exc, msg, tb = sys.exc_info() xprint("\n *** %s: %s ***\n", exc.__name__, msg) del tb except IOError: exc, msg, tb = sys.exc_info() xprint("\n *** %s: %s ***\n", exc.__name__, msg) del tb
Example #3
Source File: dumprar.py From addon with GNU General Public License v3.0 | 5 votes |
def test(fn, psw): """Process one archive with error handling. """ try: test_real(fn, psw) except rf.NeedFirstVolume: xprint(" --- %s is middle part of multi-vol archive ---", fn) except rf.Error: exc, msg, tb = sys.exc_info() xprint("\n *** %s: %s ***\n", exc.__name__, msg) del tb except IOError: exc, msg, tb = sys.exc_info() xprint("\n *** %s: %s ***\n", exc.__name__, msg) del tb
Example #4
Source File: magic.py From TitleDB with The Unlicense | 5 votes |
def process_rar_archive(parent, relatives, cache_path): filename = os.path.join(cache_path, parent.filename) results = list() try: with rarfile.RarFile(filename) as archive: for entry in archive.infolist(): switcher = { 'application/x-3ds-archive': process_cia, 'application/x-3ds-homebrew': process_tdsx, 'application/x-3ds-iconfile': process_smdh, 'application/x-3ds-arm9bin': process_arm9, 'application/x-3ds-xml': process_xml } action = switcher.get(determine_mimetype(entry.filename), None) if action: working_file = os.path.join(cache_path, 'archive_root', entry.filename) working_path = '/'.join(working_file.split('/')[:-1]) if not os.path.isdir(working_path): os.makedirs(working_path) with open(working_file, 'wb') as f: with archive.open(entry.filename, 'r') as a: for block in iter((lambda:a.read(32768)),''): if not block: break f.write(block) os.utime(working_file, (entry.date_time.timestamp(),entry.date_time.timestamp())) results.append(action(parent, relatives, cache_path, entry.filename)) except rarfile.Error as e: log.debug("Archive error: %s", e) if results: for result_item in results: # Match up any xml or smdh files in the same folder as our 3dsx. if result_item.__class__ in (XML, SMDH): matched = False for check_item in results: if not matched: matched = check_siblings(check_item, result_item) result_item.active = matched return(results)
Example #5
Source File: dumprar.py From bazarr with GNU General Public License v3.0 | 5 votes |
def test(fn, psw): """Process one archive with error handling. """ try: test_real(fn, psw) except rf.NeedFirstVolume: xprint(" --- %s is middle part of multi-vol archive ---", fn) except rf.Error: exc, msg, tb = sys.exc_info() xprint("\n *** %s: %s ***\n", exc.__name__, msg) del tb except IOError: exc, msg, tb = sys.exc_info() xprint("\n *** %s: %s ***\n", exc.__name__, msg) del tb