ó
¬M‘Nc           @   sn  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 Z d d l Z d d l Z d d l	 Z	 e	 j
 d d e ƒ d d l Z d d l Z d d l m Z d e f d „  ƒ  YZ e ƒ  Z e d k rjd d l Z d d l Z d	 e j f d
 „  ƒ  YZ y> e j d d g d e j d e j ƒd k rRe j ƒ  n  Wn e k
 rfn Xn  d S(   sy   apport.PackageInfo class implementation for python-apt and dpkg.

This is used on Debian and derivatives such as Ubuntu.
iÿÿÿÿNt   ignores   apt API not stable yet(   t   PackageInfot   __AptDpkgPackageInfoc           B   s.  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z e d d „ Z e d „  ƒ Z d „  Z d „  Z d d „ Z d „  Z d „  Z e d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z  d „  Z! d „  Z" RS(   s€   Concrete apport.PackageInfo class implementation for python-apt and
    dpkg, as found on Debian and derivatives such as Ubuntu.c         C   s(   d  |  _ d  |  _ d  |  _ d |  _ d  S(   Ns   /etc/default/apport(   t   Nonet
   _apt_cachet   _contents_dirt   _mirrort   configuration(   t   self(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   __init__   s    			c         C   sD   y, |  j  r+ d d  l } | j |  j  ƒ n  Wn t k
 r? n Xd  S(   Niÿÿÿÿ(   R   t   shutilt   rmtreet   AttributeError(   R   R
   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   __del__#   s    	c         C   sX   |  j  sQ y" t j t j j j ƒ  ƒ |  _  WqQ t k
 rM t j ƒ  |  _  qQ Xn  |  j  S(   st   Return apt.Cache() (initialized lazily).
        
        Throw a ValueError if the package does not exist.
        (   R   t   aptt   Cachet   progresst   baset
   OpProgressR   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   _cache+   s    	"c         C   s6   y |  j  ƒ  | SWn t k
 r1 t d ƒ ‚ n Xd S(   s}   Return apt.Cache()[package] (initialized lazily).
        
        Throw a ValueError if the package does not exist.
        s   package does not existN(   R   t   KeyErrort
   ValueError(   R   t   package(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   _apt_pkg9   s    c         C   s4   |  j  | ƒ } | j } | s- t d ƒ ‚ n  | j S(   s*   Return the installed version of a package.s   package does not exist(   R   t	   installedR   t   version(   R   R   t   pkgt   inst(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_versionC   s
    	c         C   s   |  j  | ƒ j j S(   s1   Return the latest available version of a package.(   R   t	   candidateR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_available_versionL   s    c         C   sb   |  j  | ƒ j j } | s g  Sg  | j j d g  ƒ | j j d g  ƒ D] } | d j j ^ qH S(   s/   Return a list of packages a package depends on.t   Dependst
   PreDependsi    (   R   t   _pkgt   current_vert   depends_listt   gett
   target_pkgt   name(   R   R   t   cur_vert   d(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_dependenciesQ   s
    c         C   s^   |  j  | ƒ j r% |  j  | ƒ j j S|  j  | ƒ j rJ |  j  | ƒ j j St d | ƒ ‚ d S(   s-   Return the source package name for a package.s   package %s does not existN(   R   R   t   source_nameR   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt
   get_source[   s
    c   
      C   s@  t  j d d d g d t  j ƒ} | j ƒ  d j ƒ  } | j d k sL t ‚ |  j | ƒ } | j rz | j j	 d k rz t S| g } yf x_ t j d ƒ D]N } xE t t j j d | ƒ ƒ D]( } | j ƒ  } | r¸ | j | ƒ q¸ q¸ Wq– WWn t k
 rü n Xd } | j j } | r<x$ | D] }	 |	 j | k rt SqWn  t S(   sa   Check if a package is a genuine distro package (True) or comes from
        a third-party source.t   lsb_releases   -is   -st   stdouti    s   /etc/apport/native-origins.dN(   t
   subprocesst   Popent   PIPEt   communicatet   stript
   returncodet   AssertionErrorR   R   R   R   t   Falset   ost   listdirt   opent   patht   joint   appendt   OSErrorR   t   originst   origint   True(
   R   R   R,   t   this_osR   t   native_originst   ft   lineR=   t   o(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   is_distro_packagee   s.    	"c         C   sj   |  j  | ƒ j r+ |  j  | ƒ j j p* d S|  j  | ƒ j rV |  j  | ƒ j j pU d St d | ƒ ‚ d S(   s—   Return the architecture of a package.

        This might differ on multiarch architectures (e. g.  an i386 Firefox
        package on a x86_64 system)t   unknowns   package %s does not existN(   R   R   t   architectureR   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_architecture…   s
    c         C   sQ   |  j  d | g ƒ } | d k r% d Sg  | j ƒ  D] } | j d ƒ s2 | ^ q2 S(   s*   Return list of files shipped by a package.s   -Lt   divertedN(   t
   _call_dpkgR   t
   splitlinest
   startswith(   R   R   t   listRB   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt	   get_files’   s    c   	      C   s´  d | |  j  ƒ  f } t j j | ƒ s5 d | } n  yC t j | ƒ } t j | j ƒ sb t ‚ n  t | j	 | j
 ƒ } Wn t k
 rŒ g  SXd } d | |  j  ƒ  f } t j j | ƒ sÞ d | } t j j | ƒ sÞ g  Sn  x¸ t | ƒ D]ª } y† d | k rt j d | ƒ wë n  | j ƒ  } | s>t j d | ƒ wë n  t j d	 | d
 ƒ } t | j	 | j
 ƒ | k rvwë n  Wn t k
 rŠn X| | 7} që W| r¬|  j | ƒ Sg  Sd S(   s/   Return list of all modified files of a package.s   /var/lib/dpkg/info/%s:%s.lists   /var/lib/dpkg/info/%s.listt    s    /var/lib/dpkg/info/%s:%s.md5sumss   /var/lib/dpkg/info/%s.md5sumst    s(   %s contains NUL character, ignoring lines%   %s contains empty line, ignoring linet   /iÿÿÿÿN(   t   get_system_architectureR6   R9   t   existst   statt   S_ISREGt   st_modeR<   t   maxt   st_mtimet   st_ctimeR8   t   apportt   warningt   splitt   _check_files_md5(	   R   R   t   listfilet   st   max_timet   sumst   sumfileRC   t   words(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_modified_filesš   sD    	

c         C   s¶   d } d } d } x | r± | t | ƒ k  r± t j d d d d | g | | | | !d t j d t j d	 t j d
 t ƒ} | j ƒ  d } | j d k r¤ | } n  | | 7} q W| S(   ss   Call fgrep for a pattern on given file list and return the first
        matching file, or None if no file matches.id   i    t   fgreps   -lxmt   1s   --t   stdinR-   t   stderrt	   close_fdsN(   R   t   lenR.   R/   R0   R?   R1   R3   (   R   t   patternt	   file_listt   matcht
   slice_sizet   it   pt   out(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   __fgrep_filesÉ   s    	c         C   s“  t  j d d | g d t  j d t  j ƒ} | j ƒ  d } | j d k r] | r] | j ƒ  d St j j t j j	 | ƒ ƒ d j
 ƒ  } g  } g  } x t j d ƒ D]p }	 t j j t j j	 |	 ƒ ƒ d j
 ƒ  j d ƒ d }
 |
 | k sô | |
 k r| j |	 ƒ q¡ | j |	 ƒ q¡ W|  j | | ƒ } | sB|  j | | ƒ } n  | rut j j t j j	 | ƒ ƒ d j d ƒ d S| r‹|  j | | ƒ Sd	 Sd	 S(
   só  Return the package a file belongs to, or None if the file is not
        shipped by any package.
        
        If uninstalled is True, this will also find files of uninstalled
        packages; this is very expensive, though, and needs network access and
        lots of CPU and I/O resources. In this case, map_cachedir can be set to
        an existing directory which will be used to permanently store the
        downloaded maps. If it is not set, a temporary directory will be used.
        s   /usr/sbin/dpkg-diverts   --listR-   Rh   i    iÿÿÿÿs   /var/lib/dpkg/info/*.listt   :N(   R.   R/   R0   R1   R3   R\   R6   R9   t   splitextt   basenamet   lowert   globR;   t    _AptDpkgPackageInfo__fgrep_filest   _search_contentsR   (   R   t   filet   uninstalledt   map_cachedirt   dpkgRq   t   fnamet	   all_listst   likely_listsRB   Rp   Rm   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_file_packageÜ   s*    (5-c         C   sY   t  j d d g d t  j ƒ} | j ƒ  d j ƒ  } | j d k sI t ‚ | sU t ‚ | S(   sc   Return the architecture of the system, in the notation used by the
        particular distribution.R}   s   --print-architectureR-   i    (   R.   R/   R0   R1   R2   R3   R4   (   t   klassR}   t   arch(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyRR     s    c         C   sQ   t  j d d g d t  j ƒ} | j ƒ  d j ƒ  } | j d k sI t ‚ d | S(   sà   Return a list of default library search paths.
        
        The entries should be separated with a colon ':', like for
        $LD_LIBRARY_PATH. This needs to take any multiarch directories into
        account.
        s   dpkg-architectures   -qDEB_HOST_MULTIARCHR-   i    s   /lib/%s:/lib(   R.   R/   R0   R1   R2   R3   R4   (   R   R}   t   multiarch_triple(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_library_paths  s
    c         C   s   | |  _  d S(   sÚ   Explicitly set a distribution mirror URL for operations that need to
        fetch distribution files/packages from the network.

        By default, the mirror will be read from the system configuration
        files.N(   R   (   R   t   url(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt
   set_mirror  s    c      
   C   s  d d d | g } | r/ | d c d | 7<n  y, t  j | d t  j d | ƒd k rZ d SWn t k
 ro d SXd } xE t j t j j | | d	 ƒ ƒ D]! } t j j	 | ƒ r™ | } q™ q™ W| sÍ t
 d
 ‚ y/ t  j d d t d | d t  j d t  j ƒWn t k
 rn X| S(   s  Download given source package and unpack it into dir (which should
        be empty).

        This also has to care about applying patches etc., so that dir will
        eventually contain the actually compiled source.

        If version is given, this particular version will be retrieved.
        Otherwise this will fetch the latest available version.

        Return the directory that contains the actual source root directory
        (which might be a subdirectory of dir). Return None if the source is
        not available.s   apt-gets   --assume-yest   sourceiÿÿÿÿt   =R-   t   cwdi    s   -*s.   could not determine source tree root directorys˜   debian/rules patch || debian/rules apply-patches || debian/rules apply-dpatches || debian/rules unpack || debian/rules patch-stamp || debian/rules setupt   shellRh   N(   R.   t   callR0   R   R<   Rw   R6   R9   R:   t   isdirR4   R?   (   R   t
   srcpackaget   dirR   t   argvt   rootR(   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_source_tree(  s*    )c         C   s   d t  j ƒ  d S(   s„   Return the actual Linux kernel package name.

        This is used when the user reports a bug against the "linux" package.
        s   linux-image-i   (   R6   t   uname(   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   get_kernel_packageT  s    c         C   sŸ  d d l  } d d l } g  } g  } | d j ƒ  d } | d } | d j ƒ  d } d | }	 |  j ƒ  }
 |
 j |	 ƒ r’ |
 |	 j r’ | | f S| j j d ƒ d	 } d
 |	 | | f } d | } t t	 j
 j | | ƒ d ƒ } | j | ƒ } | j ƒ  d k rd Sx0 t r:| j d ƒ } | s*Pn  | j | ƒ qW| j ƒ  t j d d t	 j
 j | | ƒ g ƒ } | d k r•| j | j d ƒ d ƒ n  | | f S(   sÀ   Install kernel debug package 

        Ideally this would be just another package but the kernel is
        special in various ways currently so we can not use the apt
        method.
        iÿÿÿÿNt   Unamei   t   Architecturet   Packages   linux-image-debug-%ss   Dir::Cache::archivess   /partials   %s_%s_%s.ddebs,   http://ddebs.ubuntu.com/pool/main/l/linux/%st   wi  RO   t   linuxi   i   R}   s   -ii    t   _(   RO   s   linuxi    (   t   urllibt   apt_pkgR\   R   t   has_keyt   isInstalledt   Configt   FindDirR8   R6   R9   R:   t   urlopent   getcodeR?   t   readt   writet   flushR.   RŒ   R;   (   R   t   reportR›   Rœ   R   t   outdatedt   kverRƒ   t   vert   debug_pkgnamet   ct
   target_dirt   debR†   Rq   t   ut   blockt   ret(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   _install_debug_kernel\  s6    



	
'c      	   C   s‡  | s d } n t  j j | | d ƒ } t  j j | ƒ sL t d | ƒ ‚ n  | r¹ t } | ry t  j j | | d ƒ }	 n t  j j | d d ƒ }	 y t  j |	 ƒ WqË t k
 rµ qË Xn t } t	 j
 ƒ  }	 |  j |	 | ƒ | ró t j j ƒ  }
 n t j j ƒ  }
 t j ƒ  } | j |
 ƒ t j ƒ  } d } xv| D]n\ } } y | | j } Wn t k
 rjd } n X| sœd | } | | d 7} t j | ƒ q4n  | rØ| j | k rØd	 | | | j f } | | d 7} n  | | j t t ƒ | j d
 k r4| j | d ƒ r)| | d j t t ƒ q¢| j | d ƒ r¢| | d j t t ƒ | | d j j | j k rŸ| d | | j | | d j j f 7} qŸq¢q4q4Wt j j |
 ƒ } t j j | j ƒ } y | j | | ƒ } Wn< t j  j! k
 r!} t j" d t# | ƒ ƒ t$ j% d ƒ n X| r0d GHn  x- | j& D]" } t' j( d d | j) | g ƒ q:W| rvt* j+ |	 ƒ n  t j j, ƒ  | S(   s•  Install packages into a sandbox (for apport-retrace).

        In order to work without any special permissions and without touching
        the running system, this should only download and unpack packages into
        the given root directory, not install them into the system.

        configdir points to a directory with by-release configuration files for
        the packaging system; this is completely dependent on the backend
        implementation, the only assumption is that this looks into
        configdir/release/, so that you can use retracing for multiple
        DistroReleases. As a special case, if configdir is None, it uses the
        current system configuration, and "release" is ignored.

        release is the value of the report's 'DistroRelease' field.

        packages is a list of ('packagename', 'version') tuples. If the version
        is None, it should install the most current available version.
        
        If cache_dir is given, then the downloaded packages will be stored
        there, to speed up subsequent retraces.

        Return a string with outdated packages, or None if all packages were
        installed.
        s   /etc/apt/sources.lists   sources.lists   %s does not existR   t   systemRO   s#   package %s does not exist, ignorings   
s+   %s version %s required, but %s is availablet   alls   -dbgs   -dbgsymsK   outdated debug symbol package for %s: package version %s dbgsym version %s
s+   Package download error, try again later: %sic   s   Extracting downloaded debs...R}   s   -xN(-   R6   R9   R:   RS   t   SystemErrorR5   t   makedirsR<   R?   t   tempfilet   mkdtempt   _build_apt_sandboxR   R   t   TextFetchProgresst   FetchProgressR   t   updateR   R   R   RZ   R[   R   t   mark_installRG   R   Rœ   t
   GetAcquiret   GetPackageManagert	   _depcachet   _fetchArchivest   cachet   FetchFailedExceptiont   errort   strt   syst   exitt   ItemsR.   t
   check_callt   DestFileR
   R   t   init_config(   R   t   rootdirt	   configdirt   releaset   packagest   verboset	   cache_dirt   apt_sourcest   tmp_aptroott   aptroott   fetchProgressR«   t   obsoleteR   R©   R   t   mR˜   t   fetchert   pmt   rest   eRo   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   install_packages‚  sz    	

/ c         C   s   t  j j |  j ƒ  j ƒ  | ƒ S(   s2   Return known package names which match given glob.(   Rw   t   fnmatcht   filterR   t   keys(   R   t   nameglob(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   package_name_globð  s    c         C   s^   t  j d g | d t  j d t  j ƒ} | j t ƒ d } | j d k rN | St d ƒ ‚ d S(   sR   Call dpkg with given arguments and return output, or return None on
        error.R}   R-   Rh   i    s   package does not existN(   R.   R/   R0   R1   t   inputR3   R   (   R   t   argsR}   Rq   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyRJ   ù  s    c         C   s  t  j j | ƒ ra t j d d | g d t j d t j d t d d d i  ƒ} | j ƒ  d	 } nU t j d d g d
 t j d t j d t j d t d d d i  ƒ} | j | ƒ d	 } | j d	 k rÉ g  Sg  } xC | j	 ƒ  D]5 } | j
 d ƒ rÜ | j | j d d ƒ d	 ƒ qÜ qÜ W| S(   s…   Internal function for calling md5sum.

        This is separate from get_modified_files so that it is automatically
        testable.s   /usr/bin/md5sums   -cR-   Rh   Ri   RŠ   RQ   t   envi    Rg   t   FAILEDRs   i   (   R6   R9   RS   R.   R/   R0   R?   R1   R3   RK   t   endswithR;   t   rsplit(   R   Rb   RÖ   Rq   t
   mismatchest   l(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyR]     s     $c         C   sˆ   |  j  s xu t d ƒ D]X } | j ƒ  } t | ƒ d k r | d d k r | d j d ƒ r | d |  _  Pq q Wt d ƒ ‚ n  |  j  S(   s   Return the distribution mirror URL.

        If it has not been set yet, it will be read from the system
        configuration.s   /etc/apt/sources.listi   i    R­   i   s   http://sX   cannot determine default mirror: /etc/apt/sources.list does not contain a valid deb line(   R   R8   R\   Rj   RL   R´   (   R   Rè   t   fields(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   _get_mirror!  s    	5c         C   s  | r | } n$ |  j  s* t j ƒ  |  _  n  |  j  } |  j ƒ  } t j j | d | ƒ } t j j | ƒ sd d l } t	 j
 d d g d t	 j ƒ} | j ƒ  d j ƒ  } | j d k s¿ t ‚ d |  j ƒ  | | f }	 | j |	 | ƒ t j j | ƒ st ‚ n  | j d	 ƒ r| d
 } n  d }
 t	 j
 d d d | | g d t	 j d t	 j ƒ} | j ƒ  d } | r™| j ƒ  d
 j d ƒ d j d	 ƒ d }
 n  |
 S(   s4   Internal function for searching file in Contents.gz.s   Contents-%s.gziÿÿÿÿNR,   s   -scR-   i    s   %s/dists/%s/Contents-%s.gzRQ   i   t   zgreps   -m1s   ^%s[[:space:]]Rh   t   ,(   R   R¶   R·   RR   R6   R9   R:   RS   R›   R.   R/   R0   R1   R2   R3   R4   Rê   t   urlretrieveRL   R   R\   (   R   Rz   R|   R   Rƒ   t   mapR›   R,   t   release_nameR†   R   Rë   Rq   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyRy   2  s2    			-c      
   C   s;  t  j j ƒ  t  j j j d | ƒ t  j j j d d ƒ t  j j j d ƒ t j j t j j	 | d d d ƒ ƒ sât j
 t j j	 | d d d ƒ ƒ t j
 t j j	 | d d d ƒ ƒ t j
 t j j	 | d d d	 ƒ ƒ t j
 t j j	 | d
 d d ƒ ƒ t j
 t j j	 | d d d d d ƒ ƒ t j
 t j j	 | d d d d d ƒ ƒ t j
 t j j	 | d d d ƒ ƒ t j j	 | d d d ƒ } t j
 | ƒ t t j j	 | d ƒ d ƒ j ƒ  t j d t j j	 | d
 d d d ƒ ƒ n  t | ƒ G } t t j j	 | d d d ƒ d ƒ  } | j | j ƒ  ƒ Wd  QXWd  QXd  S(   Nt   RootDirs   Debug::NoLockingt   trues    APT::Update::Post-Invoke-Successt   etcR   s   sources.list.ds
   apt.conf.ds   trusted.gpg.dt   usrt   libt   vart   listst   partialRÁ   t   archivest   logR}   t   statusR˜   s   /usr/lib/apt/methodst   methodss   sources.list(   R   Rœ   RÊ   t   configt   sett   clearR6   R9   RS   R:   Rµ   R8   t   closet   symlinkR¤   R£   (   R‚   t   apt_rootRÑ   t   dpkglibt   srct   dest(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyR¸   [  s&    '""""((""+'c         C   s   t  j | | ƒ S(   sk   Compare two package versions.

        Return -1 for ver < ver2, 0 for ver1 == ver2, and 1 for ver1 > ver2.(   R   t   VersionCompare(   R   t   ver1t   ver2(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   compare_versionss  s    c         C   sJ   y t  |  j ƒ j ƒ  } Wn t k
 r- t SXt j d | t j ƒ d k S(   sÛ  Return whether Apport should generate crash reports.

        Signal crashes are controlled by /proc/sys/kernel/core_pattern, but
        some init script needs to set that value based on a configuration file.
        This also determines whether Apport generates reports for Python,
        package, or kernel crashes.
        
        Implementations should parse the configuration file which controls
        Apport (such as /etc/default/apport in Debian/Ubuntu).
        s   ^\s*enabled\s*=\s*0\s*$N(	   R8   R   R£   t   IOErrorR?   t   ret   searcht   MR   (   R   t   conf(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   enabledz  s
    N(#   t   __name__t
   __module__t   __doc__R	   R   R   R   R   R   R)   R+   RE   RH   RN   Rd   Rx   R5   R   R   t   classmethodRR   R…   R‡   R’   R”   R±   RÛ   Rà   RJ   R]   Rê   Ry   R¸   R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyR      s<   				
				
	
	 			/	)			,		'm						)	t   __main__t   _Tc           B   s×   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s,   t  j |  _ t j ƒ  |  _ t j j ƒ  d  S(   N(	   t   implR   t	   orig_confR¶   R·   t   workdirR   Rœ   t   init_system(   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   setUp™  s    c         C   s    |  j  t _ t j |  j ƒ d  S(   N(   R  R  R   R
   R   R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   tearDownŸ  s    c         C   s¥  t  j ƒ  } z„t j j | d ƒ } t j j | d ƒ } t j j | d ƒ } t | d ƒ j d ƒ t | d ƒ j d ƒ t | d ƒ j d | d | f ƒ |  j t j	 | ƒ g  d	 ƒ t | d ƒ j d
 ƒ |  j t j	 | ƒ | d g d ƒ t | d ƒ j d ƒ |  j t j	 | ƒ | d | g d ƒ t | d ƒ j d ƒ |  j t j	 | ƒ | g d ƒ |  j t j	 t | ƒ j
 ƒ  ƒ | g d ƒ Wd t j | ƒ Xd S(   s   _check_files_md5().s
   test 1.txts
   test:2.txts   sums.txtR˜   s
   Some stuffs
   More stuffsZ   2e41290da2fa3f68bd3313174467e3b5  %s
        f6423dfbc4faf022e58b4d3f5ff71a70  %s
        i   s   correct md5sumss   Some stuff!s   file 1 wrongs   More stuff!s   files 1 and 2 wrongs   file 2 wrongN(   R¶   R·   R6   R9   R:   R8   R¤   t   assertEqualR  R]   R£   R
   R   (   R   t   tdt   f1t   f2Rb   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_check_files_md5£  s&    #&c         C   sO   |  j  t j d ƒ j d ƒ ƒ |  j t t j d ƒ |  j t t j d ƒ d S(   s   get_version().t   libc6t   2t   nonexistingt
   wukrainianN(   t
   assertTrueR  R   RL   t   assertRaisesR   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_versionÁ  s    c         C   s9   |  j  t j d ƒ j d ƒ ƒ |  j t t j d ƒ d S(   s   get_available_version().R   R!  R"  N(   R$  R  R   RL   R%  R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_available_versionÈ  s    c         C   s  t  j d ƒ } |  j t | ƒ d k ƒ |  j d | k ƒ x$ | D] } |  j t  j | ƒ ƒ qB Wt  j d ƒ } |  j t | ƒ d k ƒ |  j d | k ƒ x$ | D] } |  j t  j | ƒ ƒ q¤ Wt  j d ƒ } |  j t | ƒ d k ƒ x$ | D] } |  j t  j | ƒ ƒ qó Wd S(   s   get_dependencies().t   bashi   R   t	   coreutilsi   N(   R  R)   R$  Rj   R   (   R   R(   t   dep(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_dependenciesÎ  s    c         C   sO   |  j  t t j d ƒ |  j t j d ƒ d ƒ |  j d t j d ƒ k ƒ d S(   s   get_source().R"  R(  t   glibcR   N(   R%  R   R  R+   R  R$  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_sourceå  s    c         C   s0   |  j  t t j d ƒ |  j t j d ƒ ƒ d S(   s   is_distro_package().R"  R(  N(   R%  R   R  RE   R$  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_is_distro_packageì  s    c         C   s|   |  j  t t j d ƒ t j d d g d t j ƒ} | j ƒ  d j ƒ  } | j	 d k s_ t
 ‚ |  j t j d ƒ | ƒ d S(   s   get_architecture().R"  R}   s   --print-architectureR-   i    R(  N(   R%  R   R  RH   R.   R/   R0   R1   R2   R3   R4   R  (   R   R(   t   system_arch(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_architectureó  s    c         C   s6   |  j  t t j d ƒ |  j d t j d ƒ k ƒ d S(   s   get_files().R"  s	   /bin/bashR(  N(   R%  R   R  RN   R$  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_filesþ  s    c         C   sh   |  j  t j d ƒ d ƒ |  j  t j d ƒ d ƒ |  j  t j d ƒ d ƒ |  j  t j d ƒ d ƒ d S(	   s&   get_file_package() on installed files.s	   /bin/bashR(  s   /bin/catR)  s   /etc/blkid.tabt	   libblkid1s   /nonexistingN(   R  R  R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_file_package  s    c         C   sC  t  j d d g d t  j ƒ} | j ƒ  d j ƒ  } | j d k sI t ‚ t j ƒ  } zÙt	 j
 j | d | ƒ } t	 j | ƒ t j t	 j
 j | d t j ƒ  ƒ d ƒ } | j d ƒ | j ƒ  |  j t j d	 t | ƒ d ƒ |  j t j d	 t | ƒ d
 ƒ |  j t j d t | ƒ d
 ƒ t j d ƒ |  j t t j d	 t ƒ t j d | ƒ |  j t j d	 t ƒ d
 ƒ |  j t j d t ƒ d
 ƒ t	 j
 j | d ƒ } t	 j | ƒ |  j t j d	 t | ƒ d
 ƒ |  j t t	 j | ƒ ƒ d ƒ |  j t	 j | ƒ d j d ƒ ƒ |  j t j d t | ƒ d ƒ Wd t  j! | ƒ Xd S(   s+   get_file_package() on uninstalled packages.R,   s   -scR-   i    t   distss   Contents-%s.gzR˜   s  
 foo header
FILE                                                    LOCATION
usr/bin/frobnicate                                      foo/frob
usr/bin/frob                                            foo/frob-utils
bo/gu/s                                                 na/mypackage
s   usr/bin/frobs
   frob-utilss   /usr/bin/frobs   file:///foo/nonexistings   file://RÁ   i   s	   Contents-s   /bo/gu/st	   mypackageN("   R.   R/   R0   R1   R2   R3   R4   R¶   R·   R6   R9   R:   Rµ   t   gzipR8   R  RR   R¤   Rÿ   R  R   R5   R   R?   R‡   R%  R	  t   mkdirRj   R7   R$  RL   R
   R   (   R   R,   Rï   t   basedirt   mapdirRB   RÐ   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt!   test_get_file_package_uninstalled  s8    
##c         C   sŒ   t  j d d t d t  j ƒ} | j ƒ  d } | j d k sC t ‚ | sO t ‚ | j ƒ  } | d } | d } |  j t	 j
 | ƒ | ƒ d S(   s'   get_file_package() for a diverted file.s'   LC_ALL=C dpkg-divert --list | head -n 1R‹   R-   i    i   iÿÿÿÿN(   R.   R/   R?   R0   R1   R3   R4   R\   R  R  R   (   R   Rp   Rq   Ré   Rz   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_file_package_diversion=  s    

c         C   s3   t  j ƒ  } |  j | d ƒ |  j d | k ƒ d S(   s   get_system_architecture().RO   s   
N(   R  RR   t   assertNotEqualR$  (   R   Rƒ   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_system_architectureL  s    c         C   sY   t  j ƒ  } |  j | d ƒ |  j d | k ƒ |  j d | k ƒ |  j d | k ƒ d S(   s   get_library_paths().RO   Rs   s   /libs   
N(   R  R…   R<  R$  (   R   t   paths(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_library_pathsT  s
    c         C   s¬   |  j  t j d d ƒ d ƒ |  j  t j d d ƒ d ƒ |  j  t j d d ƒ d ƒ |  j  t j d d ƒ d ƒ |  j  t j d d	 ƒ d ƒ |  j  t j d
 d ƒ d ƒ d S(   s   compare_versions.Rf   R!  iÿÿÿÿs   1.0-1ubuntu1s   1.0-1ubuntu2i    i   s   1:1.0-1s   2007-2s	   1:1.0-1~1N(   R  R  R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_compare_versions^  s    c         C   s  d t  _ |  j t  j ƒ  t ƒ t j ƒ  } | j t  _ | j d ƒ | j	 ƒ  |  j t  j ƒ  t ƒ | j
 ƒ  t j ƒ  } | j t  _ | j d ƒ | j	 ƒ  |  j t  j ƒ  t ƒ | j
 ƒ  t j ƒ  } | j t  _ | j d ƒ | j	 ƒ  |  j t  j ƒ  t ƒ | j
 ƒ  d S(   s   enabled.s   /nonexistings    # configuration file
enabled = 1s#   # configuration file
  enabled =0  s!   # configuration file
nothing hereN(   R  R   R  R  R?   R¶   t   NamedTemporaryFileR&   R¤   R¥   Rÿ   R5   (   R   RB   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_enabledh  s(    	




c         C   s   |  j  d t j ƒ  k ƒ d S(   s   get_kernel_package().R™   N(   R$  R  R”   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_get_kernel_pacakgeƒ  s    c         C   sw   |  j  t t j d ƒ ƒ d k ƒ |  j  d t j d ƒ k ƒ |  j t j d ƒ d g ƒ |  j t j d ƒ g  ƒ d S(   s   package_name_glob().s   a*i   R(  s   ba*hs   xzywef*N(   R$  Rj   R  Rà   R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_package_name_globˆ  s    "c      	   C   s  |  j  ƒ  t j |  j |  j d d d d g t |  j ƒ |  j t j	 j
 t j	 j |  j d ƒ ƒ ƒ |  j t j	 j
 t j	 j |  j d	 ƒ ƒ ƒ |  j t j	 j
 t j	 j |  j d
 ƒ ƒ ƒ |  j t j	 j
 t j	 j |  j d ƒ ƒ ƒ |  j t j |  j ƒ d g ƒ |  j t j t j	 j |  j d ƒ ƒ d g ƒ t j t j	 j |  j d d d d d d ƒ ƒ } g  | D] } | j d ƒ d ^ qh} |  j d | k ƒ |  j d | k ƒ |  j d | k ƒ |  j d | k ƒ |  j d | k ƒ t j |  j |  j d d g t |  j ƒ t j |  j |  j d d  g ƒ } |  j t | j ƒ  ƒ d ƒ |  j d | k ƒ |  j d | k ƒ |  j t j	 j
 t j	 j |  j d ƒ ƒ ƒ t j |  j |  j d d! g ƒ } |  j t | j ƒ  ƒ d ƒ |  j d | k ƒ |  j d | k ƒ d S("   s/   install_packages() with versions and with caches
   Foonux 1.2R)  s   7.4-2ubuntu2R   s   2.11.1-0ubuntu7t   tzdatas   2010i-1s   usr/bin/stats   usr/lib/debug/usr/bin/stats   usr/share/zoneinfo/zone.tabs   usr/share/doc/libc6/copyrights   sources.listR   Rõ   RÁ   Rø   Rš   i    s   coreutils-dbgsyms	   libc6-dbgs   gnome-commons   1.1i   s   usr/bin/gnome-autogen.sht   buggerboggers	   not existN(   s	   coreutilss   7.4-2ubuntu2(   s   libc6s   2.11.1-0ubuntu7(   RE  s   2010i-1(   s	   coreutilss   7.4-2ubuntu2(   s   gnome-commons   1.1(   RF  N(   t   _setup_foonux_configR  RÛ   RË   RÌ   R5   t   cachedirR$  R6   R9   RS   R:   R  R7   R\   Rj   RK   R   (   R   RÁ   Rp   t   cache_namest   result(    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_install_packages_versioned  sP    
$
&c         C   s   |  j  ƒ  t j |  j |  j d d	 d
 g t d ƒ |  j t j	 j
 t j	 j |  j d ƒ ƒ ƒ |  j t j	 j
 t j	 j |  j d ƒ ƒ ƒ |  j t j	 j
 t j	 j |  j d ƒ ƒ ƒ |  j t j |  j ƒ d g ƒ |  j t j t j	 j |  j d ƒ ƒ d g ƒ |  j t j |  j ƒ g  ƒ d S(   s0   install_packages() without versions and no caches
   Foonux 1.2R)  RE  s   usr/bin/stats   usr/lib/debug/usr/bin/stats   usr/share/zoneinfo/zone.tabs   sources.listN(   s	   coreutilsN(   s   tzdataN(   RG  R  RÛ   RË   RÌ   R   R5   R$  R6   R9   RS   R:   R  R7   RH  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt!   test_install_packages_unversionedÈ  s    

$
c      	   C   s“  |  j  ƒ  t j |  j d d d t j d ƒ f d g t |  j ƒ } |  j t	 j
 j t	 j
 j |  j d ƒ ƒ ƒ |  j t	 j
 j t	 j
 j |  j d ƒ ƒ ƒ |  j t | j ƒ  ƒ d ƒ |  j d | k ƒ |  j d | k ƒ t	 j t	 j
 j |  j d d d	 d
 d d ƒ ƒ } g  | D] } | j d ƒ d ^ q} |  j d | k ƒ |  j d | k ƒ |  j d | k ƒ t j |  j d d d g t |  j ƒ d S(   s,   install_packages() with system configurationR)  RE  s   1.1s   usr/bin/stats   usr/share/zoneinfo/zone.tabi   R²   R   Rõ   RÁ   Rø   Rš   i    s   coreutils-dbgsymN(   s   tzdatas   1.1(   s	   coreutilsN(   RG  R  RÛ   RË   R   R   R5   RH  R$  R6   R9   RS   R:   R  Rj   RK   R7   R\   (   R   RJ  RÁ   Rp   RI  (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   test_install_packages_systemà  s(    
&c         C   së   t  j j |  j d ƒ |  _ t  j j |  j d ƒ |  _ t  j j |  j d ƒ |  _ t  j |  j ƒ t  j |  j ƒ t  j |  j ƒ t  j t  j j |  j d ƒ ƒ t t  j j |  j d d ƒ d ƒ ! } | j	 d ƒ | j	 d ƒ Wd	 QXd	 S(
   s;   Set up directories and configuration for install_packages()RÁ   R‘   Rü   s
   Foonux 1.2s   sources.listR˜   s1   deb http://archive.ubuntu.com/ubuntu/ lucid main
s(   deb http://ddebs.ubuntu.com/ lucid main
N(
   R6   R9   R:   R  RH  RË   RÌ   R7  R8   R¤   (   R   RB   (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyRG  ÿ  s    '(   R  R  R  R  R  R&  R'  R+  R-  R.  R0  R1  R3  R:  R;  R=  R?  R@  RB  RC  RD  RK  RL  RM  RG  (    (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyR  —  s.   												1			
	
				8		R}   s   --helpR-   Rh   i    (   R  R.   R6   Rw   RT   RÅ   R¶   R
  R
   t   warningst   filterwarningst   FutureWarningR   RZ   t   apport.packagingR   R   R  R  t   unittestR6  t   TestCaseR  RŒ   R0   t   mainR<   (    (    (    s9   /usr/lib/python2.7/dist-packages/apport/packaging_impl.pyt   <module>   s(   lÿ ÿ x	ÿ x