import gzip, FuseArchive, logging, cPickle gzip_compress_level = 6 class Serializer: """This lets us experiment with different main file serializers""" @staticmethod def dump( f, obj ): out = open( f, "wb" ) Serializer.dumpfh( obj, out ) # new file format out.close() @staticmethod def dumpfh( fh, obj ): logging.debug( "Going to serialize %s to %s" % ( obj, fh ) ) fh.truncate( 0 ) fh.seek( 0 ) f = gzip.GzipFile( None, "wb", gzip_compress_level, fh ) #f = fh cPickle.dump( obj, f, -1 ) del f fh.flush() @staticmethod def load( f ): if FuseArchive.magic_profiling: return { 'size': 0, 'chunks': 0, 'chunk_size': 0 } inp = open( f, "rb" ) magic = Serializer.loadfh( inp ) inp.close() return magic @staticmethod def loadfh( fh ): logging.debug( "Going to load from %s" % fh ) fh.seek( 0 ) f = gzip.GzipFile( None, "rb", gzip_compress_level, fh ) #f = fh magic = cPickle.load( f ) return( magic )