
3Rc           @   sZ   d  Z  d d l Z d d l Z d d l Z d e f d     YZ d e f d     YZ d S(   s   Interface to uscaniNt
   UscanErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyR       s   t   Uscanc           B   s_   e  Z d  Z d d  Z e d    Z e d    Z d   Z d   Z d   Z	 d d	  Z
 RS(
   s   /usr/bin/uscant   .c         C   s+   t  |  _ d  |  _ t j j |  |  _ d  S(   N(   t   Falset	   _uptodatet   Nonet   _tarballt   ost   patht   abspatht   _dir(   t   selft   dir(    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   __init__   s    		c         C   s   |  j  S(   N(   R   (   R   (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   uptodate    s    c         C   s   |  j  S(   N(   R   (   R   (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   tarball$   s    c         C   s  d } t |  _ x| j d  D] } t j d |  } | rT d | j d  } Pq | j d  r t j d |  } | r d | j d  } Pn  t j d |  } | r d | j d  } Pq q q Wi  } y x` | j d  D]O } xF d D]> } t j d | | f |  } | r | j d  | | <q q Wq Wt j	 j
 | d
  d | d <d | } t j	 j |  sd | d
 j d d  d } t j	 j |  st d |   qn  Wn* t k
 r} t d | j d   n X| |  _ d S(   s  
        Parse the uscan output return and update the object's properties

        @param out: uscan output
        @type out: string

        >>> u = Uscan('http://example.com/')
        >>> u._parse('<target>virt-viewer_0.4.0.orig.tar.gz</target>')
        >>> u.tarball
        '../virt-viewer_0.4.0.orig.tar.gz'
        >>> u.uptodate
        False
        >>> u._parse('')
        Traceback (most recent call last):
        ...
        UscanError: Couldn't find 'upstream-url' in uscan output
        s   
s   <target>(.*)</target>s   ../%si   s
   <messages>s   .*symlinked ([^\s]+) to its/   Successfully downloaded updated package ([^<]+)t   packages   upstream-versions   upstream-urls   <%s>(.*)</%s>t   exts3   ../%(package)s_%(upstream-version)s.orig.tar%(ext)st   /s   Couldn't find tarball at '%s's"   Couldn't find '%s' in uscan outputi    N(   s   packages   upstream-versions   upstream-url(   R   R   R   t   splitt   ret   matcht   groupt
   startswithR	   R
   t   splitextt   existst   rsplitR    t   KeyErrort   argsR   (   R   t   outt   sourcet   rowt   mt   dt   nt   e(    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   _parse(   sL    			 
c         C   s%   d | k r t  |  _ n	 t |  _ d S(   s  
        Check if the uscan reports that we're up to date.

        @param out: uscan output
        @type out: string

        >>> u = Uscan('http://example.com/')
        >>> u._parse_uptodate('<status>up to date</status>')
        >>> u.tarball
        >>> u.uptodate
        True
        >>> u._parse_uptodate('')
        >>> u.tarball
        >>> u.uptodate
        False
        s   <status>up to date</status>N(   t   TrueR   R   (   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   _parse_uptodatej   s    c         C   su   d } xM d D]E } t j d | | f | t j  } | r d | j d  } Pq q W| se d } n  t |   d S(	   s  
        Parse the uscan output for errors and warnings and raise
        a L{UscanError} exception based on this. If no error detail
        is found a generic error message is used.

        @param out: uscan output
        @type out: string
        @raises UscanError: exception raised

        >>> u = Uscan('http://example.com/')
        >>> u._raise_error("<warnings>uscan warning: "
        ... "In watchfile debian/watch, reading webpage\n"
        ... "http://a.b/ failed: 500 Cant connect "
        ... "to example.com:80 (Bad hostname)</warnings>")
        Traceback (most recent call last):
        ...
        UscanError: Uscan failed: uscan warning: In watchfile debian/watch, reading webpage
        http://a.b/ failed: 500 Cant connect to example.com:80 (Bad hostname)
        >>> u._raise_error("<errors>uscan: Can't use --verbose if "
        ... "you're using --dehs!</errors>")
        Traceback (most recent call last):
        ...
        UscanError: Uscan failed: uscan: Can't use --verbose if you're using --dehs!
        >>> u = u._raise_error('')
        Traceback (most recent call last):
        ...
        UscanError: Uscan failed - debug by running 'uscan --verbose'
        t   errorst   warningss   <%s>(.*)</%s>s   Uscan failed: %si   s1   Uscan failed - debug by running 'uscan --verbose'N(   s   errorss   warnings(   R   R   t   searcht   DOTALLR   R    (   R   R   t   msgR$   R"   (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   _raise_error   s    "	s   ..c         C   s   t  j d d d | d g d |  j d t  j } | j   d } |  j |  |  j s | j rp |  j |  q |  j	 |  n  d S(	   s,   Invoke uscan to fetch a new upstream versiont   uscans	   --symlinks   --destdir=%ss   --dehst   cwdt   stdouti    N(
   t
   subprocesst   PopenR   t   PIPEt   communicateR(   R   t
   returncodeR.   R&   (   R   t   destdirt   pR   (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   scan   s    				(   R   R   t   cmdR   t   propertyR   R   R&   R(   R.   R9   (    (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyR      s   	B		*(   t   __doc__R	   R   R2   t	   ExceptionR    t   objectR   (    (    (    s1   /usr/lib/python2.7/dist-packages/gbp/deb/uscan.pyt   <module>   s   $