σ
jϊ\c           @@ 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 d e d  d d d d d d d d d d  Z d   Z e d  Z d   Z d   Z d S(   sx   This utility lets you look into the data and metadata of your data files.

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

i    (   t   print_function(   t   absolute_importN(   t	   open_file(   t   Group(   t   Leaf(   t   Tablet   Column(   t   UnImplemented(   t   ranget   rngt	   showattrst   verboset   dumpt   colinfot   idxinfoc         C@ s&  t  j r t t |    n t t |    t  j rO t d t |  j   n  t  j r\t |  t	  r\t d  t  j
 j d  k r d } n t  j
 j } t  j
 j d  k rΝ |  j d k rΩ |  j d } qΩ n t  j
 j } t  j
 j d  k rτ d } n t  j
 j } |  j d k r$t d |  d	  q\x5 t | | |  D] } t d | |  | f  q7Wn  t |  t  r§t  j r§x0 |  j D]" } t t |  j j |    q~Wn  t |  t  r"t  j r"x` |  j D]R } |  j j |  } t | t  rΙ| j d  k	 rΙ| j } t t |   qΙqΙWn  d  S(
   Ns     s     Data dump:i    i   s   [SCALAR] %ss   [%s] %s(    (    (    (   t   optionsR   t   printt   reprt   strR
   t   attrsR   t
   isinstanceR   R	   t   startt   Nonet   stopt   shapet   stepR   R   R   t   colnamest   colst   _f_colR   R   t   index(   t   leafR   R   R   t   it   colnamet   colt   idx(    (    s4   lib/python2.7/site-packages/tables/scripts/ptdump.pyt	   dump_leaf,   s<    		
		#	c         C@ sβ   |  j  j d } |  j   } | r@ t | d t j d  } n  x | D] } t t |   t j	 r t d t
 | j   n  xW | D]O } xF | j |  D]5 } t j s΅ t j rΒ t |  q t t |   q Wq WqG Wd  S(   Ni   t   keyt   _v_pathnames     (   t   _v_filet   _node_kindst   _f_walk_groupst   sortedt   operatort
   attrgetterR   R   R   R
   R   t   _v_attrst   _f_list_nodesR   R   R#   (   t   pgroupt   sortt
   node_kindst   whatt   groupt   kindt   node(    (    s4   lib/python2.7/site-packages/tables/scripts/ptdump.pyt
   dump_groupZ   s    	c       	   C@ sω   t  j d d  }  |  j d d d d d d |  j d	 d
 d d d d |  j d d d d d d |  j d d d d d d |  j d d d d d d |  j d d d d d d |  j d d d d d d d d |  j d d d  d d! |  S("   Nt   descriptionsο   The 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*).s   -vs	   --verboset   actiont
   store_truet   helps"   dump more metainformation on nodess   -ds   --dumps   dump data information on leavess   -as   --showattrss?   show attributes in nodes (only useful when -v or -d are active)s   -ss   --sorts   sort output by node names   -cs	   --colinfosM   show info of columns in tables (only useful when -v or -d
        are active)s   -is	   --idxinfosK   show info of indexed columns (only useful when -v or -d are
        active)s   -Rs   --ranget   destR	   t   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.t   srcs   filename[:nodepath]s   name of the HDF5 file to dump(   t   argparset   ArgumentParsert   add_argument(   t   parser(    (    s4   lib/python2.7/site-packages/tables/scripts/ptdump.pyt   _get_parserm   s4    		c          C@ sv  t    }  |  j d t  } t | j t j  r{ y t d | j d  t _ Wn t k
 rn |  j	 d  q{ Xd | _
 n  | j j d d  } t |  d k rΆ | d d } } n! | \ } } | d	 k rΧ d } n  y t | d
  } Wn t k
 r
} d t |  SX| _ | j |  } t | t  rCt | | j  n) t | t  r_t |  n t d |  Wd  QXd  S(   Nt	   namespaces   slice(t   )s'   Error when getting the range parameter.i   t   :i    t   /t    t   rs   Cannot open input file: s   Unrecognized object:(   RB   t
   parse_argsR   R   R	   t   sixt   string_typest   evalt	   Exceptiont   errorR   R=   t   rsplitt   lenR   R   t   get_nodeR   R5   R/   R   R#   R   (   RA   t   argsR=   t   filenamet   nodenamet   h5filet   et
   nodeobject(    (    s4   lib/python2.7/site-packages/tables/scripts/ptdump.pyt   main   s2    		(   t   __doc__t
   __future__R    R   R>   R*   t   tables.fileR   t   tables.groupR   t   tables.leafR   t   tables.tableR   R   t   tables.unimplementedR   RJ   t	   six.movesR   t	   Namespacet   sliceR   R   R#   t   FalseR5   RB   RX   (    (    (    s4   lib/python2.7/site-packages/tables/scripts/ptdump.pyt   <module>   s,   			.	.