<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from __future__ import absolute_import <EOL> import sys <EOL> import time <EOL> import os . path <EOL> import argparse <EOL> import warnings <EOL> from tables . file import open_file <EOL> from tables . group import Group <EOL> from tables . leaf import Filters <EOL> from tables . flavor import internal_flavor <EOL> from tables . exceptions import OldIndexWarning , NoSuchNodeError , FlavorWarning <EOL> verbose = False <EOL> regoldindexes = True <EOL> createsysattrs = True <EOL> numpy_aliases = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def newdst_group ( dstfileh , dstgroup , title , filters ) : <EOL> group = dstfileh . root <EOL> for nodename in dstgroup . split ( '<STR_LIT:/>' ) : <EOL> if nodename == '<STR_LIT>' : <EOL> continue <EOL> try : <EOL> group2 = dstfileh . get_node ( group , nodename ) <EOL> except NoSuchNodeError : <EOL> group2 = dstfileh . create_group ( group , nodename , <EOL> title = title , <EOL> filters = filters ) <EOL> group = group2 <EOL> return group <EOL> def recreate_indexes ( table , dstfileh , dsttable ) : <EOL> listoldindexes = table . _listoldindexes <EOL> if listoldindexes != [ ] : <EOL> if not regoldindexes : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % <EOL> ( dstfileh . filename , dsttable . _v_pathname ) ) <EOL> return <EOL> if verbose : <EOL> print ( "<STR_LIT>" % <EOL> ( dstfileh . filename , dsttable . _v_pathname ) ) <EOL> for colname in listoldindexes : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % colname ) <EOL> colobj = dsttable . cols . _f_col ( colname ) <EOL> colobj . create_index ( filters = None ) <EOL> def copy_leaf ( srcfile , dstfile , srcnode , dstnode , title , <EOL> filters , copyuserattrs , overwritefile , overwrtnodes , stats , <EOL> start , stop , step , chunkshape , sortby , check_CSI , <EOL> propindexes , upgradeflavors ) : <EOL> srcfileh = open_file ( srcfile , '<STR_LIT:r>' ) <EOL> srcnode = srcfileh . get_node ( srcnode ) <EOL> last_slash = dstnode . rindex ( '<STR_LIT:/>' ) <EOL> if last_slash == len ( dstnode ) - <NUM_LIT:1> : <EOL> dstgroup = dstnode [ : - <NUM_LIT:1> ] <EOL> elif last_slash > <NUM_LIT:0> : <EOL> dstgroup = dstnode [ : last_slash ] <EOL> else : <EOL> dstgroup = "<STR_LIT:/>" <EOL> dstleaf = dstnode [ last_slash + <NUM_LIT:1> : ] <EOL> if dstleaf == "<STR_LIT>" : <EOL> dstleaf = srcnode . name <EOL> if os . path . isfile ( dstfile ) and not overwritefile : <EOL> dstfileh = open_file ( dstfile , '<STR_LIT:a>' , pytables_sys_attrs = createsysattrs ) <EOL> try : <EOL> dstgroup = dstfileh . get_node ( dstgroup ) <EOL> except : <EOL> dstgroup = newdst_group ( dstfileh , dstgroup , title , filters ) <EOL> else : <EOL> if not isinstance ( dstgroup , Group ) : <EOL> if overwrtnodes : <EOL> parent = dstgroup . _v_parent <EOL> last_slash = dstgroup . _v_pathname . rindex ( '<STR_LIT:/>' ) <EOL> dstgroupname = dstgroup . _v_pathname [ last_slash + <NUM_LIT:1> : ] <EOL> dstgroup . remove ( ) <EOL> dstgroup = dstfileh . create_group ( parent , dstgroupname , <EOL> title = title , <EOL> filters = filters ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> dstfileh = open_file ( dstfile , '<STR_LIT:w>' , title = title , filters = filters , <EOL> pytables_sys_attrs = createsysattrs ) <EOL> dstgroup = newdst_group ( dstfileh , dstgroup , title = "<STR_LIT>" , filters = filters ) <EOL> try : <EOL> dstnode = srcnode . copy ( <EOL> dstgroup , dstleaf , filters = filters , <EOL> copyuserattrs = copyuserattrs , overwrite = overwrtnodes , <EOL> stats = stats , start = start , stop = stop , step = step , <EOL> chunkshape = chunkshape , <EOL> sortby = sortby , check_CSI = check_CSI , propindexes = propindexes ) <EOL> except : <EOL> ( type_ , value , traceback ) = sys . exc_info ( ) <EOL> print ( "<STR_LIT>" % <EOL> ( srcfile , srcnode , dstfile , dstnode ) ) <EOL> print ( "<STR_LIT>" % ( type_ , value ) ) <EOL> print ( "<STR_LIT>" , dstfileh ) <EOL> srcfileh . close ( ) <EOL> dstfileh . close ( ) <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if upgradeflavors : <EOL> if srcfileh . format_version . startswith ( "<STR_LIT:1>" ) : <EOL> dstnode . del_attr ( '<STR_LIT>' ) <EOL> elif srcfileh . format_version < "<STR_LIT>" : <EOL> if dstnode . get_attr ( '<STR_LIT>' ) in numpy_aliases : <EOL> dstnode . set_attr ( '<STR_LIT>' , internal_flavor ) <EOL> if srcnode . _c_classid == "<STR_LIT>" : <EOL> recreate_indexes ( srcnode , dstfileh , dstnode ) <EOL> srcfileh . close ( ) <EOL> dstfileh . close ( ) <EOL> def copy_children ( srcfile , dstfile , srcgroup , dstgroup , title , <EOL> recursive , filters , copyuserattrs , overwritefile , <EOL> overwrtnodes , stats , start , stop , step , <EOL> chunkshape , sortby , check_CSI , propindexes , <EOL> upgradeflavors , use_hardlinks = True ) : <EOL> """<STR_LIT>""" <EOL> srcfileh = open_file ( srcfile , '<STR_LIT:r>' , root_uep = srcgroup ) <EOL> srcgroup = srcfileh . root <EOL> created_dstgroup = False <EOL> if os . path . isfile ( dstfile ) and not overwritefile : <EOL> dstfileh = open_file ( dstfile , '<STR_LIT:a>' , pytables_sys_attrs = createsysattrs ) <EOL> try : <EOL> dstgroup = dstfileh . get_node ( dstgroup ) <EOL> except NoSuchNodeError : <EOL> dstgroup = newdst_group ( dstfileh , dstgroup , title , filters ) <EOL> created_dstgroup = True <EOL> else : <EOL> if not isinstance ( dstgroup , Group ) : <EOL> if overwrtnodes : <EOL> parent = dstgroup . _v_parent <EOL> last_slash = dstgroup . _v_pathname . rindex ( '<STR_LIT:/>' ) <EOL> dstgroupname = dstgroup . _v_pathname [ last_slash + <NUM_LIT:1> : ] <EOL> dstgroup . remove ( ) <EOL> dstgroup = dstfileh . create_group ( parent , dstgroupname , <EOL> title = title , <EOL> filters = filters ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> dstfileh = open_file ( dstfile , '<STR_LIT:w>' , title = title , filters = filters , <EOL> pytables_sys_attrs = createsysattrs ) <EOL> dstgroup = newdst_group ( dstfileh , dstgroup , title = "<STR_LIT>" , filters = filters ) <EOL> created_dstgroup = True <EOL> if created_dstgroup and copyuserattrs : <EOL> srcgroup . _v_attrs . _f_copy ( dstgroup ) <EOL> try : <EOL> srcgroup . _f_copy_children ( <EOL> dstgroup , recursive = recursive , filters = filters , <EOL> copyuserattrs = copyuserattrs , overwrite = overwrtnodes , <EOL> stats = stats , start = start , stop = stop , step = step , <EOL> chunkshape = chunkshape , <EOL> sortby = sortby , check_CSI = check_CSI , propindexes = propindexes , <EOL> use_hardlinks = use_hardlinks ) <EOL> except : <EOL> ( type_ , value , traceback ) = sys . exc_info ( ) <EOL> print ( "<STR_LIT>" % <EOL> ( srcfile , srcgroup , dstfile , dstgroup ) ) <EOL> print ( "<STR_LIT>" % ( type_ , value ) ) <EOL> print ( "<STR_LIT>" , dstfileh ) <EOL> srcfileh . close ( ) <EOL> dstfileh . close ( ) <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if upgradeflavors : <EOL> for dstnode in dstgroup . _f_walknodes ( "<STR_LIT>" ) : <EOL> if srcfileh . format_version . startswith ( "<STR_LIT:1>" ) : <EOL> dstnode . del_attr ( '<STR_LIT>' ) <EOL> elif srcfileh . format_version < "<STR_LIT>" : <EOL> if dstnode . get_attr ( '<STR_LIT>' ) in numpy_aliases : <EOL> dstnode . set_attr ( '<STR_LIT>' , internal_flavor ) <EOL> for table in srcgroup . _f_walknodes ( "<STR_LIT>" ) : <EOL> dsttable = dstfileh . get_node ( dstgroup , table . _v_pathname ) <EOL> recreate_indexes ( table , dstfileh , dsttable ) <EOL> srcfileh . close ( ) <EOL> dstfileh . close ( ) <EOL> def _get_parser ( ) : <EOL> parser = argparse . ArgumentParser ( <EOL> description = '''<STR_LIT>''' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT>' , default = True , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , dest = '<STR_LIT:title>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT>' , default = True , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT>' , default = True , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , type = int , default = <NUM_LIT:0> , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , choices = ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) , default = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , type = int , choices = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , type = int , choices = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , type = int , choices = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT>' , default = True , <EOL> dest = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '''<STR_LIT>''' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT:src>' , metavar = '<STR_LIT>' , help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , help = '<STR_LIT>' , <EOL> ) <EOL> return parser <EOL> def main ( ) : <EOL> global verbose <EOL> global regoldindexes <EOL> global createsysattrs <EOL> parser = _get_parser ( ) <EOL> args = parser . parse_args ( ) <EOL> if args . rng : <EOL> try : <EOL> args . rng = eval ( "<STR_LIT>" + args . rng + "<STR_LIT:)>" ) <EOL> except Exception : <EOL> parser . error ( "<STR_LIT>" ) <EOL> if args . chunkshape . isdigit ( ) or args . chunkshape . startswith ( '<STR_LIT:(>' ) : <EOL> args . chunkshape = eval ( args . chunkshape ) <EOL> if args . complevel < <NUM_LIT:0> or args . complevel > <NUM_LIT:9> : <EOL> parser . error ( <EOL> '<STR_LIT>' <EOL> ) <EOL> src = args . src . split ( '<STR_LIT::>' ) <EOL> dst = args . dst . split ( '<STR_LIT::>' ) <EOL> if len ( src ) == <NUM_LIT:1> : <EOL> srcfile , srcnode = src [ <NUM_LIT:0> ] , "<STR_LIT:/>" <EOL> else : <EOL> srcfile , srcnode = src <EOL> if len ( dst ) == <NUM_LIT:1> : <EOL> dstfile , dstnode = dst [ <NUM_LIT:0> ] , "<STR_LIT:/>" <EOL> else : <EOL> dstfile , dstnode = dst <EOL> if srcnode == "<STR_LIT>" : <EOL> srcnode = "<STR_LIT:/>" <EOL> if dstnode == "<STR_LIT>" : <EOL> dstnode = "<STR_LIT:/>" <EOL> warnings . filterwarnings ( "<STR_LIT:ignore>" , category = OldIndexWarning ) <EOL> if args . upgradeflavors : <EOL> warnings . filterwarnings ( "<STR_LIT:ignore>" , category = FlavorWarning ) <EOL> filter_params = ( <EOL> args . complevel , <EOL> args . complib , <EOL> args . shuffle , <EOL> args . bitshuffle , <EOL> args . fletcher32 , <EOL> ) <EOL> if ( filter_params == ( None , ) * <NUM_LIT:4> or args . keepfilters ) : <EOL> filters = None <EOL> else : <EOL> if args . complevel is None : <EOL> args . complevel = <NUM_LIT:0> <EOL> if args . shuffle is None : <EOL> if args . complevel > <NUM_LIT:0> : <EOL> args . shuffle = True <EOL> else : <EOL> args . shuffle = False <EOL> if args . bitshuffle is None : <EOL> args . bitshuffle = False <EOL> if args . bitshuffle : <EOL> args . shuffle = False <EOL> if args . complib is None : <EOL> args . complib = "<STR_LIT>" <EOL> if args . fletcher32 is None : <EOL> args . fletcher32 = False <EOL> filters = Filters ( complevel = args . complevel , complib = args . complib , <EOL> shuffle = args . shuffle , bitshuffle = args . bitshuffle , <EOL> fletcher32 = args . fletcher32 ) <EOL> start , stop , step = None , None , <NUM_LIT:1> <EOL> if args . rng : <EOL> start , stop , step = args . rng . start , args . rng . stop , args . rng . step <EOL> verbose = args . verbose <EOL> regoldindexes = args . regoldindexes <EOL> createsysattrs = args . createsysattrs <EOL> t1 = time . time ( ) <EOL> cpu1 = time . clock ( ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" * <NUM_LIT:20> ) <EOL> print ( "<STR_LIT>" , args . recursive ) <EOL> print ( "<STR_LIT>" , filters ) <EOL> if args . sortby is not None : <EOL> print ( "<STR_LIT>" , args . sortby ) <EOL> print ( "<STR_LIT>" , args . checkCSI ) <EOL> if args . propindexes : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % ( srcfile , srcnode , <EOL> dstfile , dstnode ) ) <EOL> print ( "<STR_LIT>" * <NUM_LIT:20> ) <EOL> h5srcfile = open_file ( srcfile , '<STR_LIT:r>' ) <EOL> srcnodeobject = h5srcfile . get_node ( srcnode ) <EOL> h5srcfile . close ( ) <EOL> stats = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> if isinstance ( srcnodeobject , Group ) : <EOL> copy_children ( <EOL> srcfile , dstfile , srcnode , dstnode , <EOL> title = args . title , recursive = args . recursive , filters = filters , <EOL> copyuserattrs = args . copyuserattrs , overwritefile = args . overwritefile , <EOL> overwrtnodes = args . overwrtnodes , stats = stats , <EOL> start = start , stop = stop , step = step , chunkshape = args . chunkshape , <EOL> sortby = args . sortby , check_CSI = args . checkCSI , <EOL> propindexes = args . propindexes , <EOL> upgradeflavors = args . upgradeflavors , <EOL> use_hardlinks = True ) <EOL> else : <EOL> copy_leaf ( <EOL> srcfile , dstfile , srcnode , dstnode , <EOL> title = args . title , filters = filters , <EOL> copyuserattrs = args . copyuserattrs , <EOL> overwritefile = args . overwritefile , overwrtnodes = args . overwrtnodes , <EOL> stats = stats , start = start , stop = stop , step = step , <EOL> chunkshape = args . chunkshape , <EOL> sortby = args . sortby , check_CSI = args . checkCSI , <EOL> propindexes = args . propindexes , <EOL> upgradeflavors = args . upgradeflavors ) <EOL> t2 = time . time ( ) <EOL> cpu2 = time . clock ( ) <EOL> tcopy = round ( t2 - t1 , <NUM_LIT:3> ) <EOL> cpucopy = round ( cpu2 - cpu1 , <NUM_LIT:3> ) <EOL> tpercent = int ( round ( cpucopy / tcopy , <NUM_LIT:2> ) * <NUM_LIT:100> ) <EOL> if verbose : <EOL> ngroups = stats [ '<STR_LIT>' ] <EOL> nleaves = stats [ '<STR_LIT>' ] <EOL> nlinks = stats [ '<STR_LIT>' ] <EOL> nhardlinks = stats [ '<STR_LIT>' ] <EOL> nbytescopied = stats [ '<STR_LIT>' ] <EOL> nnodes = ngroups + nleaves + nlinks + nhardlinks <EOL> print ( <EOL> "<STR_LIT>" , ngroups , <EOL> "<STR_LIT>" , nleaves , <EOL> "<STR_LIT>" , nlinks , <EOL> "<STR_LIT>" , nhardlinks , <EOL> ) <EOL> if args . copyuserattrs : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" , round ( nbytescopied / <NUM_LIT> , <NUM_LIT:3> ) ) <EOL> print ( "<STR_LIT>" % ( <EOL> tcopy , cpucopy , tpercent ) ) <EOL> print ( "<STR_LIT>" , round ( ( nnodes ) / float ( tcopy ) , <NUM_LIT:1> ) ) <EOL> print ( "<STR_LIT>" , int ( nbytescopied / ( tcopy * <NUM_LIT> ) ) ) </s>
