ó
	+]Yc           @   s\   d  Z  d Z d Z d d l Z d d l Z d d l Z d d l Z d e f d „  ƒ  YZ d S(   s   Git version generator
s(   Duncan Macleod <duncan.macleod@ligo.org>s"   Adam Mercer <adam.mercer@ligo.org>iÿÿÿÿNt	   GitStatusc           B   sh   e  Z d  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 d
 „ Z RS(   s'   Git repository version information
    c         C   sR   |  j  ƒ  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  S(   N(
   t	   _find_gitt   _bint   Nonet   idt   datet   brancht   tagt   authort	   committert   status(   t   self(    (    s$   /home/pi/Code/cbp_2/utils/version.pyt   __init__"   s    						c          C   s›   xˆ t  j d j t  j ƒ D]m }  t j d k rG t  j j |  d ƒ } n t  j j |  d ƒ } t  j j | ƒ r t  j	 | t  j
 ƒ r | Sq Wt d ƒ ‚ d S(   sG   Determine the full path of the git binary on this
        host
        t   PATHt   win32s   git.exet   gits!   Git binary not found on this hostN(   t   ost   environt   splitt   pathsept   syst   platformt   patht   joint   isfilet   accesst   X_OKt
   ValueError(   R   t   gitbin(    (    s$   /home/pi/Code/cbp_2/utils/version.pyR   /   s     'c      
   G   s’   |  j  g t | ƒ } t j | d t j d t j d t | t ƒ ƒ} | j ƒ  \ } } | j d k rˆ t j	 | j d j
 | ƒ ƒ ‚ n  | j ƒ  S(   s=   Executable a command with arguments in a sub-process
        t   stdoutt   stderrt   shelli    t    (   R   t   listt
   subprocesst   Popent   PIPEt
   isinstancet
   basestringt   communicatet
   returncodet   CalledProcessErrorR   t   strip(   R   t   argst   cmdargst   pt   outt   err(    (    s$   /home/pi/Code/cbp_2/utils/version.pyR   =   s    		c         C   s«   |  j  d d d ƒ j d ƒ \ } } } } } } | |  _ | |  _ | } | } | }	 | }
 t j d t j t |  j ƒ ƒ ƒ |  _ d | | f |  _	 d |	 |
 f |  _
 d S(   s5   Determine basic info about the latest commit
        t   logs   -1s&   --pretty=format:%H,%ct,%an,%ae,%cn,%cet   ,s   %Y-%m-%d %H:%M:%S +0000s   %s <%s>N(   R   R   R   t   udatet   timet   strftimet   gmtimet   floatR   R   R	   (   R   t   at   bt   ct   dt   et   fR   t   author_emailR	   t   committer_email(    (    s$   /home/pi/Code/cbp_2/utils/version.pyt   get_commit_infoN   s    *			c         C   sI   |  j  d d d ƒ } | d k r- d  |  _ n t j j | ƒ |  _ |  j S(   Ns	   rev-parses   --symbolic-full-namet   HEAD(   R   R   R   R   R   t   basename(   R   R   (    (    s$   /home/pi/Code/cbp_2/utils/version.pyt
   get_branch^   s
    c         C   s‚   y |  j  d d ƒ } Wn t j k
 r5 d |  _ nF Xy |  j  d d d d ƒ } Wn t j k
 rq d |  _ n
 Xd |  _ |  j S(   s6   Determine modification status of working tree
        s
   diff-filess   --quiets   UNCLEAN: Modified working trees
   diff-indexs   --cacheR@   s"   CLEAN: All modifications committed(   R   R"   R)   t   _statusR
   (   R   R
   (    (    s$   /home/pi/Code/cbp_2/utils/version.pyt
   get_statusf   s    	c         C   s_   |  j  s |  j ƒ  n  y" |  j d d d |  j  ƒ |  _ Wn t j k
 rW d |  _ n X|  j S(   s*   Determine name of the current tag
        t   describes   --exact-matchs   --tagsN(   R   R?   R   R   R"   R)   R   (   R   (    (    s$   /home/pi/Code/cbp_2/utils/version.pyt   get_tagw   s    	c         C   s‘   | j  d ƒ | j  d |  j |  j f ƒ x` d d d d d d g D]F } t |  | ƒ } | rx | j  d	 | | f ƒ qC | j  d
 | ƒ qC Wd S(   sZ   Write the contents of this `GitStatus` to a version.py format
        file object
        sa   # -*- coding: utf-8 -*-
# Copyright (C) Duncan Macleod (2013)

"""Versioning record for CIS
"""

s\   __author__ = 'Duncan Macleod <duncan.macleod@ligo.org>'
__version__ = '%s'
__date__ = '%s'

R   R   R   R   R	   R
   s   git_%s = '%s'
s   git_%s = None
N(   t   writet   versionR   t   getattr(   R   t   fobjt   attrt   val(    (    s$   /home/pi/Code/cbp_2/utils/version.pyRG   †   s    	s
   version.pyc         C   sˆ   |  j  ƒ  |  j ƒ  |  j ƒ  |  j ƒ  |  j p7 |  j |  _ t | d ƒ  } |  j | ƒ Wd QXt | d ƒ  } | j	 ƒ  SWd QXd S(   s:  Process the version information into a new file

        Parameters
        ----------
        outputfile : `str`
            path to output python file in which to write version info

        Returns
        -------
        info : `str`
            returns a string dump of the contents of the outputfile
        t   wNt   r(
   R?   RB   RF   RD   R   R   RH   t   openRG   t   read(   R   t
   outputfileRJ   (    (    s$   /home/pi/Code/cbp_2/utils/version.pyt   __call__œ   s    



(   t   __name__t
   __module__t   __doc__R   t   staticmethodR   R   R?   RB   RD   RF   RG   RR   (    (    (    s$   /home/pi/Code/cbp_2/utils/version.pyR       s   							(	   RU   t
   __author__t   __credits__R   R"   R3   R   t   objectR    (    (    (    s$   /home/pi/Code/cbp_2/utils/version.pyt   <module>   s   