def processzip(self,name,full_path,file): rel_file=os.path.relpath(file,config.SOPDS_ROOT_LIB) zsize = os.path.getsize(file) if opdsdb.arc_skip(rel_file,zsize): self.arch_skipped+=1 self.logger.debug('Skip ZIP archive '+rel_file+'. Already scanned.') else: zip_process_error = 0 try: z = zipfile.ZipFile(file, 'r', allowZip64=True) filelist = z.namelist() cat = opdsdb.addcattree(rel_file, opdsdb.CAT_ZIP, zsize) for n in filelist: try: self.logger.debug('Start process ZIP file = '+file+' book file = '+n) file_size=z.getinfo(n).file_size bookfile = z.open(n) self.processfile(n,file,bookfile,cat,opdsdb.CAT_ZIP,file_size) bookfile.close() except zipfile.BadZipFile: self.logger.warning('Error processing ZIP file = '+file+' book file = '+n) zip_process_error = 1 z.close() self.arch_scanned+=1 except zipfile.BadZipFile: self.logger.warning('Error while read ZIP archive. File '+file+' corrupt.') zip_process_error = 1 self.bad_archives+=zip_process_error
def inpskip_callback(self, inpx, inp_name, inp_size): self.zip_file = os.path.join(inpx,"%s%s"%(inp_name,'.zip')) self.rel_path=os.path.relpath(self.zip_file,config.SOPDS_ROOT_LIB) if opdsdb.arc_skip(self.rel_path,inp_size): self.logger.info('Skip ZIP for INP archive '+self.zip_file+'. Not changed.') result = 1 else: self.logger.info('Start process ZIP for INP archive = '+self.zip_file) self.inp_cat = opdsdb.addcattree(self.rel_path, opdsdb.CAT_INP, inp_size) result = 0 return result