o
    (f                     @   s&  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 Ze
je
je
 e
dd	efd
dZdej de!de!d	efddZ"edej#ej$eej%eedej&j'ddddedej(j'dddddgddgdgdZ)dS )    )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                K   s:   t || j| jdkd}|dkrt  t  t  |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ret r!   5/usr/lib/python3/dist-packages/uaclient/cli/detach.pyaction_detach   s   	r#   r   r   r   c           	   	   C   s   g }t | D ]%}z	t j| |d}W n
 tjy   Y qw |jdd\}}|r,|| q|rHtt	j
t| |D ]}td|j q<tj|dsPdS |D ]}t|| ||dd qRt| }|  t  t|  tt	j d	S )
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_filer!   r!   r"   r   (   sD   


r   detachz--assume-yes)command
store_true)helpactionz--formatcli)defaultstorer   )r>   r?   choicesrA   )	arguments)r>   descriptionr?   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_commandr!   r!   r!   r"   <module>   sJ   ( 
3
