B
    q\V                 @   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 }yhtj| f|}|j r| d nD|jr| d n2|jr|jn|j}||j|j|jrdnd	|j	d
 W n0 tk
r } ztt| W d	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_idZ	delimiterc                s&   i | ]\}}| kr|d k	r||qS )N ).0kv)read_kwargsr   >lib/python3.7/site-packages/astropy/table/scripts/showtable.py
<dictcomp>J   s    zshowtable.<locals>.<dictcomp>Z
attributesstatsFN)	max_lines	max_widthZ	show_unit
show_dtype)infor   warningswarnr   anyr   r   Z	hide_unitr   varsitemsr   readZmoreZpprintIOErrorr   errorstr)filenameargskwargstableZ	formatterer   )r
   r   	showtable5   s*    

r    c       
      C   sV  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	 || } x2t| j	D ]$\}}	|d(krBt
  t|	|  q*W 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
        )Z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-dtypez&include a header row for column dtypesz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_argumentZ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[   sN    








r2   )N)__doc__r'   r)   r   Zastropyr   Zastropy.tabler   Zastropy.utils.exceptionsr   r    r2   r   r   r   r   <module>+   s   &