How to use the ratarmount.ProgressBar function in ratarmount

To help you get started, we’ve selected a few ratarmount examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mxmlnkn / ratarmount / ratarmount.py View on Github external
# 2. Open TAR file reader
        try:
            streamed = ( 'IndexedBzip2File' in globals() and isinstance( fileObject, IndexedBzip2File ) ) or \
                       ( 'IndexedGzipFile' in globals() and isinstance( fileObject, IndexedGzipFile ) )
            # r: uses seeks to skip to the next file inside the TAR while r| doesn't do any seeks.
            # r| might be slower but for compressed files we have to go over all the data once anyways
            # and I had problems with seeks at this stage. Maybe they are gone now after the bz2 bugfix though.
            loadedTarFile = tarfile.open( fileobj = fileObject, mode = 'r|' if streamed else 'r:', ignore_zeros = True )
        except tarfile.ReadError as exception:
            print( "Archive can't be opened! This might happen for compressed TAR archives, "
                   "which currently is not supported." )
            raise exception

        if progressBar is None:
            progressBar = ProgressBar( os.fstat( fileObject.fileno() ).st_size )

        # 3. Iterate over files inside TAR and add them to the database
        try:
          for tarInfo in loadedTarFile:
            loadedTarFile.members = []
            globalOffset = streamOffset + tarInfo.offset_data
            globalOffsetHeader = streamOffset + tarInfo.offset
            if 'IndexedBzip2File' in globals() and isinstance( fileObject, IndexedBzip2File ):
                # We will have to adjust the global offset to a rough estimate of the real compressed size.
                # Note that tell_compressed is always one bzip2 block further, which leads to underestimated
                # file compression ratio especially in the beginning.
                progressBar.update( int( globalOffset * fileObject.tell_compressed() / 8 / fileObject.tell() ) )
            elif 'IndexedGzipFile' in globals() and isinstance( fileObject, IndexedGzipFile ):
                try:
                    progressBar.update( int( globalOffset * fileObject.fileobj().tell() / fileObject.tell() ) )
                except: