B
    lc^                 @  s   U d Z ddlm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
Z
ddlZdZded< d	ed
< ddddZe  ddddZddddZddddZd ddddddZd!ddddZdS )"z9Module providing access to all known dataset definitions.    )annotationsN)Path)Any   zdict[str, Any]
definitionzset[str]fileinfo_dirtyNone)returnc              C  s   i a t atdd } tdd }x| dD ]}| }|j}t	|t |< t
 }|| | t | d< ||j }| st| q2t	| }|d t | d kr|d tkr|t | d< q2t| q2W dS )	z
    Read dataset .yml files from definitions/ and hashinfo/ directories.
    This is done once during the module import stage.
    
dials_dataZdefinitionshashinfoz*.ymlhashr   formatversionN)r   setr   importlib_resourcesfilesZglobZ
read_bytesZstemyamlZ	safe_loadhashlibZsha256updateZ	hexdigestnameexistsadd_hashinfo_formatversion)Zbase_directoryZhash_directoryZdefinition_fileZdataset_definitiondataset_nameZdhashZh_filer    r   2lib/python3.7/site-packages/dials_data/datasets.py_load_yml_definitions   s(    


r   c             C  s   t |  d tdS )zT
    Generate a dictionary for the integrity information of a specific dataset.
    r   )r   r   )r   r   )r   r   r   r   create_integrity_record7   s    
r   r   c           
   C  s  t drFy tt jd } | jddd | S  tttfk
rD   Y nX ytd} |  r\| S W n tk
rr   Y nX t dry$tt jd d } | jddd | S  tttfk
r   Y nX y"t	 d d } | jddd | S  ttfk
r   t
dY nX d	S )
aC  
    Returns an appropriate location where the downloaded regression data should
    be stored.

    In order of evaluation:
    * If the environment variable DIALS_DATA is set and exists or can be
      created then use that location
    * If a Diamond Light Source specific path exists then use that location
    * If the environment variable LIBTBX_BUILD is set and the directory
      'dials_data' exists or can be created underneath that location then
      use that.
    * Use ~/.cache/dials_data if it exists or can be created
    * Otherwise fail with a RuntimeError
    Z
DIALS_DATAT)parentsexist_okz,/dls/science/groups/scisoft/DIALS/dials_dataZLIBTBX_BUILDr
   z.cachezQCould not determine regression data location. Use environment variable DIALS_DATAN)osgetenvr   environmkdirKeyError	TypeErrorOSErroris_dirhomeRuntimeError)Z
repositoryr   r   r   repository_locationA   s6    

r)   intc             C  s*   | t krdS tdd t|  d d D S )Nr   c             s  s   | ]}|d  V  qdS )sizeNr   ).0itemr   r   r   	<genexpr>q   s    z$get_resident_size.<locals>.<genexpr>r   Zverify)r   sumr   )Zdsr   r   r   get_resident_sizen   s    r0   Bfloatstr)numsuffixr	   c             C  sZ   xHdD ]@}| dk r$| d| | S | dk r>| d| | S | d } qW | dd| S )N) kMG
   z.1fi   z.0fg      @Tr   )r4   r5   Zunitr   r   r   _human_readablet   s    
r<   Fc          	   C  s   d}xt | D ]}|r t| qt| }|tkr6d}ntt|}tdj|||d tdj|dd||dd	d
 |drtdj||d tdtj	|d ||d qW d S )Nz    zunverified datasetz1{shortname}: {dataset[name]} ({size_information}))	shortnamedatasetsize_informationz{indent}{author} ({license})authorzunknown authorlicensezunknown license)r@   indentrA   Zurlz{indent}{dataset[url]})rB   r>   z
{}
description)initial_indentsubsequent_indent)
sortedprintr   r   r<   r0   formatgettextwrapfill)Zds_listquietrB   r=   r>   r?   r   r   r   list_known_definitions~   s2    

rM   )r1   )F)__doc__Z
__future__r   r   r   rJ   Zpathlibr   typingr   r   r   r   __annotations__r   r   r)   r0   r<   rM   r   r   r   r   <module>   s$    
-
