ó
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 Z d d l Z d d l	 m
 Z
 m Z d d l Z d d l m Z d „  Z d „  Z d	 d
 e e e e e e d e d „
 Z d e f d „  ƒ  YZ e d „ Z d d „ Z d S(   sj   This utility prints the contents of an HDF5 file as a tree.

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

i    (   t   absolute_import(   t   print_functionN(   t   defaultdictt   deque(   t   zipc          C@ sÅ  t  j d d ƒ }  |  j d d d t d d d d	 ƒ|  j d
 d d t d d d d ƒ|  j d d d d d d d ƒ|  j d d d d d ƒ|  j d d d d d d d ƒ|  j d d d d d ƒ|  j d d d d d d d ƒ|  j d d d d d ƒ|  j d d d d d d d ƒ|  j d  d d d d ƒ|  j d! d d d d" d d# ƒ|  j d$ d d d d" d d% ƒ|  j d& d' d( d d) ƒ|  j d d* d d+ d t d t d t d t d" t ƒ |  S(,   Nt   descriptions±  
        `pttree` is designed to give a quick overview of the contents of a
        PyTables HDF5 file by printing a depth-indented list of nodes, similar
        to the output of the Unix `tree` function.

        It can also display the size, shape and compression states of
        individual nodes, as well as summary information for the whole file.

        For a more verbose output (including metadata), see `ptdump`.
        s   -Ls   --max-levelt   typet   destt	   max_deptht   helps8   maximum branch depth of tree to display (-1 == no limit)s   -Ss	   --sort-byt   sort_bys@   artificially order nodes, can be either "size", "name" or "none"s   --print-sizet   actiont
   store_truet
   print_sizes   print size of each node/branchs   --no-print-sizet   store_falses   --print-shapet   print_shapes   print shape of each nodes   --no-print-shapes   --print-compressiont   print_compressions9   print compression library(level) for each compressed nodes   --no-print-compressions   --print-percentt   print_percents>   print size of each node as a %% of the total tree size on disks   --no-print-percents   --use-si-unitst   use_si_unitss)   report sizes in SI units (1 MB == 10^6 B)s   --use-binary-unitss.   report sizes in binary units (1 MiB == 2^20 B)t   srct   metavars   filename[:nodepath]s&   path to the root of the tree structurei   t   size(   t   argparset   ArgumentParsert   add_argumentt   intt   strt   set_defaultst   Truet   False(   t   parser(    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   _get_parser   sT    	
	c          C@ s¸   t  ƒ  }  |  j ƒ  } | j j d ƒ j d d ƒ } t | ƒ d k rY | d d } } n! | \ } } | d k rz d } n  t j | d ƒ & } t | | | j  } t	 | ƒ Wd  QXd  S(   NR   t   :i   i    t   /t    t   r(
   R   t
   parse_argst   __dict__t   popt   rsplitt   lent   tablest	   open_filet   get_tree_strt   print(   R   t   argsR   t   filenamet   nodenamet   ft   tree_str(    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   maind   s    		R!   iÿÿÿÿc   0      C@ sD  |  j  | ƒ } | j ƒ  | j } | d k  r= t j j } n  t |
 ƒ } d } d } d } t d „  ƒ } t d „  ƒ } t d „  ƒ } t d „  ƒ } t d „  ƒ } t d „  ƒ } t d „  ƒ } t | ƒ } t ƒ  } x¥| r€| j	 ƒ  } t
 | t j j ƒ r| j | ƒ qÜ n  | j } | j ƒ  \ } } | | c d	 7<| | | | <| | | <t
 | t j ƒ r"| | d	 k ryn | j } | j } | | c | 7<| | c | 7<| | c d	 7<| | 7} | | 7} | d	 7} | | | <Wqt k
 r}  t j |  j ƒ qXn  | j | ƒ qÜ t
 | t j ƒ rÜ | | d	 k rm| j t | j j ƒ  ƒ ƒ | | | <q}| j | ƒ qÜ qÜ Wi  }! | } xá| rp| j	 ƒ  } | j } | j }" |" j }# | |# c | | 7<| |# c | | 7<| |# c | | 7<| j | }$ |$ | k sE| j }% | r8|% d
 | j j  7}% n  g  }& d | | | }' | | | d	 k rŽ|% d | | | | | | | f 7}% n  t
 | t j j ƒ rº|& j d | j! ƒ n| | d	 k ræ|& j d | | | ƒ nUt
 | t j" t j# f ƒ rÉ| rRd | | | ƒ | | | ƒ f }( | rB|( d |' 7}( n  |& j |( ƒ n  | ru|& j d t$ | j% ƒ ƒ n  | r;| j& j' }) | j& j( }* |* r¬d |) |* f }+ n d }+ |& j d |+ ƒ q;nr |$ | k r;d | | }, | r|, d | | | ƒ | | | ƒ f 7}, n  | r+|, d |' 7}, n  |& j |, ƒ n  | |! k ra|! j) i t* ƒ  | 6ƒ n  |% |! | _+ |& |! | _, |	 d k r˜|' |! | _- n` |	 d k r·| j |! | _- nA | d k rÓd |! | _- n% t |" j j ƒ  ƒ j. | ƒ |! | _- | d k	 rE|# |! k r*|! j) i t* ƒ  |# 6ƒ n  |! |# j/ |! | ƒ qEn  | | k	 r|" | k r| j0 |" ƒ qqWd d d d" }- |- t1 |! | j ƒ d# 7}- | r@t2 | ƒ | }. t j3 |  j4 ƒ j5 }/ |- d d d 7}- |- d | 7}- |- d | | ƒ | | ƒ f 7}- |- d  |. 7}- |- d! | |/ ƒ 7}- |- d d d 7}- n  |- S($   sl   
    Generate the ASCII string representing the tree structure, and the summary
    info (if requested)
    i    c           S@ s   d S(   Ng        (    (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   <lambda>•   R"   c           S@ s   d S(   Ng        (    (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR3   –   R"   c           S@ s   d S(   Ni    (    (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR3   —   R"   c           S@ s   d S(   Ni    (    (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR3   ›   R"   c           S@ s   d S(   Ni    (    (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR3   œ   R"   c           S@ s   d  S(   N(   t   None(    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR3      R"   c           S@ s   d S(   NR"   (    (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR3   ž   R"   i   s    (%s)id   s   , addr=%i, ref=%i/%is   softlink --> %ss   hardlink --> %ss   mem=%s, disk=%ss
    [%4.1f%%]s   shape=%ss   %s(%i)R4   s   compression=%ss   ... %i leavess   , mem=%s, disk=%sR   t   nameR!   s   
t   -i<   i   s   Total branch leaves:    %i
s1   Total branch size:      %s in memory, %s on disk
s   Mean compression ratio: %.2f
s   HDF5 file size:         %s
s   

s   

(6   t   get_nodet   _g_check_opent   _v_deptht   ost   syst   maxintt   bytes2humanR   R   R&   t
   isinstanceR)   t   linkt   Linkt   appendt   _v_pathnamet   _get_obj_infot   Leaft   size_in_memoryt   size_on_diskt   NotImplementedErrort   warningst   warnt   messaget   Groupt   extendt   listt   _v_childrent   valuest	   _v_parentt   _v_namet	   __class__t   __name__t   targett   Arrayt   Tablet   reprt   shapet   filterst   complibt	   complevelt   updatet
   PrettyTreeR5   t   labelsR
   t   indext	   add_childt
   appendleftR   t   floatt   statR.   t   st_size(0   R0   t   whereR   t   print_classR   R   R   R   t   print_totalR
   R   t   roott   start_deptht   b2ht   total_in_memt   total_on_diskt   total_itemst   in_memt   on_diskt
   leaf_countt	   ref_countt   ref_idxt   hl_addressest
   hl_targetst   stackt   leavest   nodet   patht   addrt   rct   mt   dt   et   prettyt   parentt   parent_patht   depthR5   R^   t   pctt   sizestrt   libt   levelt   compstrt   itemstrt   out_strt	   avg_ratiot   fsize(    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR+   z   s   	
				
		


							!%R]   c           B@ sG   e  Z d  Z d d d d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s  

    A pretty ASCII representation of a recursive tree structure. Each node can
    have multiple labels, given as a list of strings.

    Example:
    --------

        A = PrettyTree('A', labels=['wow'])
        B = PrettyTree('B', labels=['such tree'])
        C = PrettyTree('C', children=[A, B])
        D = PrettyTree('D', labels=['so recursive'])
        root = PrettyTree('root', labels=['many nodes'], children=[C, D])
        print root

    Credit to Andrew Cooke's blog:
    <http://www.acooke.org/cute/ASCIIDispl0.html>

    c         C@ sR   | d  k r g  } n  | d  k r* g  } n  | |  _ | |  _ | |  _ | |  _ d  S(   N(   R4   R5   t   childrenR^   R
   (   t   selfR5   R‹   R^   R
   (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   __init__~  s    					c         C@ sM   | |  k	 s t  ‚ |  | j k s' t  ‚ | |  j k rI |  j j | ƒ n  d  S(   N(   t   AssertionErrorR‹   RA   (   RŒ   t   child(    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR`   Ž  s    c         c@ s¸   |  j  Vx |  j D] } d | Vq Wt |  j d d „  ƒ} | rM | d n d  } x^ | D]V } | | k rr d n d } x5 | j ƒ  D]' } | | V| | k r¦ d n d } q… WqZ Wd  S(   Ns      t   keyc         S@ s   |  j  S(   N(   R
   (   t   c(    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR3   ™  R"   iÿÿÿÿs   `--s   +--s   |  (   R5   R^   t   sortedR‹   R4   t
   tree_lines(   RŒ   t   labelR‹   t   lastR   t   prefixt   line(    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR“   •  s    	c         C@ s   d j  |  j ƒ  ƒ S(   Ns   
(   t   joinR“   (   RŒ   (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   __str__¡  s    c         C@ s    d |  j  j t t |  ƒ ƒ f S(   Ns
   <%s at %s>(   RR   RS   t   hext   id(   RŒ   (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   __repr__¤  s    N(	   RS   t
   __module__t   __doc__R4   R   R`   R“   R™   Rœ   (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR]   h  s   			c         @ sF   |  r d ‰  d ‰ n d ‰  d d d d d
 f ‰ ‡  ‡ f d †  } | S(   Nt   TBt   GBt   MBt   kBt   Bg   ¢”mBg    eÍÍAg    €„.Ag     @@i   t   TiBt   GiBt   MiBt   KiBi   i(   i   i   i
   c         @ sN   x= t  ˆ  ˆ ƒ D], \ } } t |  ƒ | } | d k r Pq q Wd | | f S(   Ni   s   %.1f%s(   R   Rb   (   t   nbytesR–   t   valuet   scaled(   t   prefixesRO   (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyRj   ±  s
    (   RŸ   R    R¡   R¢   R£   (   g   ¢”mBg    eÍÍAg    €„.Ag     @@i   (   R¤   R¥   R¦   R§   R£   I       i   @i   i   (    (   R   Rj   (    (   R«   RO   s4   lib/python2.7/site-packages/tables/scripts/pttree.pyR=   ¨  s    		s   /tmpc      	   C@ s1  t  j t j j |  d ƒ d ƒ } | j d d ƒ } | j | d ƒ } | j | d ƒ } t  j d d d	 d
 ƒ } xj | | f D]\ } | j | d d t j	 d d t j
 ƒd | ƒ| j | d d t j j d ƒ d | ƒq| W| j d d ƒ } | j | d d ƒ } | j | d d ƒ }	 | j | d d ƒ }
 | S(   Ns   test_pttree.hdf5t   wR!   t   group1t   group1at   group1bR[   i   RZ   t   bzip2t	   zeros128bt   obji    t   dtypeRY   t
   random128bt   group2t   softlink_g1_z128s   /group1/group1a/zeros128bt   hardlink_g1a_z128t   hardlink_g1as   /group1/group1a(   R)   R*   R:   Rx   R˜   t   create_groupt   Filterst   create_carrayt   npt   zerost   float64t   randomt   randt   create_soft_linkt   create_hard_link(   R–   R0   t   g1t   g1at   g1bRY   t   ggt   g2t   softlinkt   hardlinkt   hlgroup(    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   make_test_file½  s"    !'!		(   Rž   t
   __future__R    R   R)   t   numpyR¼   R:   R   t   collectionsR   R   RH   t	   six.movesR   R   R2   R   R   R4   R+   t   objectR]   R=   RË   (    (    (    s4   lib/python2.7/site-packages/tables/scripts/pttree.pyt   <module>   s$   	F				ë@