ó
jˆú\c           @@ sZ  d  Z  d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 y d d l m
 Z Wn! e k
 r™ d d l m Z n Xd d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z m Z m Z e a e a e a d d d d d g Z d „  Z  d „  Z! d „  Z" e d „ Z# d „  Z$ d „  Z% d S(   sn   This utility lets you repack your data files in a flexible way.

Pass the flag -h to this for help on usage.

i    (   t   print_function(   t   absolute_importN(   t   process_time(   t   clock(   t	   open_file(   t   Group(   t   Filters(   t   internal_flavor(   t   OldIndexWarningt   NoSuchNodeErrort   FlavorWarningt   numerict   Numerict   numarrayt   NumArrayt	   CharArrayc         C@ s‡   |  j  } xw | j d ƒ D]f } | d k r1 q n  y |  j | | ƒ } Wn/ t k
 rx |  j | | d | d | ƒ} n X| } q W| S(   Nt   /t    t   titlet   filters(   t   roott   splitt   get_nodeR	   t   create_group(   t   dstfileht   dstgroupR   R   t   groupt   nodenamet   group2(    (    s6   lib/python2.7/site-packages/tables/scripts/ptrepack.pyt   newdst_group3   s    	
c         C@ s¶   |  j  } | g  k r² t sB t r> t d | j | j f ƒ n  d  St re t d | j | j f ƒ n  xJ | D]? } t r‰ t d | ƒ n  | j j | ƒ } | j d d  ƒ ql Wn  d  S(   Ns.   [I]Not regenerating indexes for table: '%s:%s's*   [I]Regenerating indexes for table: '%s:%s's(   [I]Indexing column: '%s'. Please wait...R   (
   t   _listoldindexest   regoldindexest   verboset   printt   filenamet   _v_pathnamet   colst   _f_colt   create_indext   None(   t   tableR   t   dsttablet   listoldindexest   colnamet   colobj(    (    s6   lib/python2.7/site-packages/tables/scripts/ptrepack.pyt   recreate_indexesE   s    	c         C@ s2  t  |  d d | ƒ} | j | ƒ } | j d ƒ } | t | ƒ d k rV | d  } n | d k ro | |  } n d } | | d } | d k r› | j } n  t j j | ƒ r| rt  | d d	 t d | ƒ} y | j | ƒ } Wn t	 | | | | ƒ } qÁXt
 | t ƒ sÁ| rm| j } | j j d ƒ } | j | d } | j ƒ  | j | | d
 | d | ƒ} q|t d ƒ ‚ qÁnB t  | d d
 | d | d	 t d | ƒ} t	 | | d
 d d | ƒ} yX | j | | d | d | d | d |	 d |
 d | d | d | d | d | d | ƒ} Wnw t j ƒ  \ } } } t d |  | | | f ƒ t d | | f ƒ t d | ƒ | j ƒ  | j ƒ  t d ƒ ‚ n X| rø| j j d ƒ r»| j d ƒ qø| j d k  rø| j d ƒ t k rõ| j d t ƒ qõqøn  | j d k rt | | | ƒ n  | j ƒ  | j ƒ  d  S(   Nt   rt   allow_paddingR   i   iÿÿÿÿi    R   t   at   pytables_sys_attrsR   R   sy   Please check that the node names are not duplicated in destination, and if so, add the --overwrite-nodes flag if desired.t   wt   copyuserattrst	   overwritet   statst   startt   stopt   stept
   chunkshapet   sortbyt	   check_CSIt   propindexess/   Problems doing the copy from '%s:%s' to '%s:%s's   The error was --> %s: %ss!   The destination file looks like:
t   1t   FLAVORs   2.1t   TABLE(   R   R   t   rindext   lent   namet   ost   patht   isfilet   createsysattrsR   t
   isinstanceR   t	   _v_parentR#   t   removeR   t   RuntimeErrort   copyt   syst   exc_infoR!   t   closet   format_versiont
   startswitht   del_attrt   get_attrt   numpy_aliasest   set_attrR   t
   _c_classidR-   (   t   srcfilet   dstfilet   srcnodet   dstnodeR   R   R3   t   overwritefilet   overwrtnodesR5   R6   R7   R8   R9   R:   R;   R<   t   upgradeflavorsR/   t   srcfileht
   last_slashR   t   dstleafR   t   parentt   dstgroupnamet   type_t   valuet	   traceback(    (    s6   lib/python2.7/site-packages/tables/scripts/ptrepack.pyt	   copy_leafY   sp    	



c   !      C@ s4  t  |  d d | d | ƒ} | j } t } t j j | ƒ r| rt  | d d t d | ƒ} y | j | ƒ } Wn, t k
 rŸ t	 | | | | ƒ } t
 } qfXt | t ƒ sf|	 r| j } | j j d ƒ } | j | d } | j ƒ  | j | | d | d	 | ƒ} qt d
 ƒ ‚ qfnH t  | d d | d	 | d t d | ƒ} t	 | | d d d	 | ƒ} t
 } | r…| r…| j j | ƒ n  y_ | j | d | d	 | d | d |	 d |
 d | d | d | d | d | d | d | d | ƒWnw t j ƒ  \ } } } t d |  | | | f ƒ t d | | f ƒ t d | ƒ | j ƒ  | j ƒ  t d ƒ ‚ n X| rÝxv | j d ƒ D]b } | j j d ƒ rœ| j d ƒ qt| j d  k  rt| j d ƒ t k rÖ| j  d t! ƒ qÖqtqtWn  x< | j d! ƒ D]+ } | j | | j ƒ }  t" | | |  ƒ qíW| j ƒ  | j ƒ  d" S(#   s8   Copy the children from source group to destination groupR.   t   root_uepR/   R0   R1   R   i   R   R   sy   Please check that the node names are not duplicated in destination, and if so, add the --overwrite-nodes flag if desired.R2   R   t	   recursiveR3   R4   R5   R6   R7   R8   R9   R:   R;   R<   t   use_hardlinkss/   Problems doing the copy from '%s:%s' to '%s:%s's   The error was --> %s: %ss!   The destination file looks like:
s¸   Please check that the node names are not duplicated in destination, and if so, add the --overwrite-nodes flag if desired. In particular, pay attention that root_uep is not fooling you.t   LeafR=   R>   s   2.1t   TableN(#   R   R   t   FalseRC   RD   RE   RF   R   R	   R   t   TrueRG   R   RH   R#   R@   RI   R   RJ   t   _v_attrst   _f_copyt   _f_copy_childrenRL   RM   R!   RN   t   _f_walknodesRO   RP   RQ   RR   RS   RT   R   R-   (!   RV   RW   t   srcgroupR   R   Rg   R   R3   RZ   R[   R5   R6   R7   R8   R9   R:   R;   R<   R\   R/   Rh   R]   t   created_dstgroupR   R`   R^   Ra   Rb   Rc   Rd   RY   R(   R)   (    (    s6   lib/python2.7/site-packages/tables/scripts/ptrepack.pyt   copy_childrenµ   sn    	
	



c          C@ sÖ  t  j d d ƒ }  |  j d d d d d d ƒ|  j d	 d
 d d d d d d ƒ|  j d d d d d d d d ƒ|  j d d d d t d d d d ƒ|  j d d d d d d d ƒ|  j d d d d t d d d d ƒ|  j d  d d d t d d! d d" ƒ|  j d# d d d d$ d d% ƒ|  j d& d' t d d( d d) ƒ|  j d* d+ dZ d d, d d6 ƒ|  j d7 d' t d+ d[ d d9 ƒ|  j d: d' t d+ d\ d d; ƒ|  j d< d' t d+ d] d d= ƒ|  j d> d d d d? d d@ ƒ|  j dA d dB d dC ƒ|  j dD d d d dE d dF ƒ|  j dG d d d t d dH d dI ƒ|  j dJ d dK d dL ƒ|  j dM d d d dN ƒ|  j dO d d d dP ƒ|  j dQ d d d dR d dS ƒ|  j dT d dU d dV ƒ|  j dW d dX d dY ƒ|  S(^   Nt   descriptionsÙ  This utility is very powerful and lets you copy any
        leaf, group or complete subtree into another file.
        During the copy process you are allowed to change the filter
        properties if you want so. Also, in the case of duplicated pathnames,
        you can decide if you want to overwrite already existing nodes on the
        destination file. Generally speaking, ptrepack can be useful in may
        situations, like replicating a subtree in another file, change the
        filters in objects and see how affect this to the compression degree
        or I/O performance, consolidating specific data in repositories or
        even *importing* generic HDF5 files and create true PyTables
        counterparts.s   -vs	   --verboset   actiont
   store_truet   helps   show verbose informations   -os   --overwritet   destRZ   s   overwrite destination files   -Rs   --ranget   rngt   metavart   RANGEs¹   select a RANGE of rows (in the form "start,stop,step")
        during the copy of *all* the leaves.
        Default values are "None,None,1", which means a copy of all the
        rows.s   --non-recursivet   store_falset   defaultRg   s/   do not do a recursive copy. Default is to do its   --dest-titleR   R   s?   title for the new file (if not specified, the source is copied)s   --dont-create-sysattrsRF   s-   do not create sys attrs (default is to do it)s   --dont-copy-userattrsR3   s0   do not copy the user attrs (default is to do it)s   --overwrite-nodesR[   sS   overwrite destination nodes if they exist.
        Default is to not overwrite thems   --complevelt   typei    sL   set a compression level (0 for no compression, which is the
        default)s	   --complibt   choicest   zlibt   lzot   bzip2t   bloscs   blosc:blosclzs	   blosc:lz4s   blosc:lz4hcs   blosc:snappys
   blosc:zlibs
   blosc:zstdsW   set the compression library to be used during the copy.
        Defaults to %(default)ss	   --shufflei   sO   activate or not the shuffle filter (default is active if
        complevel > 0)s   --bitshuffles=   activate or not the bitshuffle filter (not active by default)s   --fletcher32sP   whether to activate or not the fletcher32 filter (not active
        by default)s   --keep-source-filterst   keepfilterss´   use the original filters in source files.
        The default is not doing that if any of --complevel, --complib,
        --shuffle --bitshuffle or --fletcher32 option is specifieds   --chunkshapet   keepsà   set a chunkshape.
        Possible options are: "keep" | "auto" | int | tuple.
        A value of "auto" computes a sensible value for the chunkshape of the
        leaves copied.  The default is to "keep" the original values   --upgrade-flavorsR\   sÏ   when repacking PyTables 1.x or PyTables 2.x files, the flavor
        of leaves will be unset. With this, such a leaves will be serialized
        as objects with the internal flavor ('numpy' for 3.x series)s   --dont-regenerate-old-indexesR   sd   disable regenerating old indexes.
        The default is to regenerate old indexes as they are founds   --sortbyt   COLUMNs¼   do a table copy sorted by the index in "column".
        For reversing the order, use a negative value in the "step" part of
        "RANGE" (see "-r" flag).  Only applies to table objectss
   --checkCSIs7   force the check for a CSI index for the --sortby columns   --propindexess   propagate the indexes existing in original tables. The default
        is to not propagate them.  Only applies to table objectss   --dont-allow-paddingt   dont_allow_paddings…   remove the possible padding in compound types in source files.
        The default is to propagate it.  Only applies to table objectst   srcs   sourcefile:sourcegroups   source file/groupt   dsts   destfile:destgroups   destination file/group(
   R€   R   R‚   Rƒ   s   blosc:blosclzs	   blosc:lz4s   blosc:lz4hcs   blosc:snappys
   blosc:zlibs
   blosc:zstd(   i    i   (   i    i   (   i    i   (   t   argparset   ArgumentParsert   add_argumentRl   t   int(   t   parser(    (    s6   lib/python2.7/site-packages/tables/scripts/ptrepack.pyt   _get_parser  sœ    		  c       '   C@ sö  t  ƒ  }  |  j ƒ  } | j r` y t d | j d ƒ | _ Wq` t k
 r\ |  j d ƒ q` Xn  | j j ƒ  s | j j d ƒ r– t | j ƒ | _ n  | j	 d k  s´ | j	 d k rÄ |  j d ƒ n  | j
 j d d	 ƒ } | j j d d	 ƒ } t | ƒ d	 k r| d d
 } } n | \ } } t | ƒ d	 k rF| d d
 } } n | \ } } | d k rgd
 } n  | d k r|d
 } n  t j d d t ƒ| j r®t j d d t ƒn  | j	 | j | j | j | j f } | dE k sç| j rðd  }	 ní | j	 d  k rd | _	 n  | j d  k rA| j	 d k r5t | _ qAt | _ n  | j d  k r\t | _ n  | j rqt | _ n  | j d  k rŒd | _ n  | j d  k r§t | _ n  t d | j	 d | j d | j d | j d | j ƒ }	 dF \ }
 } } | j r| j j | j j | j j }
 } } n  | j a | j  a  | j! a! t" j" ƒ  } t# ƒ  } t ròt$ d d ƒ t$ d | j% ƒ t$ d |	 ƒ | j& d  k	 r±t$ d | j& ƒ t$ d | j' ƒ n  | j( rÇt$ d ƒ n  t$ d | | | | f ƒ t$ d d ƒ n  | j) } t* | d d | ƒ} | j+ | ƒ } | j, ƒ  i d d 6d d  6d d! 6d d" 6d d# 6} t- | t. ƒ rüt/ | | | | d$ | j0 d% | j% d& |	 d' | j1 d( | j2 d) | j3 d* | d+ |
 d, | d- | d. | j d/ | j& d0 | j' d1 | j( d2 | j d | d3 t ƒnˆ t4 | | | | d$ | j0 d& |	 d' | j1 d( | j2 d) | j3 d* | d+ |
 d, | d- | d. | j d/ | j& d0 | j' d1 | j( d2 | j d | ƒt" j" ƒ  } t# ƒ  } t5 | | d4 ƒ } t5 | | d4 ƒ } y! t6 t5 | | d5 ƒ d6 ƒ } Wn t7 k
 rùd7 } n Xt rò| d } | d  } | d! } | d# } | d" } | | | | } t$ d8 | d9 | d: | d; | ƒ | j1 ryt$ d< ƒ n
 t$ d= ƒ t$ d> t5 | d? d4 ƒ ƒ t$ d@ | | | f ƒ t$ dA t5 | t8 | ƒ d	 ƒ ƒ t$ dB t6 | | dC ƒ ƒ n  d  S(G   Ns   slice(t   )s'   Error when getting the range parameter.t   (i    i	   s9   invalid "complevel" value, it sould be in te range [0, 9]t   :i   R   R   t   ignoret   categoryi   R€   t	   complevelt   complibt   shufflet
   bitshufflet
   fletcher32s   +=+i   s   Recursive copy:s   Applying filters:s   Sorting table(s) by column:s   Forcing a CSI creation:s%   Recreating indexes in copied table(s)s   Start copying %s:%s to %s:%sR.   R/   t   groupst   leavest   linkst   bytest	   hardlinksR   Rg   R   R3   RZ   R[   R5   R6   R7   R8   R9   R:   R;   R<   R\   Rh   i   i   id   t   NaNs   Groups copied:s   , Leaves copied:s   , Links copied:s   , Hard links copied:s   User attrs copieds   User attrs not copieds   KBytes copied:g      @s*   Time copying: %s s (real) %s s (cpu)  %s%%s   Copied nodes/sec: s   Copied KB/s :i   (   N(   NNNN(   NNi   (9   R   t
   parse_argsRy   t   evalt	   Exceptiont   errorR9   t   isdigitRP   R•   Rˆ   t   rsplitR‰   RA   t   warningst   filterwarningsR   R\   R
   R–   R—   R˜   R™   R'   R„   Rl   Rk   R   R6   R7   R8   R    R   RF   t   timet   cputimeR!   Rg   R:   t   checkCSIR<   R‡   R   R   RN   RG   R   Rs   R   R3   RZ   R[   Re   t   roundR   t   ZeroDivisionErrort   float(   RŽ   t   argsRˆ   R‰   RV   RX   RW   RY   t   filter_paramsR   R6   R7   R8   t   t1t   cpu1R/   t	   h5srcfilet   srcnodeobjectR5   t   t2t   cpu2t   tcopyt   cpucopyt   tpercentt   ngroupst   nleavest   nlinkst
   nhardlinkst   nbytescopiedt   nnodes(    (    s6   lib/python2.7/site-packages/tables/scripts/ptrepack.pyt   mainš  sþ    		!
						)					

)		
					!






	
 (&   t   __doc__t
   __future__R    R   RL   R¨   t   os.pathRC   RŠ   R¦   R   R©   t   ImportErrorR   t   tables.fileR   t   tables.groupR   t   tables.leafR   t   tables.flavorR   t   tables.exceptionsR   R	   R
   Rk   R    Rl   R   RF   RS   R   R-   Re   Rs   R   R¿   (    (    (    s6   lib/python2.7/site-packages/tables/scripts/ptrepack.pyt   <module>   s<   				`Y	ˆ