Skip to content

Commit

Permalink
io
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Aug 20, 2024
1 parent b5fec93 commit 5a3e9cb
Show file tree
Hide file tree
Showing 12 changed files with 1,418 additions and 609 deletions.
2 changes: 1 addition & 1 deletion .aux/test_with_lcg
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ CMTCONFIG=$2
source /cvmfs/sft.cern.ch/lcg/views/${LCG}/${CMTCONFIG}/setup.sh
source build/INSTALL/thisostap.sh
cd build
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j4 --output-on-failure
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j4 -R _io_ --output-on-failure

7 changes: 0 additions & 7 deletions ostap/core/ostap_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,6 @@ def all_strings ( *args ) :
docme ( __name__ , logger = logger )


# =============================================================================
if '__main__' == __name__ :

from ostap.utils.docme import docme
docme ( __name__ , logger = logger )


# =============================================================================
## The END
# =============================================================================
106 changes: 55 additions & 51 deletions ostap/io/bz2shelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,35 @@ class Bz2Shelf(CompressShelf):
extensions = '.tbz' , '.tbz2' , '.bz2'
##
def __init__(
self ,
filename ,
mode = 'c' ,
protocol = PROTOCOL ,
compress = 9 ,
writeback = False ,
silent = False ,
keyencoding = ENCODING ) :

self ,
filename ,
mode = 'c' ,
dbtype = '' ,
protocol = PROTOCOL ,
compress = 9 ,
writeback = False ,
silent = False ,
keyencoding = ENCODING ) :

## save arguments for pickling....
self.__init_args = ( filename ,
mode ,
dbtype ,
protocol ,
compress ,
writeback ,
silent )

## initialize the base class
CompressShelf.__init__ ( self ,
filename ,
mode ,
protocol ,
compress ,
writeback ,
silent ,
keyencoding )
CompressShelf.__init__ ( self ,
filename ,
mode = mode ,
dbtype = dbtype ,
protocol = protocol ,
compress = compress ,
writeback = writeback ,
silent = silent ,
keyencoding = keyencoding )

## needed for proper (un)pickling
def __getinitargs__ ( self ) :
Expand Down Expand Up @@ -266,10 +269,6 @@ def compress_item ( self , value ) :
"""Compress (zip) the item using ``bz2.compress''
- see bz2.compress
"""
## f = BytesIO ()
## p = Pickler ( f , self.protocol )
## p.dump ( value )
## return bz2.compress ( f.getvalue() , self.compresslevel )
return bz2.compress ( self.pickle ( value ) , self.compresslevel )

# =========================================================================
Expand All @@ -278,8 +277,6 @@ def uncompress_item ( self , value ) :
"""Uncompress (bzip2) the item using ``bz2.decompress''
- see bz2.decompress
"""
## f = BytesIO ( bz2.decompress ( value ) )
## return Unpickler ( f ) . load ( )
return self.unpickle ( bz2.decompress ( value ) )

# =========================================================================
Expand All @@ -295,6 +292,7 @@ def clone ( self , new_name , keys = () ) :
"""
new_db = Bz2Shelf ( new_name ,
mode = 'c' ,
dbtype = self.dbtype ,
protocol = self.protocol ,
compress = self.compresslevel ,
writeback = self.writeback ,
Expand All @@ -313,8 +311,9 @@ def clone ( self , new_name , keys = () ) :
# @date 2010-04-30
def open ( filename ,
mode = 'c' ,
dbtype = '' ,
protocol = PROTOCOL ,
compresslevel = 9 ,
compress = 9 ,
writeback = False ,
silent = True ,
keyencoding = ENCODING ) :
Expand All @@ -331,13 +330,14 @@ def open ( filename ,
See the module's __doc__ string for an overview of the interface.
"""

return Bz2Shelf ( filename ,
mode ,
protocol ,
compresslevel ,
writeback ,
silent ,
keyencoding )
return Bz2Shelf ( filename ,
mode = mode ,
dbtype = dbtype ,
protocol = protocol ,
compress = compress ,
writeback = writeback ,
silent = silent ,
keyencoding = keyencoding )

# =============================================================================
## @class TmpBz2Shelf
Expand All @@ -349,6 +349,7 @@ class TmpBz2Shelf(Bz2Shelf,TmpDB):
TEMPORARY ``bzip2''-version of ``shelve''-database
"""
def __init__( self ,
dbtype = '' ,
protocol = HIGHEST_PROTOCOL ,
compress = 9 ,
silent = False ,
Expand All @@ -360,14 +361,15 @@ def __init__( self ,
TmpDB.__init__ ( self , suffix = '.bz2db' , remove = remove , keep = keep )

## open DB
Bz2Shelf.__init__ ( self ,
self.tmp_name ,
'c' ,
protocol ,
compress ,
False , ## writeback
silent ,
keyencoding )
Bz2Shelf.__init__ ( self ,
self.tmp_name ,
dbtype = dbtype ,
mode = 'c' ,
protocol = protocol ,
compress = compress ,
writeback = False , ## writeback
silent = silent ,
keyencoding = keyencoding )

## close and delete the file
def close ( self ) :
Expand All @@ -380,25 +382,27 @@ def close ( self ) :
## helper function to open TEMPORARY ZipShelve data base#
# @author Vanya BELYAEV [email protected]
# @date 2010-04-30
def tmpdb ( protocol = HIGHEST_PROTOCOL ,
compresslevel = 9 ,
silent = True ,
keyencoding = ENCODING ,
remove = True , ## immediate remove
keep = False ) : ## keep it
def tmpdb ( dbtype = '' ,
protocol = HIGHEST_PROTOCOL ,
compress = 9 ,
silent = True ,
keyencoding = ENCODING ,
remove = True , ## immediate remove
keep = False ) : ## keep it
"""Open a TEMPORARY persistent dictionary for reading and writing.
The optional protocol parameter specifies the
version of the pickle protocol (0, 1, or 2).
See the module's __doc__ string for an overview of the interface.
"""
return TmpBz2Shelf ( protocol ,
compresslevel ,
silent ,
keyencoding ,
remove ,
keep )
return TmpBz2Shelf ( dbtype = dbtype ,
protocol = protocol ,
compress = compress ,
silent = silent ,
keyencoding = keyencoding ,
remove = remove ,
keep = keep )

# =============================================================================
if '__main__' == __name__ :
Expand Down
Loading

0 comments on commit 5a3e9cb

Please sign in to comment.