3 ©ft`~ ã @ st d dl mZ d dl mZ d dlZd dlZd dlZd dlmZ d dl m Z d dlmZ ej dƒZG dd „ d ejƒZdS ) é )Úabsolute_import)Úunicode_literalsN)Úcommands)ÚOptionParser)Ú_Údnfc @ sX e Zd ZdZdZedƒZed d „ ƒZdd„ Z d d„ Z dd„ Zdd„ Zdd„ Z dd„ ZdS )ÚUpgradeCommandzTA class containing methods needed by the cli to execute the update command. ÚupgradeÚupdateú upgrade-toú update-toÚlocalupdateÚupz,upgrade a package or packages on your systemc C s" | j ddtdƒtjtdƒd� d S )NZpackagesÚ*zPackage to upgradeZPACKAGE)ÚnargsÚhelpÚactionÚmetavar)Úadd_argumentr r ZParseSpecGroupFileCallback)Úparser© r ú/usr/lib/python3.6/upgrade.pyÚ set_argparser* s zUpgradeCommand.set_argparserc C sZ | j j}d|_d|_d|_d|_tj| j| j ƒ | j j sDtj| jƒ d| _d| _ d| _dS )zÌVerify that conditions are met so that this command can run. These include that there are enabled repositories with gpg keys, and that this command is being run by the root user. TN)ÚcliÚdemandsZsack_activationZavailable_reposZ resolvingZ root_userr Z_checkGPGKeyÚbaseÚoptsÚ filenamesZ_checkEnabledRepoÚupgrade_minimalÚall_securityÚskipped_grp_specs)Úselfr r r r Ú configure0 s zUpgradeCommand.configurec C sœ | j r dnd}| jj| j|| jd� | jjs<| jjs<| jjrzd}|| jƒ O }|| j ƒ O }|| j ƒ O }|| jƒ O }|rˆd S n| jj ƒ d S tjjtdƒƒ‚d S )NÚeqZgte)Úcmp_typeÚallFzNo packages marked for upgrade.)r r Z _populate_update_security_filterr r r Ú pkg_specsÚ grp_specsÚ_update_modulesÚ _update_filesÚ_update_packagesÚ_update_groupsr Zupgrade_allr Ú exceptionsÚErrorr )r! r$ Úresultr r r ÚrunB s zUpgradeCommand.runc C sN t | jjƒ}tjjr6tjjj| jƒ}|j | jjƒ| _ n | jj| _ t | j ƒ|kS )N)Úlenr r' r r ZWITH_MODULESÚmoduleÚmodule_baseZ ModuleBaser r )r! Zgroup_specs_numr2 r r r r( V s zUpgradeCommand._update_modulesc C s� d}| j jrŒx~| jj| j jd| jjjd�D ]^}y| jj|ƒ d}W q* tjj k r† } z$t jtdƒ| jjj j|jƒƒ W Y d d }~X q*X q*W |S )NF)ÚstrictÚprogressTzNo match for argument: %s)r r r Zadd_remote_rpmsÚoutputr4 Zpackage_upgrader r, ÚMarkingErrorÚloggerÚinfor ÚtermÚboldÚlocation)r! ÚsuccessZpkgÚer r r r) ` s *zUpgradeCommand._update_filesc C sr d}xh| j jD ]\}y| jj|ƒ d}W q tjjk rh } z"tjt dƒ| jj jj|ƒƒ W Y d d }~X qX qW |S )NFTzNo match for argument: %s) r r&