B
    d                 @   s|   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	Z	d dl
Zd dlZdd Zdd Zdd Zd	d
 Zdd ZdS )    N)save_fig_with_metadatahtml_escapec              C   s  g } dd }i }d|d< yTt j|d< t j|d< t j|d< t j|d< t j|d	< t j|d
< t j|d< t j|d< W n  t	k
r   ||t d Y nX | 
| i }y\d|d< tj|d< tj|d< tj|d< tj|d< tj|d	< tj|d
< tj|d< tj|d< W n" t	k
r   ||td Y nX | 
| i }d|d< y\ddl}|j|d< |j|d< |j|d< |j|d< |j|d	< |j|d
< |j|d< |j|d< W n6 t	k
r   |||d Y n tk
r   Y nX | 
| i }d|d< tjj |d< tjj!|d< tjj"|d< tjj#|d< tjj$|d	< tjj%|d< tjj&|d
< tjj'|d< tjj(|d< | 
| i }d|d< t)j"j"|d< t)j"j*|d< t)j"j+pd|d< t)j"j,|d< t)j"j-|d	< t)j"j.|d< t)j"j/|d
< t)j"j0|d< t)j"j1|d< | 
| | S )zThis will return a list of dictionaries containing versioning
    information about the various LIGO libraries that PyCBC will use in an
    analysis run.c             S   sb   t ||d }|j| d< |j| d< |j| d< |j| d< |j| d< |j| d< |j| d< |j| d	< d S )
NZVCSInfoIDStatusVersionTagAuthorBranch	CommitterDate)	getattrZvcsIdZ	vcsStatusversionZvcsTagZ	vcsAuthorZ	vcsBranchZvcsCommitterZvcsDate)Zinfo_dctZcurr_moduleZ	extra_strZ
vcs_object r   e/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/pycbc/results/versioning.pyadd_info_new_version"   s    






z6get_library_version_info.<locals>.add_info_new_versionZLALNamer   r   r   r   r   r	   r
   r    ZLALFrameFrameZLALSimulationr   NZ
SimulationzLSCSoft-GlueZBuilderZPyCBC)2lalZVCSIdZ	VCSStatusZ
VCSVersionZVCSTagZ	VCSAuthorZ	VCSBranchZVCSCommitterZVCSDateAttributeErrorappendlalframeZ
FrameVCSIdZFrameVCSStatusZFrameVCSVersionZFrameVCSTagZFrameVCSAuthorZFrameVCSBranchZFrameVCSCommitterZFrameVCSDatelalsimulationZSimulationVCSIdZSimulationVCSStatusZSimulationVCSVersionZSimulationVCSTagZSimulationVCSAuthorZSimulationVCSBranchZSimulationVCSCommitterZSimulationVCSDateImportErrorglueZgit_versionidstatusr   tagauthorbuilderbranchZ	committerdatepycbcZ
git_statusreleaseZgit_tagZ
git_authorZgit_builderZ
git_branchZgit_committerZgit_build_date)library_listr   ZlalinfoZlalframeinfoZlalsimulationinfor   ZglueinfoZ	pycbcinfor   r   r   get_library_version_info   s    

























r%   c             C   sx   t  }xl|D ]d}|d }d}x$| D ]\}}|d||f 7 }q&W dd| d}tt|tj| d| f| qW d S )Nr   r   z<li> %s : %s </li>
render_textz%s Version Information)zrender-functiontitlez%s_version_information.html)r%   itemsr   r   ospathjoin)r*   r$   Zcurr_libZlib_nametextkeyvaluekwdsr   r   r   write_library_informationy   s    
r0   c          	   C   s   i }x|  dD ]\}}tj|}tj|j\}}d}|jdkrRd| ||< q|jdkrjd}|||< qytj	|jdgtj
d}W n< tjk
r   d	}||j}Y n tk
r   d
}Y nX |||< qW |S )a   Will extract the version information from the executables listed in
    the executable section of the supplied ConfigParser object.

    Returns
    --------
    dict
        A dictionary keyed by the executable name with values giving the
        version string for each executable.
    ZexecutablesN)ZgsiftphttphttpszUsing bundle downloaded from %ssingularityzmExecutable run from a singularity image. See config file and site catalog for details of what image was used.z	--version)stderrz Executable fails on {} --versionz#Executable doesn't seem to exist(!))r(   urllibparseurlparser)   r*   splitscheme
subprocesscheck_outputSTDOUTCalledProcessErrorformatOSError)cpcode_version_dict_r.   exe_nameversion_stringtxtr   r   r   get_code_version_numbers   s*    




rF   c          	   C   s   t |}d}xR| D ]F\}}y| }W n tk
r>   Y nX |d|t|ddf 7 }qW ddd}tt|tj	
| df| d S )	Nr   z1<li><b>%s</b>:<br><pre>%s</pre></li><hr><br><br>
@z&#64;r&   z$Version Information from Executables)zrender-functionr'   z)version_information_from_executables.html)rF   r(   decoder   strreplacer   r   r)   r*   r+   )r*   r@   rA   Z	html_textr-   r.   r/   r   r   r   write_code_versions   s    rK   c             C   s@   t d tj| s t|  t|  t| | t d d S )NzEntering versioning modulezLeaving versioning module)logginginfor)   r*   existsmkdirr0   rK   )r*   r@   r   r   r   create_versioning_page   s    


rP   )rL   r)   r:   urllib.parser5   Zpycbc.resultsr   r   r   r   Zpycbc.versionr"   Zglue.git_versionr   r%   r0   rF   rK   rP   r   r   r   r   <module>   s   ]%