σ
ίΘ[c           @` sΥ   d  Z  d d l m Z m Z m Z m Z d d l m Z d d l Z d d l	 m
 Z
 d d l m Z d d	 l m Z d
 g Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d e d d  Z d S(   uy   
Validates a large collection of web-accessible VOTable files,
and generates a report as a directory tree of HTML files.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   sixN(   t   get_pkg_data_filenamei   (   t   html(   t   resultu   make_validation_reportc           C` s   t  j j t  S(   N(   t   ost   patht   dirnamet   __file__(    (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt
   get_srcdir   s    c         C` sπ   d d  l  } d d d g } t   } g  } xΏ | D]· } t d j |   } | j | d   } x~ | j   D]p }	 t j |  |	 j   }	 |	 | k rΡ t	 j
 |	 d |   }
 | |
 d <Wd  QX| j |	  n  | j |	  qn WWd  QXq1 W| S(	   Ni    u   goodu   brokenu	   incorrectu   urls/cone.{0}.dat.gzu   rbt   rootu   expected(   t   gzipt   setR   t   formatt   opent	   readlinesR   t   nextt   stripR   t   Resultt   appendt   add(   t   destdirt   sR   t   typest   seent   urlst   typet   filenamet   fdt   urlt   r(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt   get_urls   s"    	c         C` s8   |  \ } } t  j | d |  } | j   Wd  QXd  S(   NR   (   R   R   t   download_xml_content(   t   argsR    R   R!   (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt   download0   s    c         C` s8   |  \ } } t  j | d |  } | j   Wd  QXd  S(   NR   (   R   R   t   validate_vo(   R$   R    R   R!   (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyR&   6   s    c         C` sQ   |  \ } } } t  j | d | ' } | d d  k rG | j |  n  Wd  QXd  S(   NR   u   network_error(   R   R   t   Nonet   validate_with_votlint(   R$   t   path_to_stilts_jarR    R   R!   (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt   votlint_validate<   s    c         C` s;   |  \ } } t  j | d |  } t j |  Wd  QXd  S(   NR   (   R   R   R   t   write_result(   R$   R    R   R!   (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt   write_html_resultC   s    c         C` s)   |  \ } } } t  j | d | | d  S(   Nt   total(   R   t   write_index_table(   R$   t   subsetR   R-   (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt   write_subindexI   s    u$   astropy.io.votable.validator.resultsc      	   C` sd  d d l  m } m } m } | d k	 rU t j j |  sU t d j	 |    qU n  t j j
 |  } |  d k r | d d   } t | |  }  Wd QXnO | d d  x? | j |   D]. } t j | d |  }	 t |	 d	 <Wd QXqΊ Wg  |  D] } | | f ^ qσ }
 | d
 d  | j t |
 d | | d d  | j t |
 d | | d k	 r₯| d d  g  |  D] } | | | f ^ qq} | j t | d | n  | d d  | j t |
 d | | d d   } t j |  | |  } Wd QX| d d  t j | |  |  | d d  g  | D] } | | t |   f ^ q)} | j t | d | d S(   uκ  
    Validates a large collection of web-accessible VOTable files.

    Generates a report as a directory tree of HTML files.

    Parameters
    ----------
    urls : list of strings, optional
        If provided, is a list of HTTP urls to download VOTable files
        from.  If not provided, a built-in set of ~22,000 urls
        compiled by HEASARC will be used.

    destdir : path, optional
        The directory to write the report to.  By default, this is a
        directory called ``'results'`` in the current directory. If the
        directory does not exist, it will be created.

    multiprocess : bool, optional
        If `True` (default), perform validations in parallel using all
        of the cores on this machine.

    stilts : path, optional
        To perform validation with ``votlint`` from the the Java-based
        `STILTS <http://www.star.bris.ac.uk/~mbt/stilts/>`_ VOTable
        parser, in addition to `astropy.io.votable`, set this to the
        path of the ``'stilts.jar'`` file.  ``java`` on the system shell
        path will be used to run it.

    Notes
    -----
    Downloads of each given URL will be performed only once and cached
    locally in *destdir*.  To refresh the cache, remove *destdir*
    first.
    i   (   t   color_printt   ProgressBart   Spinneru   {0} does not exist.u   Loading URLsu   greenNu   Marking URLsR   u   expectedu   Downloading VO filest   multiprocessu   Validating VO filesu   Validating with votlintu   Generating HTML filesu   Grouping resultsu   Generating indexu   Generating subindices(   t   utils.consoleR1   R2   R3   R'   R   R	   t   existst
   ValueErrorR   t   abspathR"   t   iterateR   R   R   t   mapR%   R&   R*   R,   t   get_result_subsetsR   t   write_indext   lenR0   (   R   R   R4   t   stiltsR1   R2   R3   R   R    R!   R$   t   xt   votlint_argst   subsetsR/   t   subindex_args(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt   make_validation_reportN   sH    %"((   t   __doc__t
   __future__R    R   R   R   t   externR   R   t
   utils.dataR   t    R   R   t   __all__R   R"   R%   R&   R*   R,   R0   R'   t   TrueRC   (    (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/main.pyt   <module>   s    "								