
    ꢩedY                         d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z
 ddlZdadadag dZd	 Zd
 Zd Z	 ddZd Zd ZdS )znThis utility lets you repack your data files in a flexible way.

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

    N)Path)perf_counter)process_timeFT)numericNumericnumarrayNumArray	CharArrayc                     | j         }|                    d          D ]V}|dk    r		 |                     ||          }n3# t          j        j        $ r |                     ||||          }Y nw xY w|}W|S )N/ titlefilters)rootsplitget_nodetb
exceptionsNoSuchNodeErrorcreate_group)dstfilehdstgroupr   r   groupnodenamegroup2s          7lib/python3.11/site-packages/tables/scripts/ptrepack.pynewdst_groupr      s    MENN3''  r>>	<&&uh77FF}, 	< 	< 	<**5(163: + < <FFF	<
 Ls   >-A.-A.c                 n   | j         }|g k    rt          s)t          r t          d|j        d|j        d           d S t          r t          d|j        d|j        d           |D ]M}t          rt          d|z             |j                            |          }|                    d            Ld S d S )Nz([I]Not regenerating indexes for table: ':'z$[I]Regenerating indexes for table: 'z([I]Indexing column: '%s'. Please wait...)r   )	_listoldindexesregoldindexesverboseprintfilename_v_pathnamecols_f_colcreate_index)tabler   dsttablelistoldindexescolnamecolobjs         r   recreate_indexesr0   1   s   *N 	 A((((*>*>*>@ A A AF 	=E$$$h&:&:&:< = = =% 	. 	.G L@7JKKK]))'22F---- 	. 	.    c                    t          j        | d|          }|                    |          }|                    d          }|t	          |          dz
  k    r|d d         }n|dk    r|d |         }nd}||dz   d          }|dk    r|j        }t          |                                          r|st          j        |dt          |	          }	 |                    |          }t          |t           j
        j                  sr|ra|j        }|j                            d          }|j        |dz   d          }|                                 |                    ||||
          }ndt!          d          nT# t"          $ r t%          ||||          }Y n6w xY wt          j        |d||t          |          }t%          ||d|
          }	 |                    ||||||	|
||||||          }n# t"          $ r t)          j                    \  }}}t-          d| d|d|d|d	           t-          d| d|            t-          d|           |                                 |                                 t!          d          w xY w|r||j                            d          r|                    d           nL|j        dk     rA|                    d          t8          v r%|                    dt           j        j                   |j         dk    rtC          |||           |                                 |                                 d S )Nrallow_paddingr      r   r   apytables_sys_attrsr5   r   yPlease check that the node names are not duplicated in destination, and if so, add the --overwrite-nodes flag if desired.wr   r   r:   r5   )r   copyuserattrs	overwritestatsstartstopstep
chunkshapesortby	check_CSIpropindexesProblems doing the copy from 'r    ' to 'r!   The error was --> : !The destination file looks like:
1FLAVOR2.1TABLE)"r   	open_filer   rindexlennamer   is_filecreatesysattrs
isinstancer   Group	_v_parentr'   remover   RuntimeError	Exceptionr   copysysexc_infor%   closeformat_version
startswithdel_attrget_attrnumpy_aliasesset_attrflavorinternal_flavor
_c_classidr0   )srcfiledstfilesrcnodedstnoder   r   r>   overwritefileoverwrtnodesr@   rA   rB   rC   rD   rE   rF   rG   upgradeflavorsr5   srcfileh
last_slashr   dstleafr   parentdstgroupnametype_value	tracebacks                                r   	copy_leafry   E   s   
 |GSFFFH((G $$JS\\!^## 3B3<	a;J;'j1noo&G"}},G}} O} O<3A.;= = =	;((22H h77 ; ;%/F!)!5!<!<S!A!AJ#+#7
Q#HLOO%%%'44V\;@=D  5  F  FHH ' (: ; ; ;;  	H 	H 	H#HhwGGHHH	H, <E73A.;= = =  ("gNNNE,,gw'<u4d!YK  I I  E E E$'LNN!yww'''3 	4 	4 	43533E334442H=== D E E 	EE  F"--c22 	FX&&&&$u,,))]::  29+DEEE W$$(G444 NNNNs   E8 8FF"G0 0BJ
c                    t          j        | d||          }|j        }d}t          |                                          r|st          j        |dt
          |          }	 |                    |          }t          |t           j        j	                  sr|	ra|j
        }|j                            d          }|j        |dz   d         }|                                 |                    ||||	          }nrt          d
          nb# t           j        j        $ r t%          ||||          }d}Y n8w xY wt          j        |d||t
          |          }t%          ||d|	          }d}|r|r|j                            |           	 |                    |||||	|
||||||||           n# t,          $ r t/          j                    \  }}}t3          d| d|d|d|d	           t3          d| d|            t3          d|           |                                 |                                 t          d          w xY w|r|                    d          D ]~}|j                            d          r|                    d           2|j        dk     rA|                    d          t@          v r%|!                    dt           j"        j#                   |                    d          D ].}|                    ||j                  } tI          |||            /|                                 |                                 dS )z8Copy the children from source group to destination groupr3   )root_uepr5   Fr8   r9   r   r6   Nr   r;   Tr<   r=   r   )	recursiver   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   use_hardlinksrH   r    rI   r!   rJ   rK   rL   zPlease 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.LeafrM   rN   rO   Table)%r   rQ   r   r   rU   rV   r   rW   r   rX   rY   r'   rR   rZ   r   r[   r   r   r   _v_attrs_f_copy_f_copy_childrenr\   r^   r_   r%   r`   _f_walknodesra   rb   rc   rd   re   rf   rg   rh   r0   )!rj   rk   srcgroupr   r   r|   r   r>   rn   ro   r@   rA   rB   rC   rD   rE   rF   rG   rp   r5   r}   rq   created_dstgroupr   rt   rr   ru   rv   rw   rx   rm   r+   r,   s!                                    r   copy_childrenr      s    |GS8*79 9 9H }HG}} ! } ! <3A.;= = =	;((22H h77 ; ;%/F!)!5!<!<S!A!AJ#+#7
Q#HLOO%%%'44V\;@=D  5  F  FHH ' (: ; ; ;; }, 	$ 	$ 	$#HhwGGH#	$. <E73A.;= = =  ("gNNN  ,M ,!!(++++!!	7'<u4d!YK' 	" 	) 	) 	) 	)  + + +$'LNN!yww'''8885 	6 	6 	63533E334442H=== * + + 	++   J,,V44 	J 	JG&11#66 J  ****(500##H-->>$$Xry/HIII &&w// 4 4$$Xu/@AA(3333 NNNNs   #D
 
(D54D5#F/ /BI	c                     t          j        d          } |                     dddd           |                     dd	dd
d           |                     ddddd           |                     ddddd           |                     dddd           |                     ddddd            |                     d!ddd"d#           |                     d$dd%d&           |                     d't          d(d)*           |                     d+d,d-d./           |                     d0t          d1d23           |                     d4t          d1d53           |                     d6t          d1d73           |                     d8dd9d:           |                     d;d<d=>           |                     d?dd@dA           |                     dBdddCdD           |                     dEdFdGH           |                     dIddJ           |                     dKddL           |                     dMddNdO           |                     dPdQdRH           |                     dSdTdUH           | S )VNa  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.)descriptionz-vz	--verbose
store_truezshow verbose information)actionhelpz-oz--overwritern   zoverwrite destination file)r   destr   z-Rz--rangerngRANGEzselect 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.)r   metavarr   z--non-recursivestore_falseTr|   z/do not do a recursive copy. Default is to do it)r   defaultr   r   z--dest-titler   r   z?title for the new file (if not specified, the source is copied))r   r   r   z--dont-create-sysattrsrV   z-do not create sys attrs (default is to do it)z--dont-copy-userattrsr>   z0do not copy the user attrs (default is to do it)z--overwrite-nodesro   zSoverwrite destination nodes if they exist.
        Default is to not overwrite themz--complevelr   zLset a compression level (0 for no compression, which is the
        default))typer   r   z	--complib)zliblzobzip2blosczblosc:blosclzz	blosc:lz4zblosc:lz4hcz
blosc:zlibz
blosc:zstdblosc2zblosc2:blosclzz
blosc2:lz4zblosc2:lz4hczblosc2:zlibzblosc2:zstdr   zWset the compression library to be used during the copy.
        Defaults to %(default)s)choicesr   r   z	--shuffle)r   r6   zOactivate or not the shuffle filter (default is active if
        complevel > 0))r   r   r   z--bitshufflez=activate or not the bitshuffle filter (not active by default)z--fletcher32zPwhether to activate or not the fletcher32 filter (not active
        by default)z--keep-source-filterskeepfilterszuse the original filters in source files.
        The default is not doing that if any of --complevel, --complib,
        --shuffle --bitshuffle or --fletcher32 option is specifiedz--chunkshapekeepzset 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 value)r   r   z--upgrade-flavorsrp   zwhen 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)z--dont-regenerate-old-indexesr#   zddisable regenerating old indexes.
        The default is to regenerate old indexes as they are foundz--sortbyCOLUMNzdo 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 objects)r   r   z
--checkCSIz7force the check for a CSI index for the --sortby columnz--propindexeszpropagate the indexes existing in original tables. The default
        is to not propagate them.  Only applies to table objectsz--dont-allow-paddingdont_allow_paddingzremove the possible padding in compound types in source files.
        The default is to propagate it.  Only applies to table objectssrczsourcefile:sourcegroupzsource file/groupdstzdestfile:destgroupzdestination file/group)argparseArgumentParseradd_argumentint)parsers    r   _get_parserr     s   $
  F k,'     mL)     ieW     ->    
 WbN      <    
 t?    
 L~,    
 C    
  
 #  
 
 
 #v    
 S&L     S&    
 =F     G     L7GH     'tF     HC     \F     D    
 |!J     /6I     +2J     Mr1   c                     t                      } |                                 }|j        rF	 t          d|j        z   dz             |_        n%# t          $ r |                     d           Y nw xY w|j                                        s|j                            d          rt          |j                  |_        |j	        dk     s|j	        dk    r|                     d           |j
                            dd	          }|j                            dd	          }t          |          d	k    r|d         d
}}n|\  }}t          |          d	k    r|d         d
}}n|\  }}|dk    rd
}|dk    rd
}t          j        dt           j        j                   |j        r%t          j        dt           j        j                   |j	        |j        |j        |j        |j        f}|dk    s|j        rd }	n|j	        d|_	        |j        |j	        dk    rd|_        nd|_        |j        d|_        |j        rd|_        |j        d|_        |j        d|_        t           j                            |j	        |j        |j        |j        |j                  }	d\  }
}}|j        r$|j        j        |j        j        |j        j        }}}
|j        a|j         a |j!        a!tE                      }tG                      }t>          rtI          d           tI          d|j%                   tI          d|	           |j&        *tI          d|j&                   tI          d|j'                   |j(        rtI          d           tI          d| d| d| d|            tI          d           |j)         }t!          j*        |d|          }|+                    |          }|,                                 dddddd}t[          |t           j.        j/                  rtta          ||||fi d|j1        d |j%        d!|	d"|j2        d#|j3        d$|j4        d%|d&|
d'|d(|d)|j        d*|j&        d+|j'        d,|j(        d-|j        d.|d/d nKtk          ||||f|j1        |	|j2        |j3        |j4        ||
|||j        |j&        |j'        |j(        |j        |d0 tE                      }tG                      }||z
  }||z
  }t>          r|d1         }|d2         }|d3         }|d4         }|d5         }||z   |z   |z   }tI          d6|d7|d8|d9|           |j2        rtI          d:           ntI          d;           tI          d<|d=z  d>           tI          d?|d>d@|d>dA||z  dB           tI          dC||z  dD           tI          dE||z  d=z  dF           d S d S )GNzslice()z'Error when getting the range parameter.(r   	   z9invalid "complevel" value, it sould be in te range [0, 9]r    r6   r   r   ignore)category)NNNNTFr   )	complevelcomplibshuffle
bitshuffle
fletcher32)NNr6   z<+=++=++=++=++=++=++=++=++=++=++=++=++=++=++=++=++=++=++=++=+zRecursive copy:zApplying filters:zSorting table(s) by column:zForcing a CSI creation:z%Recreating indexes in copied table(s)zStart copying z to r3   r4   )groupsleaveslinksbytes	hardlinksr   r|   r   r>   rn   ro   r@   rA   rB   rC   rD   rE   rF   rG   rp   r5   r}   )r   r   r>   rn   ro   r@   rA   rB   rC   rD   rE   rF   rG   rp   r5   r   r   r   r   r   zGroups copied:z, Leaves copied:z, Links copied:z, Hard links copied:zUser attrs copiedzUser attrs not copiedzKBytes copied: i   z.3fzTime copying: z
 s (real) z
 s (cpu)  z.0%zCopied nodes/sec: z.1fzCopied KB/s : z.0f)6r   
parse_argsr   evalr\   errorrD   isdigitrb   r   r   rsplitr   rS   warningsfilterwarningsr   r   OldIndexWarningrp   FlavorWarningr   r   r   r   r   leafFiltersrA   rB   rC   r$   r#   rV   clockcpuclockr%   r|   rE   checkCSIrG   r   rQ   r   r`   rW   r   rX   r   r   r>   rn   ro   ry   )r   argsr   r   rj   rl   rk   rm   filter_paramsr   rA   rB   rC   t1cpu1r5   	h5srcfilesrcnodeobjectr@   t2cpu2tcopycpucopyngroupsnleavesnlinks
nhardlinksnbytescopiednnodess                                r   mainr     s6   
 ]]FD x D	DHtx/#566DHH 	D 	D 	DLLBCCCCC	D    0DO$>$>s$C$C 0t//~T^a//G	
 	
 	

 (//#q
!
!C
(//#q
!
!C
3xx1}}q63
3xx1}}q63"}}"}} Hr}/LMMMM  P2=3NOOOO 	M 	$$(8$>!DN<~!!#$?"#DO? 	! DL<!DL?"#DO'//DN*.,-1_-1_ " > > &E4x I HNDHM48=Tt lG&M(N 
B::D 
j000!7+++;"/===+T];;; 	;9:::IwIIIIgIIIIJJJj//MWcGGGI&&w//M OOAAANNE-00 
Wgw
	  
	  
	 **
	 (,
	 @G
	  ,,
	  =A<N<N
	  **	
	  38%	
	 
 %
	 
 #d
	 
 *.
	 
 ;?//
	  ;;
	  +/--
	  ((
	   ..
	  (-
	  $
	  
	  
	  	Wgw	
*g,,4;Lu4d;$-(.'	
 	
 	
 	
 
B::DGETkG B//w;'
W~7"V+j8gv"J		
 	
 	
  	+%&&&&)***9t 3999:::,UB , ,'B , ,o+, ,	- 	- 	- 	76E>777888@|e3d:@@@AAAAA/B Bs   A A-,A-)T)__doc__r   r^   r   pathlibr   timer   r   r   r   tablesr   r$   r#   rV   re   r   r0   ry   r   r   r    r1   r   <module>r      s     



        & & & & & & ) ) ) ) ) )         $. . .(\ \ \F @D	^ ^ ^ ^BH H HVmB mB mB mB mBr1   