U
    \                     @   sD   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 )    Nc                  C   sx   t ddddgd } | dkrpt ddgdd}|D ]*}d|krB|d	d
 dd}|  S qBn| S dS )zZReturn the current branch we are on or the branch that the detached head
    is pointed togitz	rev-parsez--abbrev-refHEADutf-8branch
*/) N)
subprocesscheck_outputdecodestripsplitreplace)Zcurrent_branchZbranchesr   Zdetached_from_branch r   2/home/rger/proj/rsyslog-doc/source/conf_helpers.pyget_current_branch   s    
r   c                  C   s   dd } |  }|dd S )zDReturn the current X.Y stable version number from the latest git tagc                  S   sL   t ddddgd } tdd| d}|jd	d
 d |d }|S )z+"Helper function: Return the latest git tagr   tagz--listzv*r   z[A-Za-z]r   r   c                 S   s   dd |  dD S )Nc                 S   s   g | ]}t |qS r   )int).0ur   r   r   
<listcomp>3   s     zXget_current_stable_version.<locals>.get_latest_tag.<locals>.<lambda>.<locals>.<listcomp>.)r   )sr   r   r   <lambda>3       zDget_current_stable_version.<locals>.get_latest_tag.<locals>.<lambda>)keyr	   )r   r   r   r   resubr   sort)Zgit_tag_outputZgit_tag_listZgit_tag_latestr   r   r   get_latest_tag+   s    
z2get_current_stable_version.<locals>.get_latest_tagNr   )r"   Z
latest_tagr   r   r   get_current_stable_version(   s    r$   c                  C   s2   t  } dt| dd t| dd d }|S )zReturn the next stable versionz{}.{}N   r#   )r$   formatr   )Zcurrent_versionZnext_versionr   r   r   get_next_stable_version@   s    r'   c                  C   s   t dddddgd} | S )zReturn commit hash stringr   logz--pretty=format:%hr   z-n1r   )r   r   r   )Zcommit_hashr   r   r   get_current_commit_hashN   s    r)   c                 C   sf   | dkrXt j }|d}|dkr2dt }qb|dkrRdt t |t }qbd}n
d|}|S )zReturn a release string representing the type of build. Verbose for
    dev builds and with sparse version info for release buildsdevz%Y%m%dsimplez{}detailedz{}-{}-{}-{}z'invalid value for release_string_detail)datetimedatetodaystrftimer&   r)   r'   r   )release_typerelease_string_detailversionDATEZTODAYZrelease_stringr   r   r   get_release_stringV   s"    



r5   )r-   r   r   r   r$   r'   r)   r5   r   r   r   r   <module>   s   !