<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import os <EOL> import subprocess <EOL> from pypet . trajectory import load_trajectory <EOL> from pypet import pypetconstants <EOL> def compact_hdf5_file ( filename , name = None , index = None , keep_backup = True ) : <EOL> """<STR_LIT>""" <EOL> if name is None and index is None : <EOL> index = - <NUM_LIT:1> <EOL> tmp_traj = load_trajectory ( name , index , as_new = False , load_all = pypetconstants . LOAD_NOTHING , <EOL> force = True , filename = filename ) <EOL> service = tmp_traj . v_storage_service <EOL> complevel = service . complevel <EOL> complib = service . complib <EOL> shuffle = service . shuffle <EOL> fletcher32 = service . fletcher32 <EOL> name_wo_ext , ext = os . path . splitext ( filename ) <EOL> tmp_filename = name_wo_ext + '<STR_LIT>' + ext <EOL> abs_filename = os . path . abspath ( filename ) <EOL> abs_tmp_filename = os . path . abspath ( tmp_filename ) <EOL> command = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , complib , <EOL> '<STR_LIT>' , str ( complevel ) , <EOL> '<STR_LIT>' , str ( int ( shuffle ) ) , <EOL> '<STR_LIT>' , str ( int ( fletcher32 ) ) , <EOL> abs_filename , abs_tmp_filename ] <EOL> str_command = '<STR_LIT:U+0020>' . join ( command ) <EOL> print ( '<STR_LIT>' % str_command ) <EOL> retcode = subprocess . call ( command ) <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' % <EOL> ( filename , str ( retcode ) ) ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> if keep_backup : <EOL> backup_file_name = name_wo_ext + '<STR_LIT>' + ext <EOL> os . rename ( filename , backup_file_name ) <EOL> else : <EOL> os . remove ( filename ) <EOL> os . rename ( tmp_filename , filename ) <EOL> print ( '<STR_LIT>' ) <EOL> return retcode </s>
