
    g*                        d dl Z d dlZd dlZd dlmZmZmZ 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 d dl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   ejB                         Z" ejF                   ejH                  e%            Z&dejN                  de(dee   dee(   de(de(fdZ)dddZ*ejV                  ejX                   ejZ                  ej\                         ej^                  d      d                             Z0 edejb                  ejd                  e0ejf                   e edejh                  jk                  djm                   e
jn                   ejN                                           dd       edejp                  jk                  d      d !       ed"ejr                  jk                  d#$      dd#d%gd#&       ed'ejt                  d !      g(      g)      Z;y)*    N)AnyDictList)configcontractentitlementsevent_logger
exceptionsmessagesstatusutil)ProgressWrapper)ServiceWithDependencies_dependencies)_enabled_services)cli_util)ProArgumentProArgumentGroup
ProCommand)HelpCategory)CanDisableFailurecfgserviceall_dependenciesenabled_service_namescalled_nameservice_titlec                    g }|D ]\  }|j                   |k(  s|j                   |vr!|j                  D ]-  }|j                   |k(  s|j                  |j                          / ^ |D ]f  }	t        j                  | |	      }
t
        j                  j                  ||
      }t        j                  |      rQt        j                  ||
       y )N)service_being_disableddependent_service)msg)name
depends_onappendr   	get_titler   DEPENDENT_SERVICEformatr   prompt_for_confirmationr
   DependentServiceStopsDisable)r   r   r   r   r   r   dependent_servicessrequirementr    dependent_service_titleuser_msgs               6/usr/lib/python3/dist-packages/uaclient/cli/disable.pyprompt_for_dependency_handlingr0      s      266W.C C<< 	2K7*"))!&&1	22 0 "."8"8"#
 --44#05 5 
 ++999'4"9     T)update_statusc                z   | j                   }||} |rt               }nt        t        j                  |            }| j	                  |      \  }}|st
        j                  | j                         |t        |t              r|j                  t
        j                  |j                  j                         t
        j                  |j                  j                  |j                  j                  | j                         nt
        j                  | j                         |rt        j                  |       |S )a  Perform the disable action on a named entitlement.

    :param entitlement_name: the name of the entitlement to enable
    :param cfg: the UAConfig to pass to the entitlement
    :param json_output: output should be json only

    @return: True on success, False otherwise
    
assume_yes)	error_msg
error_coder   r   )enabled_variantr   r   CLIEnableDisableProgressdisableeventservice_failedr"   
isinstancer   messageinfor!   errorservice_processedr   )	entitlementr   json_outputr5   r2   variantprogressretreasons	            r/   perform_disablerI   >   s     ))G"$"--D
 %%h/KC[--.*V5F"G~~)

6>>--.$nn00%~~22',,   	 0 01#Jr1   zpro disablec          
      D
   g }g }g }g }t         j                  ddd}| j                  dk(  }| j                  }	t	        j
                  |      }
| j                  r|	rt        j                  dd      t        | dg       }t        j                  ||      \  }}t        |      j                  D cg c]  }|j                   }}t        |      j                   }d	}|D ]  }t        j"                  ||| j                  
      }|j$                  }||}|	s&	 t'        ||j                  ||||j(                         |rt7               }nt7        t	        j8                  |	            }|j;                         |_        	 |j?                  |      \  }}tA        j@                  |       |sd}|jC                  |       |tE        |tF              r|jH                   |
|jH                  j0                         |jC                  d|j                  |jH                  j0                  |jH                  j                  d       nN|jC                  |       |jK                         }|r+d	|d<    |
t2        jL                  j                  d              |rd}ddjU                  t        jV                  |            z   dz   }djU                  tY        jZ                  |ddd            }t        j\                  ddjU                  |      |      } |
|j0                         |jC                  dd|j0                  |jP                  |jR                  d       t_        j`                  |      }|jc                          |rl|je                          |je                          |rdnd|d<   ||d <   ||d!<   ||d"<   ||d#<   tg        ti        jj                  |tl        jn                  d	$             |rd%S d&S c c}w # t        j*                  $ rd}t,        j/                  |        |
|j0                          |
t2        j4                  j                  |j(                               d}Y d}~d}~ww xY w# t        j*                  $ r}d}|jC                  |        |
|j0                          |
t2        jN                  j                  |j(                               |jC                  d|j                  |j0                  |jP                  |jR                  d       Y d}~=d}~ww xY w)'zbPerform the disable action on a list of entitlements.

    @return: 0 on success, 1 otherwise
    successF)_schema_versionresultneeds_rebootjson--purge--assume-yes)option1option2r   T)r   r"   purgeN)r   r   )titler4   r8   )typer   r?   message_coderN   zdisable operation)	operation)rV   r   r?   rW   additional_infozTry , .
P   )widthbreak_long_wordsbreak_on_hyphensr;   )rX   invalid_serviceservice_msgsystemfailurerM   processed_servicesfailed_serviceserrorswarnings)cls	sort_keysr      )8r	   JSON_SCHEMA_VERSIONr'   r5   r   &create_interactive_only_print_functionrT   r
   InvalidOptionCombinationgetattrr   get_valid_entitlement_namesr   enabled_servicesr"   r   servicesentitlement_factoryr9   r0   rU   UbuntuProErrorLOG	exceptionr!   r   ENABLE_FAILEDr   r:   calculate_total_disable_stepstotal_stepsr;   r   r$   r>   r   r?   _check_for_rebootENABLE_REBOOT_REQUIRED_TMPLDISABLE_FAILED_TMPLmsg_coderY   joinvalid_servicestextwrapwrapInvalidServiceOpErrorr   UAContractClientupdate_activity_tokensortprintrO   dumpsr   DatetimeAwareJSONEncoder)argsr   kwargsre   rf   rg   rh   json_responserD   r5   interactive_only_printnamesentitlements_foundentitlements_not_foundr+   r   r   rG   ent_nameentrE   erF   disable_retrH   ent_reboot_requiredvalid_namesrb   errcontract_clients                                 r/   action_disabler   l   s    OFH (;;M ++'KJ
 &LL zzj11~
 	
 D)R(E 	00< *#.??  %S)22
C& T..**
 %%C.HH$) ("%))" &(H&11ZHH  #@@B-	"%++h"7KMMc"&&x0%*-+ ~~1.v~~/A/AB(1+.88+1>>+=+=060C0C	 #))(3&)&;&;&=#&48M.1* <<CC&9 D ATl TYY|::sCDDsJ 	 iiMM!&!&	
 .. II&<=#

 	sww' 77 ##&#6#6	
 //4O))+!/2)	h.@*++:'("(h$,j!JJ11	
 1]: ,, a &quu-&**11		1B \ (( 	C""8,"155)",,33#))3D MM%"xx uu$%JJ'('8'8 	s9   /O.%O3=DQ-3Q*AQ%%Q*-T BTTr;   rZ   r8   )optionsstore+)helpactionnargsrQ   )command
store_true)r   r   z--formatcli)defaultrO   )r   r   choicesr   rP   )	arguments)r   descriptionr   help_categoryargument_groups)<rO   loggingr   typingr   r   r   uaclientr   r   r   r	   r
   r   r   r   uaclient.apir   +uaclient.api.u.pro.services.dependencies.v1r   r   -uaclient.api.u.pro.status.enabled_services.v1r   uaclient.clir   uaclient.cli.commandsr   r   r   uaclient.cli.parserr   (uaclient.entitlements.entitlement_statusr   get_event_loggerr<   	getLoggerreplace_top_level_logger_name__name__ru   UAConfigstrr0   rI   verify_json_format_argsassert_rootassert_attached&_raise_enable_disable_unattached_errorassert_lock_filer   CLI_ROOT_DISABLECLI_DISABLE_DESCOTHERCLI_DISABLE_SERVICEr'   r~   r   CLI_ASSUME_YESCLI_FORMAT_DESC	CLI_PURGEdisable_command r1   r/   <module>r      s(      " "	 	 	 ) L ! K K , F%%%'g:::8DE	 23  9	
  @ AE+\ 
!!	(IIJ=)r * K  "rj 		"	"))$$!55<< $		7L77OFOO<MN! = 
 #	 "!0077	7J'
 !11888G""FO! !++'/	
 'r1   