B
    i\                 @   s   d Z ddlmZ ddlm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mZmZ dd	lmZ ddlZdd
lmZ ejedddddddZdd ZdddZdd Zdd ZdS )zxThis utility lets you look into the data and metadata of your data files.

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

    )print_function)absolute_importN)	open_file)Group)Leaf)TableColumn)UnImplemented)range)rng	showattrsverbosedumpcolinfoidxinfoc             C   s  t jrtt|  ntt|  t jr8tdt| j  t jrt| t	std t j
jd krbd}nt j
j}t j
jd kr| jdkr| jd }nt j
j}t j
jd krd}nt j
j}| jdkrtd| d   n*x(t|||D ]}td|| | f  qW t| tr.t jr.x$| jD ]}tt| j| qW t| trt jrxF| jD ]<}| j|}t|trJ|jd k	rJ|j}tt| qJW d S )Nz  z  Data dump:r       z[SCALAR] %sz[%s] %s)optionsr   printreprstrr   Zattrsr   
isinstancer	   r   startstopshapestepr
   r   r   ZcolnamesZcolsZ_f_colr   r   index)Zleafr   r   r   iZcolnamecolidxr   r   4lib/python3.7/site-packages/tables/scripts/ptdump.py	dump_leaf,   s<    

r!   Fc             C   s   | j jdd  }|  }|r.t|tdd}xt|D ]l}tt| tj	r\tdt
|j  xB|D ]:}x4||D ]&}tjstjrt| qrtt| qrW qbW q4W d S )Nr   Z_v_pathname)keyz  )Z_v_fileZ_node_kindsZ_f_walk_groupssortedoperator
attrgetterr   r   r   r   r   Z_v_attrsZ_f_list_nodesr   r   r!   )ZpgroupsortZ
node_kindsZwhatgroupZkindZnoder   r   r    
dump_groupZ   s    


r(   c              C   s   t jdd} | jddddd | jdd	dd
d | jddddd | jddddd | jddddd | jddddd | jdddddd | jdddd  | S )!NzThe ptdump utility allows you look into the contents
        of your PyTables files. It lets you see not only the data but also
        the metadata (that is, the *structure* and additional information in
        the form of *attributes*).)Zdescriptionz-vz	--verbose
store_truez"dump more metainformation on nodes)actionhelpz-dz--dumpzdump data information on leavesz-az--showattrsz?show attributes in nodes (only useful when -v or -d are active)z-sz--sortzsort output by node namez-cz	--colinfozMshow info of columns in tables (only useful when -v or -d
        are active)z-iz	--idxinfozKshow info of indexed columns (only useful when -v or -d are
        active)z-Rz--ranger   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.)destmetavarr+   srczfilename[:nodepath]zname of the HDF5 file to dump)r.   r+   )argparseArgumentParseradd_argument)parserr   r   r    _get_parserm   s4    r4   c           
   C   s.  t  } | jtd}t|jtjr^ytd|j d t_W n tk
rV   | 	d Y nX d|_
|jdd}t|dkr|d d }}n|\}}|d	krd}yt|d
}W n* tk
r } zdt| S d }~X Y nX |J ||}t|tr t||j n t|trt| n
td| W d Q R X d S )N)	namespacezslice()z'Error when getting the range parameter.r   :r   / rzCannot open input file: zUnrecognized object:)r4   
parse_argsr   r   r   sixZstring_typeseval	Exceptionerrorr   r/   rsplitlenr   r   Zget_noder   r(   r&   r   r!   r   )r3   argsr/   filenamenodenameZh5fileeZ
nodeobjectr   r   r    main   s2    

rF   )F)__doc__Z
__future__r   r   r0   r$   Ztables.filer   Ztables.groupr   Ztables.leafr   Ztables.tabler   r   Ztables.unimplementedr	   r<   Z	six.movesr
   Z	Namespaceslicer   r!   r(   r4   rF   r   r   r   r    <module>   s,   .
.