
Y]
|                 @   s   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 m	 Z	 d d l
 m Z d d l m Z y d  d l m Z Wn( e k
 r Gd d   d e  Z Yn XGd	 d
   d
 e  Z d S)    N)PIPEPopen   )get_arch)gettext)PluginManagerc               @   s(   e  Z d  Z d d   Z d d   Z d S)r   c             O   s   d  S)N )selfargskwsr   r   ?/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeQuirks.py__init__(   s    zPluginManager.__init__c             O   s   g  S)Nr   )r	   r
   r   r   r   r   get_plugins+   s    zPluginManager.get_pluginsN)__name__
__module____qualname__r   r   r   r   r   r   r   '   s   r   c               @   s  e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d d  Z d d   Z d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z d+ d,   Z d- d.   Z d/ d0   Z d1 d2   Z d3 d4   Z d5 d6   Z d7 d8   Z d9 d: d;  Z d< d= d>  Z  d? d@   Z! dA dB   Z" dC dD   Z# dE dF dG  Z$ dH dI   Z% dJ dK   Z& dL dM   Z' dN dO   Z( d< S)PDistUpgradeQuirksz
    This class collects the various quirks handlers that can
    be hooked into to fix/work around issues that the individual
    releases have
    c             C   s   | |  _  | j |  _ | |  _ t d d g d t d d j   d j   |  _ t   |  _	 t
 |  j  d g  |  _ d  |  _ d |  _ i  |  _ d  S)	Nunamez-rstdoutuniversal_newlinesTr   z	./plugins )
controller_viewconfigr   r   communicatestripr   r   archr   plugin_manager_poke_uid	_user_env)r	   r   r   r   r   r   r   6   s    				zDistUpgradeQuirks.__init__c             C   s}  |  j  j r t j d  d S|  j j d d  } |  j j d d  } xc | d | | f d | | f g D]> } x5 |  j j |  D]! } t j d |  | j	   q Wqk Wd	 | } t
 |  | d  } | d k	 r t j d
 |  |   d | | f } t
 |  | d  } | d k	 r3t j d
 |  |   d | | f } t
 |  | d  } | d k	 ryt j d
 |  |   d S)a  
        Run the specific quirks handler, the follow handlers are supported:
        - PreCacheOpen: run *before* the apt cache is opened the first time
                        to set options that affect the cache
        - PostInitialUpdate: run *before* the sources.list is rewritten but
                             after an initial apt-get update
        - PostDistUpgradeCache: run *after* the dist-upgrade was calculated
                                in the cache
        - StartUpgrade: before the first package gets installed (but the
                        download is finished)
        - PostUpgrade: run *after* the upgrade is finished successfully and
                       packages got installed
        - PostCleanup: run *after* the cleanup (orphaned etc) is finished
        z)not running quirks in partialUpgrade modeNZSourcesZToZFromz%s%sz	from_%s%szrunning quirks plugin %sz%szquirks: running %s)r   Z_partialUpgradelogginginfor   getr   r   debugZdo_cleanup_cruftgetattr)r	   Z
quirksNameZ
to_releaseZfrom_releaseZ	conditionZpluginfuncnamefuncr   r   r   runF   s6    
zDistUpgradeQuirks.runc             C   s   t  j d  d S)z3 run before the apt cache is opened the first time zrunning Quirks.PreCacheOpenN)r!   r$   )r	   r   r   r   PreCacheOpen{   s    zDistUpgradeQuirks.PreCacheOpenc             C   s   t  j d  d S)z run after cleanup zrunning Quirks.PostCleanupN)r!   r$   )r	   r   r   r   PostCleanup   s    zDistUpgradeQuirks.PostCleanupc             C   sT   |  j    |  j   |  j   |  j   |  j   |  j   |  j   |  j   d  S)N)_applyPatches_removeOldApportCrashes_killUpdateNotifier_killKBluetooth_killScreensaver_pokeScreensaver_inhibitIdle_stopDocvertConverter)r	   r   r   r   StartUpgrade   s    






zDistUpgradeQuirks.StartUpgradec             C   s   |  j    d S)z]
        this function works around quirks in the
        xenial upgrade calculation
        N)_install_linux_metapackage)r	   r   r   r   xenialPostDistUpgradeCache   s    z,DistUpgradeQuirks.xenialPostDistUpgradeCachec             C   s   t    } y( t j d d g d t j d d } Wn t k
 rI | SYn Xx> | j   d j d  D]# } | rd | j | j   d  qd W| S)	z8 return a set of pci ids of the system (using lspci -n) lspciz-nr   r   Tr   
   )set
subprocessr   r   OSErrorr   splitadd)r	   r6   pliner   r   r   _get_pci_ids   s    		 zDistUpgradeQuirks._get_pci_idsc             C   s   d } t  j j |  s( d t  j k r, d  St j d d d g d t t  j d  } | d k rs t j	 d	  d  St j | g  } t j	 d
 | | f  | d k r |  j
 j t d  t d   } | s |  j j   d  S)Nz/usr/lib/nux/unity_support_testDISPLAYZpsz-Czunity-panel-servicer   wr   z5_test_and_warn_for_unity_3d_support: no unity runningz6_test_and_warn_for_unity_3d_support '%s' returned '%s'zBYour graphics hardware may not be fully supported in Ubuntu 14.04.aS  Running the 'unity' desktop environment is not fully supported by your graphics hardware. You will maybe end up in a very slow environment after the upgrade. Our advice is to keep the LTS version for now. For more information see https://wiki.ubuntu.com/X/Bugs/UpdateManagerWarningForUnity3D Do you still want to continue with the upgrade?)ospathexistsenvironr:   callopendevnullr!   r$   r   askYesNoQuestion_r   abort)r	   ZUNITY_SUPPORT_TESTZreturn_coderesr   r   r   #_test_and_warn_for_unity_3d_support   s(    $			z5DistUpgradeQuirks._test_and_warn_for_unity_3d_supportc             C   st   d d d d d d d g } |  j    } t |  j |  rp |  j j t d  t d	   } | sp |  j j   d  S)
Nz	8086:7121z	8086:7125z	8086:1132z	8086:3577z	8086:2562z	8086:3582z	8086:2572zFYour graphics hardware may not be fully supported in Ubuntu 12.04 LTS.zThe support in Ubuntu 12.04 LTS for your Intel graphics hardware is limited and you may encounter problems after the upgrade. For more information see https://wiki.ubuntu.com/X/Bugs/UpdateManagerWarningForI8xx Do you want to continue with the upgrade?)r@   r9   intersectionr   rJ   rK   r   rL   )r	   ZI8XX_PCI_IDSr6   rM   r   r   r   _test_and_warn_on_i8xx   s    			z(DistUpgradeQuirks._test_and_warn_on_i8xxc             C   s   |  j  d  r |  j d  r |  j j t d  t d   } | sS |  j j   d d d d d d	 g } t j d
 d j	 |   |  j j
 j d d  } x | D] } | j |  q W|  j j
 j d d d j	 |   d S)zi
        Some cards are no longer supported by fglrx. Check if that
        is the case and warn
        ZfglrxzhUpgrading may reduce desktop effects, and performance in games and other graphically intensive programs.zThis computer is currently using the AMD 'fglrx' graphics driver. No version of this driver is available that works with your hardware in Ubuntu 10.04 LTS.

Do you want to continue?zxorg-driver-fglrxzxorg-driver-fglrx-envyzfglrx-kernel-sourcezfglrx-amdccclezxorg-driver-fglrx-devZlibamdxvba1z	remove %sz, ZDistroZPostUpgradePurge,N)_checkVideoDriver_supportInModaliasesr   rJ   rK   r   rL   r!   r$   joinr   Zgetlistappendr9   )r	   rM   Zremovalslremover   r   r   '_test_and_warn_on_dropped_fglrx_support   s&    			z9DistUpgradeQuirks._test_and_warn_on_dropped_fglrx_supportc             C   sq   |  j  d k rm t j d  |  j   sm t j d  t d  } t d  } |  j j | |  |  j j   d S)z
        Test and fail if the cpu is not i686 or more or if its a newer
        CPU but does not have the cmov feature (LP: #587186)
        i386zchecking for i586 CPUznot a i686 or no cmovzNo i686 CPUzYour system uses an i586 CPU or a CPU that does not have the 'cmov' extension. All packages were built with optimizations requiring i686 as the minimal architecture. It is not possible to upgrade your system to a new Ubuntu release with this hardware.N)	r   r!   r$   _cpu_is_i686_and_has_cmoverrorrK   r   r   rL   )r	   summarymsgr   r   r   _test_and_fail_on_non_i686  s    z,DistUpgradeQuirks._test_and_fail_on_non_i686z/proc/cpuinfoc             C   s   t  j j |  s' t j d |  d St |   } | j   } Wd  QRXt j d | t j	  rr t j
 d  d St j d | t j	  } | r d | j d  j   k r t j
 d	 | j d   t j
 d
  d Sd S)Nzcannot open %s ?!?Tz^cpu family\s*:\s*[345]\s*z found cpu family [345], no i686+Fz^flags\s*:\s*(.*)Zcmovr   zfound flags '%s'zcan not find cmov in flags)rC   rD   rE   r!   r[   rH   readresearch	MULTILINEr$   groupr<   )r	   Zcpuinfo_pathfcpuinfomatchr   r   r   rZ     s    z+DistUpgradeQuirks._cpu_is_i686_and_has_cmovc             C   sK   |  j  d k rG |  j   sG |  j j t d  t d   |  j j   d S)z~
        Test and fail if the cpu is not a arm v6 or greater,
        from 9.10 on we do no longer support those CPUs
        ZarmelzNo ARMv6 CPUzYour system uses an ARM CPU that is older than the ARMv6 architecture. All packages in karmic were built with optimizations requiring ARMv6 as the minimal architecture. It is not possible to upgrade your system to a new Ubuntu release with this hardware.N)r   _checkArmCPUr   r[   rK   r   rL   )r	   r   r   r   _test_and_fail_on_non_arm_v6,  s    		z.DistUpgradeQuirks._test_and_fail_on_non_arm_v6c          
   C   sq   y t  j d d  WnV t j d  |  j j t d  t d   } | s[ |  j j   |  j j	   Yn Xd S)zd
        upstart and vserver environments are not a good match, warn
        if we find one
        r   r   zno init foundzNo init availablea  Your system appears to be a virtualised environment without an init daemon, e.g. Linux-VServer. Ubuntu 10.04 LTS cannot function within this type of environment, requiring an update to your virtual machine configuration first.

Are you sure you want to continue?N)
rC   killr!   warningr   rJ   rK   r   rL   ZprocessEvents)r	   rM   r   r   r   _test_and_warn_if_vserver>  s    		z+DistUpgradeQuirks._test_and_warn_if_vserverc             C   sr   t  j d  t j j d  s0 t  j d  d St d   } | j   } Wd QRXt j	 d | t j
  rn d Sd S)zE
        parse /proc/cpuinfo and search for ARMv6 or greater
        zchecking for ARM CPU versionz/proc/cpuinfozcannot open /proc/cpuinfo ?!?FNz^Processor\s*:\s*ARMv[45]T)r!   r$   rC   rD   rE   r[   rH   r_   r`   ra   rb   )r	   rd   re   r   r   r   rg   T  s    zDistUpgradeQuirks._checkArmCPUc             C   s6   t  j j d  r2 t j d  t j d d g  d S)z, /etc/init.d/apparmor stop (see bug #559433)z/etc/init.d/apparmorz/etc/init.d/apparmor stopstopN)rC   rD   rE   r!   r$   r:   rG   )r	   r   r   r   _stopApparmorc  s    zDistUpgradeQuirks._stopApparmorc             C   s6   t  j j d  r2 t j d  t j d d g  d S)z5 /etc/init.d/docvert-converter stop (see bug #450569)z/etc/init.d/docvert-converterz"/etc/init.d/docvert-converter stoprl   N)rC   rD   rE   r!   r$   r:   rG   )r	   r   r   r   r2   i  s    z'DistUpgradeQuirks._stopDocvertConverterc             C   s9   t  j j d  r5 t j d  t j d d d g  d S)zkill update-notifierz/usr/bin/killallzkilling update-notifierkillallz-qzupdate-notifierN)rC   rD   rE   r!   r$   r:   rG   )r	   r   r   r   r-   o  s    z%DistUpgradeQuirks._killUpdateNotifierc             C   s<   t  j j d  r8 t j d  t j d d d d g  d S)z3killall kblueplugd kbluetooth (riddel requested it)z/usr/bin/killallzkilling kblueplugd kbluetooth4rn   z-qZ
kblueplugdZkbluetooth4N)rC   rD   rE   r!   r$   r:   rG   )r	   r   r   r   r.   v  s    z!DistUpgradeQuirks._killKBluetoothc             C   s9   t  j j d  r5 t j d  t j d d d g  d S)zkillall gnome-screensaver z/usr/bin/killallzkilling gnome-screensaverrn   z-qzgnome-screensaverN)rC   rD   rE   r!   r$   r:   rG   )r	   r   r   r   r/   |  s    z"DistUpgradeQuirks._killScreensaverc          
   C   s   t  j j d  r t  j j d  r t j d  d } | d 7} | d 7} y, t j | d d |  _	 t
 j |  j  Wn t j d	  Yn Xd  S)
Nz/usr/bin/xdg-screensaverrA   z#setup poke timer for the scrensaverzwhile true;z3 do /usr/bin/xdg-screensaver reset >/dev/null 2>&1;z sleep 30; doneshellTz failed to setup screensaver poke)rC   rD   rE   rF   r#   r!   r$   r:   r   r   atexitregister_stopPokeScreensaver	exception)r	   cmdr   r   r   r0     s    

z"DistUpgradeQuirks._pokeScreensaverc             C   s  y t  j d d |  j d g  } | j   j d  d } t d | d d   } | j   j d	  } Wd  QRXxA | D]9 } t |  rw | j d
 d  } | d |  j | d <qw WWnT t  j	 k
 r} z1 | j
 d k r t j d  n t j d  WYd  d  } ~ Xn Xd  S)NZpgrepz-uzgnome-sessionr7   r   z/proc/z/environr =r   z"gnome-session not running for userzfailed to read user env)r:   Zcheck_outputr   decoder<   rH   r_   lenr    ZCalledProcessError
returncoder!   r$   rs   )r	   pidrd   datar?   enver   r   r   _getUserEnv  s    zDistUpgradeQuirks._getUserEnvc             C   sx  t  j j d  rtt  j j d d  |  _ |  j sK t  j j d d  |  _ |  j sr t j d  t j d  d  S|  j	   |  j
 s d  St  j t |  j   t j d  y |  j
 j d d  } | s t j d	  t j d  d  S| j d
  } t j d d d d g d |  j
 } x* | D]" } d | k r"t j | j  q"WWn t j d  Yn Xt  j t  j    d  S)Nz/usr/bin/gnome-session-inhibitZSUDO_UIDr   Z
PKEXEC_UIDz"failed to determine user upgradingz$failed to inhibit gnome-session idlezinhibit gnome-session idleZXDG_CURRENT_DESKTOPz"failed to find XDG_CURRENT_DESKTOP:zgnome-session-inhibitz	--inhibitidlez--inhibit-onlyr}   ZGNOME)rC   rD   rE   rF   r#   r   r!   r$   r[   r   r    seteuidintr<   r:   r   rp   rq   	terminaters   getuid)r	   Zxdg_desktopr   Zdesktopr   r   r   r1     s:    		
	zDistUpgradeQuirks._inhibitIdlec          	   C   sZ   d } |  j  d  k	 rV y  |  j  j   |  j  j   } Wn t j d  Yn Xd  |  _  | S)NFzfailed to stop screensaver poke)r   r   waitr!   rs   )r	   rM   r   r   r   rr     s    	z&DistUpgradeQuirks._stopPokeScreensaverc             C   s   y` xY d d d g D]H } x? t  j  d |  D]* } t j d | | f  t j |  q- Wq WWn6 t k
 r } z t j d |  WYd d } ~ Xn Xd S)z: remove old apport crash files and whoopsie control files z.crashz.uploadz	.uploadedz/var/crash/*%szremoving old %s file '%s'z+error during unlink of old crash files (%s)N)globr!   r$   rC   unlink	Exceptionrj   )r	   Zextrd   r~   r   r   r   r,     s    z)DistUpgradeQuirks._removeOldApportCrashesc             C   s   t  j d  d } t d   } | j   } Wd QRXt j d | t j  rS d } | s t  j d  t d  } t d	  } |  j	 j | |  |  j
 j   d S)
z check PAE in /proc/cpuinfo 	_checkPaer   z/proc/cpuinfoNz^flags\s+:.* pae r   zno pae in /proc/cpuinfozPAE not enabledzYour system uses a CPU that does not have PAE enabled. Ubuntu only supports non-PAE systems up to Ubuntu 12.04. To upgrade to a later version of Ubuntu, you must enable PAE (if this is possible) see:
http://help.ubuntu.com/community/EnablingPAE)r!   r$   rH   r_   r`   ra   rb   r[   rK   r   r   rL   )r	   Zpaerd   re   r\   r]   r   r   r   r     s    zDistUpgradeQuirks._checkPaec             C   s   d } t  j j |  s d St |   } | j   } Wd QRXxS | D]K } | j d  d j   } | j   j d  rE | j	 d |  rE d SqE Wd S)	z2 check if the given driver is in use in xorg.conf z/etc/X11/xorg.confFN#r   Zdriverz"%s"T)
rC   rD   rE   rH   	readlinesr<   r   lower
startswithendswith)r	   nameZXORGrd   linesr?   sr   r   r   rR     s    z#DistUpgradeQuirks._checkVideoDriverz	./patchesc       
      C   s  t  j j |  s# t j d  d Sxt  j |  D]} d | k rY t j d |  q3 t j d |  | j d d  \ } } } | j d d  } t j d	 | | | f  t  j j |  s t j d
 |  q3 t j	   } t
 | d   } | j | j    Wd QRX| j   | k r8t j d |  q3 n& | j   | k r^t j d |  q3 d d l m }	 y4 |	 | t  j j | |  |  t j d |  Wq3 t k
 rt j d |  Yq3 Xq3 Wd S)z
        helper that applies the patches in patchdir. the format is
        _path_to_file.md5sum and it will apply the diff to that file if the
        md5sum matches
        zno patchdirN.zskipping '%s' (no '.')z'check if patch '%s' needs to be appliedr8   rK   /ztarget for '%s' is '%s' -> '%s'ztarget '%s' does not existrbz%already at target hash, skipping '%s'z(unexpected target md5sum, skipping: '%s'r   )patchzapplied '%s' successfullyzed failed for '%s')rC   rD   rE   r!   r$   listdirrsplitreplacehashlibmd5rH   updater_   Z	hexdigestrj   ZDistUpgradePatcherr   rT   r"   r   rs   )
r	   Zpatchdirrd   Zencoded_pathZmd5sumZresult_md5sumrD   r   fdr   r   r   r   r+     s>    		zDistUpgradeQuirks._applyPatchesNc       	      C   s  | s |  j    } | |  j j k s8 |  j j | j rI t j d  d S|  j j | } x |  j | j j  D]~ \ } } xo | D]g } t j	 d |  } | r d | j
 d  | j
 d  f } | j   | k r t j d |  d Sq Wqo Wt j d	 |  d S)
z
        Check if pkgname will work on this hardware

        This helper will check with the modaliasesdir if the given
        pkg will work on this hardware (or the hardware given
        via the lspci argument)
        zcan not find '%s' in cacheFzpci:v0000(.+)d0000(.+)sv.*z%s:%sr   r8   z%found system pciid '%s' in modaliasesTz4checking for %s support in modaliases but none found)r@   r   cache	candidater!   rj   !_parse_modaliases_from_pkg_headerrecordr`   rf   rc   r   r$   )	r	   Zpkgnamer6   pkgmoduleZ
pciid_listZpciidmZmatchidr   r   r   rS   *  s(    	"		z&DistUpgradeQuirks._supportInModaliasesc             C   s   d | k r g  Sg  } xq | d j  d  D]\ } | j d  } | sH q* | j  d  \ } } | j | d d   | j  d  D f  q* W| S)z. return a list of (module1, (pciid, ...), ...)Z
Modaliases)z, (c             S   s   g  |  ] } | j     q Sr   )r   ).0xr   r   r   
<listcomp>T  s   	 zGDistUpgradeQuirks._parse_modaliases_from_pkg_header.<locals>.<listcomp>rQ   )r<   r   rU   )r	   Z	pkgrecordmodulesr   r   Zpciidsr   r   r   r   I  s    -z3DistUpgradeQuirks._parse_modaliases_from_pkg_headerc             C   s  t  j d  |  j j } d | k r6 t  j d  d  S| d j pM | d j sa t  j d  d  Sy d d  l } | j j   } xd | D]# } d | j	 k r t  j d  Pq Wt  j
 d  | j d	 d
 |  j j d g d  | j   Wn t  j d  Yn Xd  S)N_add_extras_repositoryzubuntu-extras-keyringz-no ubuntu-extras-keyring, no need to add repoz2ubuntu-extras-keyring not installed/marked_installr   zextras.ubuntu.comz*found extras.ubuntu.com, no need to add itz/no extras.ubuntu.com, adding it to sources.listZdebzhttp://extras.ubuntu.com/ubuntumainz!Third party developers repositoryzerror adding extras.ubuntu.com)r!   r$   r   r   marked_installZ	installedZaptsources.sourceslistZsourceslistZSourcesListZurir"   r=   ZtoDistZsavers   )r	   r   Z
aptsourcesZsourcesentryr   r   r   r   W  s.    z(DistUpgradeQuirks._add_extras_repositoryc          	   C   sn   yR |  j  j } d | k rQ | d j rQ d | k rQ t j d  | j d d  Wn t j d  Yn Xd S)z foomatic-db-gutenprint get removed during the upgrade,
            replace it with the compressed ijsgutenprint-ppds
            (context is foomatic-db vs foomatic-db-compressed-ppds)
        zfoomatic-db-gutenprintzijsgutenprint-ppdszinstalling ijsgutenprint-ppdsz1foomatic-db-gutenprint -> ijsgutenprint-ppds rulez_gutenprint_fixup failedN)r   r   Zmarked_deleter!   r"   mark_installrs   )r	   r   r   r   r   _gutenprint_fixupq  s    z#DistUpgradeQuirks._gutenprint_fixuprY   c             C   sl   d } t  j j |  sh y t  j d  Wn t k
 r= Yn Xt | d   } | j d |  Wd QRXd S)z5 enable multiarch via /etc/dpkg/dpkg.cfg.d/multiarch z/etc/dpkg/dpkg.cfg.d/multiarchz/etc/dpkg/dpkg.cfg.d/rB   zforeign-architecture %s
N)rC   rD   rE   makedirsr;   rH   write)r	   Zforeign_archZcfgrd   r   r   r   _enable_multiarch  s    z#DistUpgradeQuirks._enable_multiarchc             C   s   t  j d  } | j |  } | j |  } | rw d | j d  | j d  f } d | j d  | j d  f } t j d | | f  t j j | |  d k S)z# copied from ubuntu-drivers common z(.+)-([0-9]+)-(.+)z%s-%sr   r8   zComparing %s with %sr   )	r`   compilerf   rc   r!   r$   aptapt_pkgZversion_compare)r	   Zterm1Zterm2patternZmatch1Zmatch2r   r   r   _is_greater_than  s    z"DistUpgradeQuirks._is_greater_thanc             C   sE  | r d p d } t  j d  } t  j d  } d } d } x| D] } d | j k rC d | j k rC | j sy | j rC | j | j  }	 |	 rC | j j d }
 d |	 j d	  |	 j d
  f } |  j	 | |  rC | } | j |
  } d |
 k r$| r$d | |	 j d  | j d	  f } qC d | |	 j d  f } qC W| S)zb Get the linux headers or linux metapackage
            copied from ubuntu-drivers-common
        z-headersr   zlinux-image-(.+)-([0-9]+)-(.+)z
linux-(.+)zlinux-imageZextraZSourcez%s-%sr   r8   z-lts-zlinux%s-%s-%s   z
linux%s-%s)
r`   r   r   is_installedr   rf   r   r   rc   r   )r	   r   Zheaderssuffixr   Zsource_patternZmetapackageversionr   rf   sourceZcurrent_versionZmatch_sourcer   r   r   _get_linux_metapackage  s4    			z(DistUpgradeQuirks._get_linux_metapackagec             C   sw   |  j  j } |  j | d  } | | k r? t j d |  d S| | j ss t j d |  d } | j | |  d S)zo Ensure the linux metapackage is installed for the newest_kernel
            installed. (LP: #1509305)
        Fz$linux metapackage (%s) not availableNz installing linux metapackage: %sz8linux metapackage may have been accidentally uninstalled)r   r   r   r!   r"   r   r   )r	   r   Zlinux_metapackagereasonr   r   r   r4     s    		z,DistUpgradeQuirks._install_linux_metapackagec             C   sX   |  j  j sT t j j j d  sT d } | d 7} t j |  t j j j d d  d S)z] ensure that on a desktop install recommends are installed
            (LP: #759262)
        zApt::Install-Recommendsz%Apt::Install-Recommends was disabled,z! enabling it just for the upgrade1N)	r   Z
serverModer   r   r   Zfind_br!   rj   r9   )r	   r]   r   r   r   +ensure_recommends_are_installed_on_desktops  s    
z=DistUpgradeQuirks.ensure_recommends_are_installed_on_desktops))r   r   r   __doc__r   r(   r)   r*   r3   r5   r@   rN   rP   rX   r^   rZ   rh   rk   rg   rm   r2   r-   r.   r/   r0   r   r1   rr   r,   r   rR   r+   rS   r   r   r   r   r   r   r4   r   r   r   r   r   r   /   sL   5
!'#
/0r   )r   rp   r   r!   rC   r`   r   r:   r   r   Zutilsr   ZDistUpgradeGettextr   rK   Zjanitor.plugincore.managerr   ImportErrorobjectr   r   r   r   r   <module>   s   