
    Uٵg                     h   d dl mZmZmZmZmZmZmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZ  ej0                         Ze
j4                  e
j6                   e
j8                          e
j:                  d      d	efd
                            Zdej@                  de!de!d	efdZ" edejF                  ejH                  eejJ                   e edejL                  jO                  d      d       edejP                  jO                  d      dddgd      g      g      Z)y)    )configdaemonentitlementsevent_logger
exceptionsmessagestimerutil)cli_util)ProArgumentProArgumentGroup
ProCommand)perform_disable)HelpCategory)machine_tokenstate_files)update_motd_messagesz
pro detachreturnc                    t        || j                  | j                  dk(        }|dk(  r(t        j                          t        j                          t        j                          |S )zXPerform the detach action for this machine.

    @return: 0 on success, 1 otherwise
    json)
assume_yesjson_outputr   )	_detachr   formatr   startr	   stopeventprocess_events)argscfgkwargsrets       5/usr/lib/python3/dist-packages/uaclient/cli/detach.pyaction_detachr$      sN     dkkV6KC ax

	J    r    r   r   c                     g }t        j                  |       D ]C  }	 t        j                  | |      }|j                  d      \  }}|s3|j                  |       E |rpt        j                  t        j                  j                  t        |                   |D ]0  }t        j                  dj                  |j                               2 t        j                   |      sy|D ]  }t#        || ||d        t%        j&                  |       }|j)                          t+        j,                          t/        |        t        j                  t        j0                         y	# t        j                  $ r Y dw xY w)
aj  Detach the machine from the active Ubuntu Pro subscription,

    :param cfg: a ``config.UAConfig`` instance
    :param assume_yes: Assume a yes answer to any prompts requested.
         In this case, it means automatically disable any service during
         detach.
    :param json_output: output should be json only

    @return: 0 on success, 1 otherwise
    )r    nameT)ignore_dependent_servicesz    {})r      F)r   r   update_statusr   )r   entitlements_disable_orderentitlement_factoryr   EntitlementNotFoundErrorcan_disableappendr   infor   DETACH_WILL_DISABLE	pluralizelenr   r'   r
   prompt_for_confirmationr   r   get_machine_token_filedeleter   delete_state_filesr   DETACH_SUCCESS)	r    r   r   
to_disableent_nameentr"   _machine_token_files	            r#   r   r   (   sL    J ;;C@ #	22C 4@Qc"#  

8//99#j/JK 	2CJJxsxx01	2'':> 
#!	

 '==cB""$	JJx&&'= 22 		s   E&&E=<E=detachz--assume-yes)command
store_true)helpactionz--formatcli)defaultstorer   )rA   rB   choicesrD   )	arguments)rA   descriptionrB   help_categoryargument_groupsN)*uaclientr   r   r   r   r   r   r	   r
   uaclient.clir   uaclient.cli.commandsr   r   r   uaclient.cli.disabler   uaclient.cli.parserr   uaclient.filesr   r   uaclient.timer.update_messagingr   get_event_loggerr   verify_json_format_argsassert_rootassert_attachedassert_lock_fileintr$   UAConfigboolr   CLI_ROOT_DETACHCLI_DETACH_DESCOTHERCLI_ASSUME_YESr   CLI_FORMAT_DESCdetach_command r%   r#   <module>ra      sM  	 	 	 " K K 0 , 5 @%%%' 
!!	<(S  )   "0 0d 0 0# 0f 		!	!(($$"!00777I'
 !11888G""FO!	
r%   