
    wch                         d Z ddlZddlZddlmZmZmZmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZmZ ddlmZmZ d	d
ddddddZ ej,                   ej.                  e            ZdeddfdZd Zy)a  
This function is called from lib/upgrade_lts_contract.py and from
lib/reboot_cmds.py

This function should be used after running do-release-upgrade in a machine.
It will detect any contract deltas between the release before
do-release-upgrade and the current release. If we find any differences in
the uaclient contract between those releases, we will apply that difference
in the upgraded release.

For example, suppose we are on Trusty and we are upgrading to Xenial. We found
that the apt url for esm services on trusty:

https://esm.ubuntu.com/ubuntu

While on Xenial, the apt url is:

https://esm.ubuntu.com/infra/ubuntu

This script will detect differences like that and update the Xenial system
to reflect them.
    N)defaults
exceptionsmessagessystemutil)ProgressWrapper)_is_attached)UAConfig)entitlement_factoryentitlements_enable_order)ApplicabilityStatusApplicationStatustrustyxenialbionicfocaljammynobleplucky)r   r   r   r   r   r   questingcfgreturnc                    t         j                  d       t        |       j                  st         j                  d       y t         j                  d       t	        t
        j                         t	        t
        j                         t        dd      5 }t        j                  |j                         t        j                         d d d        t        |       D ]  }	 t        | |d      }j#                         \  }}|j%                         \  }}|t&        j(                  k(  sL|t*        j,                  k(  s`t         j                  d	|       |j/                  t1               
      }|rt         j                  d|        t	        t
        j2                         y # 1 sw Y   xY w# t        j                   $ r t         j                  d|       Y w xY w)Nz%Check whether to upgrade-lts-contractz4Skipping upgrade-lts-contract. Machine is unattachedzStarting upgrade-lts-contract.z/var/lib/apt/lists/lockw )r   namevariantzentitlement not found: %sz!upgrade-lts-contract disabling %s)progressz(upgrade-lts-contract failed disabling %s)LOGdebugr	   is_attachedprintr   RELEASE_UPGRADE_STARTINGRELEASE_UPGRADE_APT_LOCK_WAITopenfcntllockffilenoLOCK_EXr   r   r   EntitlementNotFoundErrorapplication_statusapplicability_statusr   ENABLEDr   INAPPLICABLE_perform_disabler   RELEASE_UPGRADE_SUCCESS)r   lockfiler   entitlementr+   _r,   rets           ?/usr/lib/python3/dist-packages/uaclient/upgrade_lts_contract.py%process_contract_delta_after_apt_lockr6   <   sy   II56((		HIII./	(
+
+,	(
0
01	'	- 6HOO%u}}56 *#. L	9-K !, > > @A"-"B"B"Da "3";";;$(;(H(HH II94@..8I.JC		DdK-L0 
(
*
*+76 6 22 	9II148	9s   3FF+F(+)GGc                  J    t        j                  t        j                         y )N)r   ensure_folder_absentr   ESM_APT_ROOTDIR     r5   remove_private_esm_apt_cacher<   e   s    
 8 89r;   )__doc__r&   logginguaclientr   r   r   r   r   uaclient.apir   (uaclient.api.u.pro.status.is_attached.v1r	   uaclient.configr
   uaclient.entitlementsr   r   (uaclient.entitlements.entitlement_statusr   r   !current_codename_to_past_codename	getLoggerreplace_top_level_logger_name__name__r   r6   r<   r:   r;   r5   <module>rI      s   .   A A ( A $ % ! g:::8DE&,x &,D &,R:r;   