
fMc           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 m	 Z	 d e
 f d     YZ d e f d     YZ d	 e f d
     YZ d   Z e d k r e   n  d S(   s;   Classes for working with locally available Debian packages.iN(   t   gettext(   t   StringIOt   NoDebArchiveExceptionc           B   s   e  Z d  Z RS(   s9   Exception which is raised if a file is no Debian archive.(   t   __name__t
   __module__t   __doc__(    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR      s   t
   DebPackagec           B   s  e  Z d  Z e d  \ Z Z Z Z d$ Z d Z	 d% d% d  Z d   Z d	   Z e d
    Z d   Z d   Z d   Z d   Z e d    Z e d    Z e d    Z e d    Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z e d    Z  e d    Z! e d    Z" e# d    Z$ e# d    Z% e e d  Z& d    Z' d!   Z( d"   Z) d% d#  Z* RS(&   s   A Debian Package (.deb file).i   s   data.tar.gzs   data.tar.bz2s   data.tar.lzmas   data.tar.xzi    c         C   sk   | d  k r t j   } n  | |  _ d  |  _ d |  _ i  |  _ g  |  _ d |  _ | rg |  j	 |  n  d  S(   Nt    (
   t   Nonet   aptt   Cachet   _cachet   _debfilet   pkgnamet	   _sectionst
   _need_pkgst   _failure_stringt   open(   t   selft   filenamet   cache(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   __init__0   s    						c         C   s   |  j  d d |  g  |  _ t   |  _ d |  _ | |  _ t j |  j  |  _ |  j j	 j
 d  } t j |  |  _ |  j d |  _ d S(   s    open given debfile i   s	   open '%s'R   t   controlt   PackageN(   t   _dbgR   t   sett   _installed_conflictsR   R   t   apt_instt   DebFileR   R   t   extractdatat   apt_pkgt
   TagSectionR   R   (   R   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   <   s    			c         C   s   |  j  | S(   N(   R   (   R   t   key(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   __getitem__H   s    c            sO   g    y  |  j  j j   f d    Wn" t k
 rJ t d |  j  g SX  S(   s$   return the list of files in the deb.c            s     j  |  j  S(   N(   t   appendt   name(   t   itemt   data(   t   files(    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   <lambda>P   s    s(   List of files for '%s' could not be read(   R   R%   t   got   SystemErrort   _R   (   R   (    (   R&   s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   filelistK   s     c   	      C   s=  |  j  d d |  x"| D]} | d } | d } | d } | |  j k r |  j j |  r |  j  d d |  x* |  j j |  D] } | j r t Sq Wq q n  |  j | j } | d	 k	 r t j	 | j
 | |  r t S| s xM |  j j | d t D]0 } | j r |  j  d d | j | f  t Sq Wq q Wt S(
   s   Return True if at least one dependency of the or-group is satisfied.

        This method gets an 'or_group' and analyzes if at least one dependency
        of this group is already satisfied.
        i   s   _checkOrGroup(): %s i    i   i   s+   _is_or_group_satisfied(): %s is virtual dept   include_nonvirtuals'   found installed '%s' that provides '%s'N(   R   R   t   is_virtual_packaget   get_providing_packagest   is_installedt   Truet	   installedR   R   t	   check_dept   versionR#   t   False(	   R   t   or_groupt   dept   depnamet   vert   opert   pkgt   instt   ppkg(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   _is_or_group_satisfiedV   s,    


	$	c         C   s  t  } d	 } x | D] } | \ } } } | |  j k r |  j j |  sO q n  |  j j |  } t |  d k ry q n  | d j } n  |  j | }	 |  j j j |	 j	  }
 |
 s q n  t
 j |
 j | |  s q n  |  j d d |  |  j j |  t SWd } xn | D]f } | | d 7} | rM| rM| d | d | d f 7} n  | | t |  d k r| d 7} qqW|  j t d  | 7_ t  S(
   s   Try to satisfy the or_group.i   i    i   s   Need to get: %sR   s    (%s %s)t   |s"   Dependency is not satisfiable: %s
N(   R4   R   R   R-   R.   t   lenR#   t	   _depcachet   get_candidate_vert   _pkgR   R2   t   ver_strR   R   R"   R0   R   R*   (   R   R5   t   or_foundt   virtual_pkgR6   R7   R8   R9   t	   providersR:   t   candt   or_str(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   _satisfy_or_group}   s:    c         C   s   |  j  d d | | | f  |  j | } | j rB | j j } n | j rZ | j j } n t St j	 | | |  r |  j
 | | |  r |  j t d  | j 7_ |  j  d d | j  t St S(   s@   Return True if a pkg conflicts with a real installed/marked pkg.i   s8   _check_single_pkg_conflict() pkg='%s' ver='%s' oper='%s's)   Conflicts with the installed package '%s's!   conflicts with installed pkg '%s'(   R   R   R/   R1   R3   t   marked_installt	   candidateR4   R   R2   t   replaces_real_pkgR   R*   R#   R0   (   R   R   R8   R9   R:   t   pkgver(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   _check_single_pkg_conflict   s    		c   	      C   s8  |  j  d d |  t } d } x| D] } | d } | d } | d } | |  j k r |  j j |  r' x |  j j |  D]s } |  j  d d | j  |  j | j k r |  j  d d  q n  |  j | j | |  r |  j	 j
 | j  q q Wq' q' n  |  j | | |  r' |  j	 j
 |  q' q' Wt |  j	  S(	   s5   Check the or-group for conflicts with installed pkgs.i   s    _check_conflicts_or_group(): %s i    i   i   s   conflicts virtual check: %ss   conflict on self, ignoringN(   R   R4   R   R   R-   R.   R#   R   RN   R   t   addt   bool(	   R   R5   RD   RE   R6   R7   R8   R9   R:   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   _check_conflicts_or_group   s*    


	c         C   s7   d } y t  j |  j |  SWn t k
 r2 g  SXd S(   s4   List of package names conflicting with this package.t	   ConflictsN(   R   t   parse_dependsR   t   KeyError(   R   R    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt	   conflicts   s
    c         C   sP   g  } xC d D]; } y! | j  t j |  j |   Wq t k
 rG q Xq W| S(   s7   List of package names on which this package depends on.t   Dependss   Pre-Depends(   RV   s   Pre-Depends(   t   extendR   RS   R   RT   (   R   t   dependsR    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyRX      s    !c         C   s7   d } y t  j |  j |  SWn t k
 r2 g  SXd S(   s<   List of virtual packages which are provided by this package.t   ProvidesN(   R   RS   R   RT   (   R   R    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   provides   s
    c         C   s7   d } y t  j |  j |  SWn t k
 r2 g  SXd S(   s4   List of packages which are replaced by this package.t   ReplacesN(   R   RS   R   RT   (   R   R    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   replaces   s
    c         C   s   |  j  d d | | | f  |  j | } | j rB | j j } n | j rZ | j j } n d } xd |  j D]Y } xP | D]H \ } } } | | k rw t	 j
 | | |  rw |  j  d d |  t Sqw Wqj Wt S(   s   Return True if a given non-virtual package is replaced.

        Return True if the deb packages replaces a real (not virtual)
        packages named (pkgname, oper, ver).
        i   s   replaces_real_pkg() %s %s %ss?   we have a replaces in our package for the conflict against '%s'N(   R   R   R/   R1   R3   RJ   RK   R   R\   R   R2   R0   R4   (   R   R   R9   R8   R:   RM   R5   R#   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyRL     s    		!c         C   s6   t  } x) |  j D] } |  j |  r t } q q W| S(   s   Check if there are conflicts with existing or selected packages.

        Check if the package conflicts with a existing or to be installed
        package. Return True if the pkg is OK.
        (   R0   RU   RQ   R4   (   R   t   resR5   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   check_conflicts  s
    c      
   C   s  t  t |  j   } t t | d  d  } |  j d } g  |  j D] } | d d ^ qE } xt |  j  D]\ } } | | d k r |  j j j	 t  |  | d  n  | j
 s qo n  | j j } x | j j D] }	 x |	 j D] }
 |
 j |  j k r t j | |
 j |
 j  s|  j d d | j  |  j t d  i | j d	 6|
 j d
 6|
 j d 6|
 j d 67_ |  j j j   t Sq q Wq Wd | j k ro xa| j d D]O} xF| D]>} | j j |  j k rct j | | j | j  rc|  j d d | j  |  j t d  i | j d	 6| j j d 6| j d 6| j d 67_ |  j j j   t Sn  | j j | k r|  j | j k r|  j d d |  |  j t d  i d j |  d 6|  j  d 6| j j d 6| j d	 67_ |  j j j   t SqWqWqo qo W|  j j j   t! S(   s    
        check if installing the package would break exsisting 
        package on the system, e.g. system has:
        smc depends on smc-data (= 1.4)
        and user tries to installs smc-data 1.6
        i2   i   t   Versioni    g      Y@i   s   would break (depends) %ss]   Breaks existing package '%(pkgname)s' dependency %(depname)s (%(deprelation)s %(depversion)s)R   R7   t   deprelationt
   depversionRR   s   would break (conflicts) %ssZ   Breaks existing package '%(pkgname)s' conflict: %(targetpkg)s (%(comptype)s %(targetver)s)t	   targetpkgt   comptypet	   targetvers{   Breaks existing package '%(pkgname)s' that conflict: '%(targetpkg)s'. But the '%(debfile)s' provides it via: '%(provides)s't   ,RZ   t   debfile("   t   floatR?   R   t   maxt   intR   RZ   t	   enumeratet   op_progresst   updateR/   RB   t   current_verR1   t   dependenciest   or_dependenciesR#   R   R   R2   t   relationR3   R   R   R*   t   doneR4   t   depends_listt
   target_pkgt	   comp_typet
   target_vert   joinR   R0   (   R   t   sizet   stepst   debvert   xRZ   t   iR:   R8   t   dep_orR6   t   conflicts_ver_listt   c_or(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   check_breaks_existing_packages,  s^    $$	





c         C   s%  |  j  d d  |  j d } |  j d } |  j  d d |  | |  j k r| ry |  j | j ry |  j | j j } n4 | r |  j | j r |  j | j j } n |  j S| d	 k	 rt j	 | |  } |  j  d d |  | d k r |  j
 S| d k  r|  j S| d k r|  j Sqn  |  j S(
   s	  Compare the package to the version available in the cache.

        Checks if the package is already installed or availabe in the cache
        and if so in what version, returns one of (VERSION_NONE,
        VERSION_OUTDATED, VERSION_SAME, VERSION_NEWER).
        i   t   compare_to_version_in_cacheR   R_   i   s
   debver: %ss"   CompareVersion(debver,instver): %si    N(   R   R   R   R1   R3   RK   t   VERSION_NONER   R   t   version_comparet   VERSION_SAMEt   VERSION_NEWERt   VERSION_OUTDATED(   R   t   use_installedR   Ry   t   cachevert   cmp(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   k  s(    c         C   s`  |  j  d d  d |  j k rB |  j  d d  t d  |  _ t S|  j d } | d k r | t j j d  k r |  j  d d	  t d
  | |  _ t S|  j   |  j	 k r |  j
 |  j j r t d  |  _ t Sn  d |  _ |  j   s t S|  j   st S|  j |  j  st S|  j   s't S|  j
 j j d k r\t d  |  _ |  j
 j   t St S(   s$   Check if the package is installable.i   t   checkt   Architecturei   s   ERROR: no architecture fields$   No Architecture field in the packaget   alls   APT::Architectures   ERROR: Wrong architecture dude!s   Wrong architecture '%s's$   A later version is already installedR   i    s1   Failed to satisfy all dependencies (broken cache)(   R   R   R*   R   R4   R   t   configt   findR   R   R   R   R1   R^   R   t   _satisfy_dependsRX   R@   t   broken_countt   clearR0   (   R   t   arch(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR     s8    $	c         C   s   |  j  t j |   S(   s-   Satisfy the dependencies in the given string.(   R   R   RS   (   R   t
   dependsstr(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   satisfy_depends_str  s    c         C   s   y t  j |  j j  } Wn t k
 r, n Xx3 | D]+ } |  j |  s4 |  j |  s_ t Sq4 q4 Wxc |  j D]X } y |  j | j	 d t  Wqm t
 k
 r } t d  | |  _ |  j j   t SXqm Wt S(   s   Satisfy the dependencies.t	   from_users   Cannot install '%s'(   R   t   ActionGroupR   R@   t   AttributeErrorR=   RI   R4   R   t   mark_installR)   R*   R   R   R0   (   R   RX   t   _actiongroupR5   R:   t   e(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR     s     	c         C   s:   |  j  d d |  j  |  j d k r3 |  j   n  |  j S(   s   Return missing dependencies.i   s   Installing: %sN(   R   R   R   R   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   missing_deps  s    c         C   s   g  } g  } g  } x |  j  D] } | j s4 | j r | j | j  t } x! | j j D] } | | j O} qW W| s | j | j  q n  | j	 r | j | j  q q W| | | f S(   s   Get the changes required to satisfy the dependencies.

        Returns: a tuple with (install, remove, unauthenticated)
        (
   R   RJ   t   marked_upgradeR"   R#   R4   RK   t   originst   trustedt   marked_delete(   R   t   installt   removet   unauthenticatedR:   t   authenticatedt   origin(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   required_changes  s    	c         C   s   y d d l  m } Wn t t d    n Xg  } x< | |  j  j D]( } | rI | d k rI | j |  qI qI Wt |  S(   s,    return the list of files in control.tar.gt i(   R   s"   Python-debian module not availablet   .(   t   debian.debfileR   t	   ExceptionR*   R   R   R"   t   sorted(   R   R   t   contentR#   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   control_filelist  s    c         C   sX   d } xK t  |   D]= \ } } | d d k r< | d 7} n  | d t |  7} q W| S(   NR   iP   i    s   
s   %2.2x (   Rj   t   ord(   t   in_datat   hexR{   t   c(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   to_hex  s    c         C   sV   d } xI |  D]A } t  |  d k  s7 t  |  d k rD | d 7} q | | 7} q W| S(   NR   i
   i   t    (   R   (   R   t   sR   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt	   to_strish  s    $c   
      C   s   | j  d  r | d } n  | j |  } | j d  r} | r} t |  } t j d |  } t d  } | | j   7} n  y t | d  } Wn3 t	 k
 r } t d  }	 |	 |  j
 |  7}	 |	 SX| S(   Ns   ./i   s   .gzt   fileobjs   Automatically decompressed:

s   utf-8s,   Automatically converted to printable ascii:
(   t
   startswithR   t   endswithR   t   gzipt   GzipFileR*   t   readt   unicodeR   R   (
   R   t   partR#   t   auto_decompresst   auto_hexR%   t   iot   gzR   t   new_data(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   _get_content  s    c         C   s3   y |  j  |  j j |  SWn t k
 r. d SXd S(   s6    return the content of a specific control.tar.gz file R   N(   R   R   R   t   LookupError(   R   R#   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   control_content)  s    c         C   s3   y |  j  |  j j |  SWn t k
 r. d SXd S(   s6    return the content of a specific control.tar.gz file R   N(   R   R   R%   R   (   R   R#   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   data_content0  s    c         C   s#   | |  j  k r t j | IJn  d S(   s%   Write debugging output to sys.stderr.N(   t   debugt   syst   stderr(   R   t   levelt   msg(    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   7  s    c         C   s   | d k r+ t j t j d d d |  j  Sy | j   Wn t k
 rV | j   n X| j |  j  } y | j	   Wn t k
 r | j
   n X| Sd S(   s   Install the package.t   dpkgs   -iN(   R   t   ost   spawnlpt   P_WAITR   t   start_updateR   t   startUpdatet   runt   finish_updatet   finishUpdate(   R   t   install_progressR]   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   <  s    (   s   data.tar.gzs   data.tar.bz2s   data.tar.lzmas   data.tar.xzN(+   R   R   R   t   rangeR   R   R   R   t   _supported_data_membersR   R   R   R   R!   t   propertyR+   R=   RI   RN   RQ   RU   RX   RZ   R\   RL   R^   R   R0   R   R   R   R   R   R   R   t   staticmethodR   R   R   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   !   sD    			'	-								?	3			
			t   DscSrcPackagec           B   sM   e  Z d  Z d d d  Z e d    Z e d    Z d   Z d   Z	 RS(   s#   A locally available source package.c         C   sr   t  j |  d  |  | |  _ g  |  _ g  |  _ t   |  _ d |  _ g  |  _	 |  j d  k	 rn |  j
 |  j  n  d  S(   NR   (   R   R   R   R   t   _dependst
   _conflictsR   R   R   t   binariesR   (   R   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   O  s    					c         C   s   |  j  S(   s&   Return the dependencies of the package(   R   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyRX   Z  s    c         C   s   |  j  S(   s&   Return the dependencies of the package(   R   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyRU   _  s    c   	      C   sp  d d g } d d g } t  |  } t j |  } z x | D] } x= | D]5 } | | k rb qJ n  |  j j t j | |   qJ Wx= | D]5 } | | k r q n  |  j j t j | |   q Wd | k r | d |  _ n  d | k r| d j d  |  _	 n  d | k r= | d |  j
 d <q= q= WWd	 ~ | j   Xt d
  |  j d j |  j	  f } | |  j
 d <d	 S(   s   Open the package.s   Build-Dependss   Build-Depends-Indeps   Build-Conflictss   Build-Conflicts-Indept   Sourcet   Binarys   , R_   NsB   Install Build-Dependencies for source package '%s' that builds %s
R   t   Description(   R   R   t   TagFileR   RW   t   parse_src_dependsR   R   t   splitR   R   t   closeR*   Rv   (	   R   t   filet   depends_tagst   conflicts_tagst   fobjt   tagfilet   sect   tagR   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   d  s4    !!	c         C   sl   |  j    s\ xM |  j D]? } |  j | j j rD t t d    n  |  j | j   q Wn  |  j |  j	  S(   s%   Check if the package is installable..s%   An essential package would be removed(
   R^   R   R   RB   t	   essentialR   R*   t   mark_deleteR   RX   (   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR     s    N(
   R   R   R   R   R   R   RX   RU   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyR   L  s   	c    	      C   s"  d d l  m }  d d l m } |    } d } d | | j |  f GH| j |  } d | GHx | D] } d | j GHqf Wt t j	 d |  } d	 | j
 GH| j   s d
 GH| j GHn  d | j GH| j GH| j GHd GH| j |    } | GHt d |  } d } | j t j |   GHd S(   s   Test functioni(   R
   (   t   DpkgInstallProgresss   www-browsers   %s virtual: %ss   Providers for %s :s    %si   s   Deb: %ss   can't be satifieds   missing deps: %ss   Installing ...R   s:   libc6 (>= 2.3.2), libaio (>= 0.3.96) | libaio1 (>= 0.3.96)N(   t	   apt.cacheR
   t   apt.progressR   R-   R.   R#   R   R   t   argvR   R   R   R   R   R+   R   R   R   R   RS   (	   R
   R   R   t   vpRF   R:   t   dt   retR   (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   _test  s.    		t   __main__(   R   R	   R   R   R   R   R   R    R*   R   t   IOErrorR   t   objectR   R   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/debfile.pyt   <module>   s      -B	%