def flush(block, fileToWrite ,ftp , storage_path, size, name): global log_ctr if was_dia_cancelled(): fileToWrite.close() raise Exception('User cancel') else: fileToWrite.write(block) if log_ctr % 2000 == 0: progress = (float(os.path.getsize(storage_path)) / size)*100 log_dia('Fetching zipfile for %s, progress %.1f%%' %(name, progress)) log_ctr = log_ctr + 1
def extract_file(location, target,curr_item,was_install): fh = open(location, 'rb') was_cancelled = False ctr = 0 try: z = zipfile.ZipFile(fh) for name in z.namelist(): try: outpath = target z.extract(name, outpath) if ctr % UPDATE_LOG_DIA_EVERY == 0: log_dia('Extracting %s' % name) if ctr % CHECK_REMAINING_STORAGE_EVERY == 0: if get_free_space_mb(target) < MIN_DISK_MB: wx.MessageBox('Not enough space left on device, cancelling', 'Info',wx.OK | wx.ICON_WARNING) was_cancelled = True break if was_dia_cancelled(): was_cancelled = True break ctr += 1 except: log_dia_info('unable to extract [%s]' %name) except: raise InvalidZipFileException('Invalid zipentry') finally: fh.close() if was_cancelled and was_install: folder = '%s/%s' % (target,curr_item.folder) log_dia_info('Cleaned up folder %s after cancel' % folder) delete_folder(folder) curr_item.was_installed = False delete_file(resolveDbFile(target,curr_item.name)) log_dia_info('Done')