U
    e»{j•  ã                   @   sV   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„ Z
d
dd	„ZdS )až  
``showtable`` is a command-line script based on ``astropy.io`` and
``astropy.table`` for printing ASCII, FITS, HDF5 or VOTable files(s) to the
standard output.

Example usage of ``showtable``:

1. FITS::

    $ showtable astropy/io/fits/tests/data/table.fits

     target V_mag
    ------- -----
    NGC1001  11.1
    NGC1002  12.3
    NGC1003  15.2

2. ASCII::

    $ showtable astropy/io/ascii/tests/t/simple_csv.csv

     a   b   c
    --- --- ---
      1   2   3
      4   5   6

3. XML::

    $ showtable astropy/io/votable/tests/data/names.xml --max-width 70

               col1             col2     col3  ... col15 col16 col17
               ---              deg      deg   ...  mag   mag   ---
    ------------------------- -------- ------- ... ----- ----- -----
    SSTGLMC G000.0000+00.1611   0.0000  0.1611 ...    --    --    AA



4. Print all the FITS tables in the current directory::

    $ showtable *.fits

é    N)Úlog)ÚTable)ÚAstropyUserWarningc              
      s  |j r|jrt dt¡ t|j|j|j|j	fƒrH|j s<|jrHt dt¡ d‰ ‡ fdd„t
|ƒ ¡ D ƒ}zptj| f|Ž}|j rˆ|  d¡ nL|jrš|  d¡ n:|jr¦|jn|j}||j|j|jrÀdnd	|j	rÌd
nd	d� W n2 tk
�r } zt t|ƒ¡ W 5 d	}~X Y nX d	S )zŒ
    Read a table and print to the standard output.

    Parameters
    ----------
    filename : str
        The path to a FITS file.

    z*--info and --stats cannot be used togetherz9print parameters are ignored if --info or --stats is used)ZhduÚformatZtable_idÚ	delimiterc                    s&   i | ]\}}|ˆ kr|d k	r||“qS )N© )Ú.0ÚkÚv©Zread_kwargsr   ú^/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/table/scripts/showtable.pyÚ
<dictcomp>M   s
        zshowtable.<locals>.<dictcomp>Ú
attributesÚstatsFNT)Ú	max_linesÚ	max_widthZ	show_unitÚ
show_dtype)Úinfor   ÚwarningsÚwarnr   Úanyr   r   Z	hide_unitr   ÚvarsÚitemsr   ÚreadÚmoreÚpprintÚOSErrorr   ÚerrorÚstr)ÚfilenameÚargsÚkwargsÚtableÚ	formatterÚer   r   r   Ú	showtable6   s8    
ÿÿþü
r%   c           
      C   sR  t jt d¡d�}|j}|dddd� |ddd	� |d
ddd� |dddd� |dddd� | d¡}|j}|dtdd� |dtdd� |dddd� |dddd� | d¡}|j}|ddd	� | d¡}|j}|d d!d	� | d"¡}|j}|d#d$d	� | d%¡}|j}|d&d'd	� | | ¡} t| j	ƒD ]$\}}	|d(k�r@t
ƒ  t|	| ƒ �q(d)S )*z3The main function called by the `showtable` script.aŸ  
            Print tables from ASCII, FITS, HDF5, VOTable file(s).  The tables
            are read with 'astropy.table.Table.read' and are printed with
            'astropy.table.Table.pprint'. The default behavior is to make the
            table output fit onto a single screen page.  For a long and wide
            table this will mean cutting out inner rows and columns.  To print
            **all** the rows or columns use ``--max-lines=-1`` or
            ``max-width=-1``, respectively. The complete list of supported
            formats can be found at
            http://astropy.readthedocs.io/en/latest/io/unified.html#built-in-table-readers-writers
        )Údescriptionr   ú+zpath to one or more files)ÚnargsÚhelpz--formatzNinput table format, should be specified if it cannot be automatically detected)r)   z--moreÚ
store_truez"use the pager mode from Table.more)Úactionr)   z--infoz(show information about the table columnsz--statsz'show statistics about the table columnszpprint argumentsz--max-lineszPmaximum number of lines in table output (default=screen length, -1 for no limit))Útyper)   z--max-widthzEmaximum width in table output (default=screen width, -1 for no limit)z--hide-unitzThide the header row for unit (which is shown only if one or more columns has a unit)z--show-dtypezfalways include a header row for column dtypes (otherwise shown only if any column is multidimensional)zASCII argumentsz--delimiterzcolumn delimiter stringzFITS argumentsz--hduzname of the HDU to showzHDF5 argumentsz--pathz%the path from which to read the tablezVOTable argumentsz
--table-idzthe table to read inr   N)ÚargparseÚArgumentParserÚtextwrapÚdedentÚadd_argumentÚadd_argument_groupÚintÚ
parse_argsÚ	enumerater   Úprintr%   )
r    ÚparserZaddargZpprint_argsZ
ascii_argsZ	fits_argsZ	hdf5_argsZvotable_argsÚidxr   r   r   r   Úmain`   sz    ÿÿý  ÿ  ÿ
üýüü






r9   )N)Ú__doc__r-   r/   r   Zastropyr   Zastropy.tabler   Zastropy.utils.exceptionsr   r%   r9   r   r   r   r   Ú<module>   s   +*