ó
1ùÌNc           @   sù   d  d l  m 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
 m
 Z d  d l m Z d  d l m Z m Z m Z d e f d „  ƒ  YZ e d k rõ e d d ƒ Z d	 e j d
 d ƒ GHn  d S(   iÿÿÿÿ(   t   TemplateN(   t   gettext(   t   SourcesList(   t   get_distt   url_downloadablet   country_mirrort   DistUpgradeFetcherCorec           B   sª   e  Z d  Z d Z d Z d e j k Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 d
 „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s2    base class (without GUI) for the upgrade fetcher s    http://archive.ubuntu.com/ubuntut   maint   DEBUG_UPDATE_MANAGERc         C   s+   | |  _  t ƒ  |  _ | |  _ g  |  _ d  S(   N(   t   new_distR   t   current_dist_namet	   _progresst   run_options(   t   selfR	   t   progress(    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   __init__+   s    		c         C   s$   |  j  r  t j j | d ƒ n  d S(   s"    helper to show debug information s   
N(   t   DEBUGt   syst   stderrt   write(   R   t   msg(    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   _debug2   s    	c         C   s   t  S(   N(   t   True(   R   (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   showReleaseNotes7   s    c         C   s   | GH| GHt  S(   s    dummy implementation for error display, should be overwriten
            by subclasses that want to more fancy method
        (   t   False(   R   t   summaryt   message(    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   error:   s    c         C   s–   |  j  j r’ |  j d t j j |  j  j ƒ } |  j d t j j |  j  j ƒ } d t j j | ƒ t j j | ƒ f GH|  j | | ƒ r’ t Sn  t	 S(   Nt   /s   authenticate '%s' against '%s' (
   R	   t   upgradeToolSigt   tmpdirt   ost   patht   basenamet   upgradeToolt   gpgauthenticateR   R   (   R   t   ft   sig(    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   authenticateB   s    ##'s   /etc/apt/trusted.gpgc         C   sñ   t  j ƒ  } d d |  j d d d | g | j _ | j d | | g d d d	 d
 g ƒ} | j d j ƒ  } y | j ƒ  WnX t	 k
 rÒ } d | GHd GH| j d j ƒ  GH| j d
 j ƒ  GH| j d	 j ƒ  GHt
 SXd | k rã t Sd GH| GHt
 S(   sx    authenticated a file against a given signature, if no keyring
            is given use the apt default keyring
        s   --no-optionss	   --homedirs   --no-default-keyrings   --ignore-time-conflicts	   --keyrings   --verifyt
   create_fhst   statust   loggerR   s   exception from gpg: %ss   Debug information: t   VALIDSIGs   invalid result from gpg:(   t   GnuPGInterfacet   GnuPGR   t   optionst
   extra_argst   runt   handlest   readt   waitt   IOErrorR   R   (   R   t   filet	   signaturet   keyringt   gpgt   proct   gpgrest   e(    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyR#   K   s.    		c         C   sÙ   t  j j |  j t  j j |  j ƒ ƒ } d t  j j | ƒ GHt  j j | ƒ sR t SyX t j	 |  j d t  j j |  j ƒ d ƒ } x | D] } | j
 | ƒ qˆ W| j ƒ  Wn( t j k
 rÔ } t j d | ƒ t SXt S(   Ns   extracting '%s'R   t   rs   failed to open tarfile (%s)(   R   R    t   joinR   R!   t   urit   existsR   t   tarfilet   opent   extractt   closet	   ReadErrort   loggingR   R   (   R   t   fnamet   tart   tarinfoR:   (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   extractDistUpgraderi   s    ',c         C   s`   d |  j  |  j j f |  _ } t j j | ƒ s\ |  j t d ƒ t d ƒ d t d ƒ ƒ St	 S(   Ns   %s/%ss   Could not run the upgrade tools   .  sw   This is most likely a bug in the upgrade tool. Please report it as a bug using the command 'ubuntu-bug update-manager'.(
   R   R	   t   namet   scriptR   R    R>   R   t   _R   (   R   RJ   (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   verifyDistUpradery   s
     c      
   C   s)  |  j  d |  j ƒ t d t ƒ } t ƒ  } xé | j D]Þ } | j s6 | j s6 | j d k rd q6 n  | j	 | k ry q6 n  | j	 j
 | ƒ r³ | j |  j k r³ |  j | j k r³ | S| j |  j k r6 d | j k r6 | j	 | t | ƒ } t | |  j  ƒ r| S| j | j	 ƒ q6 q6 W|  j  d ƒ d S(   s  
      try to figure what the mirror is from current sources.list

      do this by looing for matching DEFAULT_COMPONENT, current dist
      in sources.list and then doing a http HEAD/ftp size request
      to see if the uri is available on this server
      s   mirror_from_sources_list: %st   withMatchert   debR   s   no mirror foundt    (   R   R
   R   R   t   sett   listt   disabledt   invalidt   typeR=   t
   startswitht   distt   DEFAULT_COMPONENTt   compst   lenR   t   add(   R   R=   t   default_urit   sourcest   seenR:   t
   mirror_uri(    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   mirror_from_sources_list…   s(    	"c         C   sÎ   | j  |  j ƒ rA |  j d ƒ |  j | |  j ƒ } | rA | Sn  t | ƒ } t ƒ  } | j d | ƒ } y) t | |  j ƒ s t d | ƒ ‚ n  Wn6 t k
 rÉ } |  j d | ƒ | j d d ƒ } n X| S(   s…   
        expand the uri so that it uses a mirror if the url starts
        with a well know string (like archive.ubuntu.com)
        s   trying to find suitable mirrort   countrymirrors   failed to download %ss    url '%s' could not be downloadedRO   (	   RU   t   DEFAULT_MIRRORR   R_   R    R   t   safe_substituteR   t	   Exception(   R   R=   t   new_urit   uri_templatet   mR:   (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt
   _expandUri¤   s    	c         C   sÎ  t  j d d ƒ |  _ } t j | ƒ t j d | ƒ |  j d k ro t j	 j
 d d ƒ t j	 j
 d d ƒ n  t j |  j ƒ } |  j j d k rÍ |  j |  j j ƒ } t j | | d t d	 ƒ ƒ} | n  |  j j d k rÊ|  j |  j j ƒ |  _ t j | |  j d t d
 ƒ ƒ} | | j ƒ  } | | j k rLt j d | ƒ t Sxw t j j |  j j ƒ t j j |  j j ƒ g D]E } t j j | ƒ oªt j j | ƒ d k s}t j d | ƒ t Sq}Wt St S(   s.    download the tarball with the upgrade script t   prefixs   update-manager-s   using tmpdir: '%s'i    s   Debug::Acquire::httpt   1s   Debug::Acquire::ftpt   descrs   Upgrade tool signatures   Upgrade tools   fetch result != continue (%s)s   file '%s' missingN(   t   tempfilet   mkdtempR   R   t   chdirRD   t   debugR   t   apt_pkgt   Configt   Sett   AcquireR   R	   R   t   NoneRg   t   AcquireFileRK   R"   R=   R/   t   RESULT_CONTINUEt   warnR   R    R!   R>   t   getsizeR   (   R   R   t   fetcherR=   t   af1t   af2t   resultR$   (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   fetchDistUpgrader½   s<    			*c         C   sV   |  j  g |  j } t j ƒ  d k r? t j d d g | ƒ n t j |  j  | ƒ d  S(   Ni    s   /usr/bin/sudot   sudo(   RJ   R   R   t   getuidt   execv(   R   t   args(    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   runDistUpgraderã   s    c         C   s!   t  j d ƒ t j |  j ƒ d  S(   Ns   ..(   R   Rm   t   shutilt   rmtreeR   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   cleanupê   s    c         C   s‹  |  j  ƒ  s d  S|  j ƒ  s< |  j t d ƒ t d ƒ ƒ d  S|  j ƒ  sr |  j t d ƒ t d ƒ ƒ |  j ƒ  d  S|  j ƒ  sž |  j t d ƒ t d ƒ ƒ d  S|  j ƒ  sÔ |  j t d ƒ t d ƒ ƒ |  j ƒ  d  SyK t j	 |  j
 t j ƒ st d	 |  j
 ƒ } d
 | _ | ‚ n  |  j ƒ  Wne t k
 r†} | j d
 k r`|  j t d ƒ t d ƒ ƒ t S|  j t d ƒ t d ƒ | j ƒ n Xt S(   Ns   Failed to fetchs=   Fetching the upgrade failed. There may be a network problem. s   Authentication faileds_   Authenticating the upgrade failed. There may be a problem with the network or with the server. s   Failed to extracts[   Extracting the upgrade failed. There may be a problem with the network or with the server. s   Verification faileds[   Verifying the upgrade failed.  There may be a problem with the network or with the server. s   Can not execute '%s'i   s   Can not run the upgradesy   This usually is caused by a system where /tmp is mounted noexec. Please remount without noexec and run the upgrade again.s   The error message is '%s'.(   R   R|   R   RK   R&   R„   RH   RL   R   t   accessRJ   t   X_OKt   OSErrort   errnoR   R   t   strerrorR   (   R   t   exR:   (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyR/   ð   sD    

		(   t   __name__t
   __module__t   __doc__Ra   RW   R   t   environR   R   R   R   R   R&   R#   RH   RL   R_   Rg   R|   R   R„   R/   (    (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyR   $   s$   					
					&		t   __main__s   got mirror: '%s'sg   http://archive.ubuntu.com/ubuntu/dists/intrepid-proposed/main/dist-upgrader-all/0.93.34/intrepid.tar.gzs    http://archive.ubuntu.com/ubuntu(   t   stringR    R   Ro   RD   R?   Rk   R‚   R   R+   R   RK   t   aptsources.sourceslistR   t   utilsR   R   R   t   objectR   R‹   Rs   t   dR_   (    (    (    sF   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeFetcherCore.pyt   <module>   s   û