+eTq@sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z m Z ddlmZddlmZddlmZGdd d eZdS) )absolute_importN)PIPEPopen)get_arch)gettext) PluginManagerc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFdGZ%dHdIdJZ&dKdLZ'dMdNZ(dOdPZ)dQdRdSZ*dTdUZ+dVdWZ,dHS)XDistUpgradeQuirksz This class collects the various quirks handlers that can be hooked into to fix/work around issues that the individual releases have cCs||_|j|_||_tddgdtddjdj|_t|_ t |jdg|_ d|_ dS)Nunamez-rstdoutuniversal_newlinesTrz ./plugins) controller_viewconfigrr communicatestripr rarchrplugin_manager_poke)selfr rr?/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeQuirks.py__init__1s    zDistUpgradeQuirks.__init__cCs|jjrtjddS|jjdd}|jjdd}xc|d||fd||fgD]>}x5|jj|D]!}tjd||j qWqkWd |}t ||d}|dk rtjd ||nd||f}t ||d}|dk r9tjd ||nd||f}t ||d}|dk rtjd ||ndS) 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 a 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 modeNZSourcesZToZFromz%s%sz from_%s%szrunning quirks plugin %sz%szquirks: running %s) r Z_partialUpgradelogginginforgetrZ get_pluginsdebugZdo_cleanup_cruftgetattr)rZ quirksNameZ to_releaseZ from_releaseZ conditionZpluginZfuncnamefuncrrrrun?s6         zDistUpgradeQuirks.runcCstjddS)z3 run before the apt cache is opened the first time zrunning Quirks.PreCacheOpenN)rr)rrrr PreCacheOpentszDistUpgradeQuirks.PreCacheOpencCsntjdtjjjddkrjtjdtjjjddtjjjdtd ndS) Nz"running Quirks.oneiricPreCacheOpenzApt::Architectureamd64z5multiarch: enabling i386 as a additional architecturezApt::Architectures::i386zAPT::Cache-Start0iii)rraptapt_pkgrfindsetstr)rrrroneiricPreCacheOpenxs  z%DistUpgradeQuirks.oneiricPreCacheOpencCstjddS)z run after cleanup zrunning Quirks.PostCleanupN)rr)rrrr PostCleanupszDistUpgradeQuirks.PostCleanupcCs5tjdtjjj|j|jdS)z Quirks that are run before the sources.list is updated to the new distribution when upgrading from a lucid system (either to maverick or the new LTS) z running %sN)rrsys _getframef_codeco_name_test_and_fail_on_non_i686_test_and_warn_on_i8xx)rrrrfrom_lucidPostInitialUpdates z-DistUpgradeQuirks.from_lucidPostInitialUpdatecCs*|jdkr|jn|jdS)Nr"r!)zi386zamd64)r _checkPae#_test_and_warn_for_unity_3d_support)rrrrfrom_precisePostInitialUpdates z/DistUpgradeQuirks.from_precisePostInitialUpdatecCs|jdS)N)r0)rrrroneiricPostInitialUpdatesz*DistUpgradeQuirks.oneiricPostInitialUpdatecCs?tjdtjjj|j|j|jdS)zA quirks that are run before the sources.list is updated to lucid z running %sN) rrr+r,r-r._test_and_fail_on_non_arm_v6_test_and_warn_if_vserver'_test_and_warn_on_dropped_fglrx_support)rrrrlucidPostInitialUpdates  z(DistUpgradeQuirks.lucidPostInitialUpdatecCs|jdS)zn this function works around quirks in the maverick -> natty cache upgrade calculation N)%_add_kdegames_card_extra_if_installed)rrrrnattyPostDistUpgradeCachesz+DistUpgradeQuirks.nattyPostDistUpgradeCachecCs|j|jdS)zf this function works around quirks in the lucid->maverick upgrade calculation N)_add_extras_repository_gutenprint_fixup)rrrrmaverickPostDistUpgradeCaches z.DistUpgradeQuirks.maverickPostDistUpgradeCachecCsJ|j|j|j|j|j|j|jdS)N) _applyPatches_removeOldApportCrashes_killUpdateNotifier_killKBluetooth_killScreensaver_pokeScreensaver_stopDocvertConverter)rrrr StartUpgrades      zDistUpgradeQuirks.StartUpgradecCstjdtjjdrtjjd rd}tjj|sZtj|ntjd|tjd|tjtjj |ddnt j j j dd kr|jd d ndS) Nzoneiric StartUpgrade quirksz/usr/sbin/update-grubz%/etc/kernel/postinst.d/zz-update-grubz/etc/kernel/postinst.dzcopying zz-update-grub into %szzz-update-grubizApt::Architecturer! foreign_archr")rrospathexistsmakedirsshutilcopychmodjoinr$r%rr&_enable_multiarch)rZ targetdirrrroneiricStartUpgrades "z%DistUpgradeQuirks.oneiricStartUpgradecCstjd|jdS)Nzfrom_hardyStartUpgrade quirks)rr _stopApparmor)rrrrfrom_hardyStartUpgrades z(DistUpgradeQuirks.from_hardyStartUpgradec Cst}y(tjddgdtjdd}Wntk rI|SYnXxA|jdjdD]&}|rd|j|jdqdqdW|S) z8 return a set of pci ids of the system (using lspci -n) lspciz-nr r Tr )r' subprocessrrOSErrorrsplitadd)rrTplinerrr _get_pci_idss     zDistUpgradeQuirks._get_pci_idscCsd}tjj| s(dtjkr,dStjdddgdttjd}|dkrstj d dStj|g}tj d ||f|dkr|j j t d t d }|s|j jqndS) Nz/usr/lib/nux/unity_support_testDISPLAYZpsz-Czunity-panel-servicer wrz5_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.aSRunning 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?)rHrIrJenvironrWcallopendevnullrrraskYesNoQuestion_r abort)rZUNITY_SUPPORT_TESTZ return_coderesrrrr3s($     z5DistUpgradeQuirks._test_and_warn_for_unity_3d_supportcCszdddddddg}|j}t|j|rv|jjtdtd }|sv|jjqvndS) 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]r' intersectionrrdrer rf)rZ I8XX_PCI_IDSrTrgrrrr0s    z(DistUpgradeQuirks._test_and_warn_on_i8xxcCs|jdr|jd r|jjtdtd}|sV|jjndddddd g}tjd d j ||jj j d d }x|D]}|j |qW|jj j d d dj |ndS)zi Some cards are no longer supported by fglrx. Check if that is the case and warn ZfglrxzhUpgrading 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?zxorg-driver-fglrxzxorg-driver-fglrx-envyzfglrx-kernel-sourcezfglrx-amdccclezxorg-driver-fglrx-devZ libamdxvba1z remove %sz, ZDistroZPostUpgradePurge,N)_checkVideoDriver_supportInModaliasesrrdrer rfrrrOrZgetlistappendr')rrgZremovalslremoverrrr8s&    z9DistUpgradeQuirks._test_and_warn_on_dropped_fglrx_supportcCsw|jdkrstjd|jsstjdtd}td}|jj|||jjqsndS)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) r"zchecking for i586 CPUznot 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) rrr_cpu_is_i686_and_has_cmoverrorrerr rf)rsummarymsgrrrr/Es     z,DistUpgradeQuirks._test_and_fail_on_non_i686z /proc/cpuinfocCstjj|s'tjd|dSt|j}tjd|tj rbtj ddStjd|tj }|rd|j dj krtj d |j dtj d dSndS) Nzcannot open %s ?!?Tz^cpu family\s*:\s*[345]\s*z found cpu family [345], no i686+Fz^flags\s*:\s*(.*)Zcmovrzfound flags '%s'zcan not find cmov in flags) rHrIrJrrprbreadresearch MULTILINErgrouprY)rZ cpuinfo_pathcpuinfomatchrrrroZs  z+DistUpgradeQuirks._cpu_is_i686_and_has_cmovcCsQ|jdkrM|jsM|jjtdtd|jjqMndS)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 Zarmelz 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 _checkArmCPUrrprer rf)rrrrr6ls     z.DistUpgradeQuirks._test_and_fail_on_non_arm_v6c CstytjddWnYtjd|jjtdtd}|s^|jjn|jj YnXdS)zd upstart and vserver environments are not a good match, warn if we find one rrz no init foundzNo init availableaYour 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) rHkillrwarnrrdrer rfZ processEvents)rrgrrrr7~s   z+DistUpgradeQuirks._test_and_warn_if_vservercCsbtjdtjjds0tjddStd}tjd|j tj r^dSdS)zE parse /proc/cpuinfo and search for ARMv6 or greater zchecking for ARM CPU versionz /proc/cpuinfozcannot open /proc/cpuinfo ?!?Fz^Processor\s*:\s*ARMv[45]T) rrrHrIrJrprbrtrursrv)rrxrrrrzs    zDistUpgradeQuirks._checkArmCPUcCs9tjjdr5tjdtjddgndS)z, /etc/init.d/apparmor stop (see bug #559433)z/etc/init.d/apparmorz/etc/init.d/apparmor stopstopN)rHrIrJrrrWra)rrrrrRs zDistUpgradeQuirks._stopApparmorcCs9tjjdr5tjdtjddgndS)z5 /etc/init.d/docvert-converter stop (see bug #450569)z/etc/init.d/docvert-converterz"/etc/init.d/docvert-converter stopr}N)rHrIrJrrrWra)rrrrrEs z'DistUpgradeQuirks._stopDocvertConvertercCs<tjjdr8tjdtjdddgndS)zkill update-notifierz/usr/bin/killallzkilling update-notifierkillallz-qzupdate-notifierN)rHrIrJrrrWra)rrrrrAs z%DistUpgradeQuirks._killUpdateNotifiercCs?tjjdr;tjdtjddddgndS)z3killall kblueplugd kbluetooth (riddel requested it)z/usr/bin/killallzkilling kblueplugd kbluetooth4r~z-qZ kblueplugdZ kbluetooth4N)rHrIrJrrrWra)rrrrrBs z!DistUpgradeQuirks._killKBluetoothcCs<tjjdr8tjdtjdddgndS)zkillall gnome-screensaver z/usr/bin/killallzkilling gnome-screensaverr~z-qzgnome-screensaverN)rHrIrJrrrWra)rrrrrCs z"DistUpgradeQuirks._killScreensaverc Cstjjdrtjjdrtjdd}|d7}|d7}y,tj|dd|_ t j |j Wqtj d YqXndS) Nz/usr/bin/xdg-screensaverr^z#setup poke timer for the scrensaverz while true;z3 do /usr/bin/xdg-screensaver reset >/dev/null 2>&1;z sleep 30; doneshellTz failed to setup screensaver poke)rHrIrJr`rrrrWrratexitregister_stopPokeScreensaver exception)rcmdrrrrDs   z"DistUpgradeQuirks._pokeScreensaverc Cs]d}|jdk rYy |jj|jj}WntjdYnXd|_n|S)NFzfailed to stop screensaver poke)rZ terminatewaitrr)rrgrrrrs  z&DistUpgradeQuirks._stopPokeScreensavercCsy`xYdddgD]H}x?tjd|D]*}tjd||ftj|q-WqWWn6tk r}ztjd|WYdd}~XnXdS)z: remove old apport crash files and whoopsie control files z.crashz.uploadz .uploadedz/var/crash/*%szremoving old %s file '%s'z+error during unlink of old crash files (%s)N)globrrrHunlink ExceptionZwarning)rZextferrrr@sz)DistUpgradeQuirks._removeOldApportCrashescCstjdd}tdj}tjd|tjrFd}n|stjdtd}td}|j j|||j j nd S) z check PAE in /proc/cpuinfo r2rz /proc/cpuinfoz^flags\s+:.* pae rzno pae in /proc/cpuinfozPAE 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/EnablingPAEN) rrrbrsrtrurvrprerr rf)rZpaerxrqrrrrrr2s     zDistUpgradeQuirks._checkPaecCs|d}tjj|sdSxYt|D]K}|jddj}|jjdr)|jd|r)dSq)WdS)z2 check if the given driver is in use in xorg.conf z/etc/X11/xorg.confF#rZdriverz"%s"T) rHrIrJrbrYrlower startswithendswith)rnameZXORGr\srrrrjsz#DistUpgradeQuirks._checkVideoDriverz ./patchesc Cstjj|s#tjddSxtj|D]}d|kr\tjd|q3ntjd||jdd\}}}|jdd}tjd |||ftjj|stjd |q3ntj }t |d }|j |j WdQX|j |kr=tjd |q3n)|j |krftjd |q3nddlm} y4| |tjj|||tjd|Wq3tk rtjd|Yq3Xq3WdS)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.zskipping '%s' (no '.')z'check if patch '%s' needs to be appliedrVre/ztarget for '%s' is '%s' -> '%s'ztarget '%s' does not existrbz%already at target hash, skipping '%s'z(unexpected target md5sum, skipping: '%s'r)patchzapplied '%s' successfullyzed failed for '%s')rHrIrJrrlistdirrsplitreplacehashlibmd5rbupdatersZ hexdigestr|ZDistUpgradePatcherrrOrrr) rZpatchdirrZ encoded_pathZmd5sumZ result_md5sumrIrfdrrrrr?s<     zDistUpgradeQuirks._applyPatchesNc Cs |s|j}n||jjks;|jj|j rLtjddS|jj|}x|j|jjD]\}}xr|D]j}tj d|}|rd|j d|j df}|j |krtj d|dSqqWqrWtj d |dS) 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) zcan not find '%s' in cacheFzpci:v0000(.+)d0000(.+)sv.*z%s:%srrVz%found system pciid '%s' in modaliasesTz4checking for %s support in modaliases but none found) r]r cache candidaterr|!_parse_modaliases_from_pkg_headerrecordrtryrwrr) rZpkgnamerTpkgmoduleZ pciid_listZpciidmZmatchidrrrrk1s(   "  z&DistUpgradeQuirks._supportInModaliasescCsd|krgSg}xt|djdD]_}|jd}|sKq*n|jd\}}|j|dd|jdDfq*W|S)z. return a list of (module1, (pciid, ...), ...)Z Modaliases)z, (cSsg|]}|jqSr)r).0xrrr [s zGDistUpgradeQuirks._parse_modaliases_from_pkg_header..ri)rYrrl)rZ pkgrecordmodulesrrZpciidsrrrrPs -z3DistUpgradeQuirks._parse_modaliases_from_pkg_headerc Cstjd|jj}d|kr6tjddS|djpM|djsatjddSyddl}|jj}xg|D]&}d|j krtjdPqqWtj d|j d d |jj d gd |j Wntjd YnXdS)Nr<zubuntu-extras-keyringz-no ubuntu-extras-keyring, no need to add repoz2ubuntu-extras-keyring not installed/marked_installrzextras.ubuntu.comz*found extras.ubuntu.com, no need to add itz/no extras.ubuntu.com, adding it to sources.listZdebzhttp://extras.ubuntu.com/ubuntumainz!Third party developers repositoryzerror adding extras.ubuntu.com)rrr rmarked_installZ installedZaptsources.sourceslistZ sourceslistZ SourcesListZurirrZZtoDistZsaver)rrZ aptsourcesZsourcesentryrrrr<^s.            z(DistUpgradeQuirks._add_extras_repositoryc CsqyU|jj}d|krT|djrTd|krTtjd|jddnWntjdYnXdS)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) zfoomatic-db-gutenprintzijsgutenprint-ppdszinstalling ijsgutenprint-ppdsz1foomatic-db-gutenprint -> ijsgutenprint-ppds rulez_gutenprint_fixup failedN)r rZ marked_deleterr mark_installr)rrrrrr=xs     z#DistUpgradeQuirks._gutenprint_fixupr"c Cs_d}tjj|s[ytjdWntk r=YnXt|djd|ndS)z5 enable multiarch via /etc/dpkg/dpkg.cfg.d/multiarch z/etc/dpkg/dpkg.cfg.d/multiarchz/etc/dpkg/dpkg.cfg.d/r_zforeign-architecture %s N)rHrIrJrKrXrbwrite)rrGZcfgrrrrPs z#DistUpgradeQuirks._enable_multiarchc CsuyY|jj}d|kp$d|ks+dS|djsE|djrX|jddnWntjdYnXdS)z test if kdegames-card-data is installed and if so, add kdegames-card-data-extra so that users do not loose functionality (LP: #745396) zkdegames-card-datazkdegames-card-data-extraNz,kdegames-card-data -> k-c-d-extra transitionz,_add_kdegames_card_extra_if_installed failed)r rZ is_installedrrrr)rrrrrr:s     z7DistUpgradeQuirks._add_kdegames_card_extra_if_installedcCsjddl}|jjsf|jjjdsfd}|d7}tj||jjjddqfndS)z] ensure that on a desktop install recommends are installed (LP: #759262) rNzApt::Install-Recommendsz%Apt::Install-Recommends was disabled,z! enabling it just for the upgrade1) r$r Z serverModer%rZfind_brr|r')rr$rrrrr+ensure_recommends_are_installed_on_desktopss    z=DistUpgradeQuirks.ensure_recommends_are_installed_on_desktops)-__name__ __module__ __qualname____doc__rrr r)r*r1r4r5r9r;r>rFrQrSr]r3r0r8r/ror6r7rzrRrErArBrCrDrr@r2rjr?rkrr<r=rPr:rrrrrr *sT   5         !  '           .    r )Z __future__rr$rrrrHrtrrLr+rWrrZutilsrZDistUpgradeGettextrreZjanitor.plugincore.managerrobjectr rrrrs