a
    \                     @   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   st   t g dd } | dkrlt ddgdd}|D ]*}d|v r>|dd	 d
d}|  S q>n| 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-8r   r   branch
*/) N)
subprocesscheck_outputdecodestripsplitreplace)Zcurrent_branchZbranchesr   Zdetached_from_branch r   #/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   sH   t g dd } tdd| d}|jdd d |d	 }|S )
z+"Helper function: Return the latest git tag)r   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       zXget_current_stable_version.<locals>.get_latest_tag.<locals>.<lambda>.<locals>.<listcomp>.)r   )sr   r   r   <lambda>3   r   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 g dd} | S )zReturn commit hash string)r   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versionZDATEZTODAYZrelease_stringr   r   r   get_release_stringV   s"    



r4   )r-   r   r   r   r$   r'   r)   r4   r   r   r   r   <module>   s   !