o Hcf$ @sddlZddlZddlZddlmZmZddlmZmZm Z m Z m Z m Z m Z mZmZddlmZmZddlmZddlmZmZddlmZeeeZdejd ed eed eed ed ef ddZ ej!ej"e#ej$e%dddZ&dejfddZ'dS)N)DictList) apiconfigcontract entitlements event_logger exceptionsmessagesstatusutil)ServiceWithDependencies _dependencies)_enabled_services)cli_util constants)CanDisableFailurecfgserviceall_dependenciesenabled_service_names called_name service_titlec Csg}|D]}|j|ks|j|vrq|jD] }|j|kr!||jqq|D]} t|| } tjj|| d} tj | dsBt j || dq%dS)N)service_being_disableddependent_service)msg) name depends_onappendr get_titler DEPENDENT_SERVICEformatr prompt_for_confirmationr DependentServiceStopsDisable) rrrrrrdependent_servicess requirementrdependent_service_titleuser_msgr)6/usr/lib/python3/dist-packages/uaclient/cli/disable.pyprompt_for_dependency_handlings0    r+z pro disablec Ksvg}g}g}g}tjddd}|jdk}t|} |jr&|jr&tjdddt |dg} t | |\} } d d t |j D} t|j}d }| D]}t j||d }|||j|jd }|j}|durb|}|jszt||j|| ||jdWn)tjy}zt|| |j| tjj|jdd}WYd}~qGd}~ww|rt}ntt}||_zU| |\}}t!j!|d|sd}|"||durt#|t$r|j%dur| |j%j|"d|j|j%j|j%jdn|"||&}|rd |d<| tj'jddWqGtjy>}z+d}|"|| |j| tj(j|jd|"d|j|j|j)|j*dWYd}~qGd}~ww| r|d}dd+t j,|d dd}d+t-j.|dddd}tj/dd+| |d}| |j|"d d|j|j)|j*dt01|}|2|r|3|3|rdnd!|d"<||d#<||d$<||d%<||d&<t4t5j6|t7j8d d'|rd(Sd)S)*zbPerform the disable action on a list of entitlements. @return: 0 on success, 1 otherwise successF)_schema_versionresult needs_rebootjson--purge --assume-yes)option1option2rcSsg|]}|jqSr))r).0r%r)r)r* bsz"action_disable..T)rr) assume_yespurgeN)rr)titler)typermessage message_coder/zdisable operation) operation)r;rr<r=additional_infozTry , )r allow_beta. P)widthbreak_long_wordsbreak_on_hyphensdisable)r>invalid_service service_msgsystemfailurer.processed_servicesfailed_serviceserrorswarnings)cls sort_keysr)9rJSON_SCHEMA_VERSIONr!r&create_interactive_only_print_functionr8r7r InvalidOptionCombinationgetattrrget_valid_entitlement_namesrenabled_servicesrservicesentitlement_factoryenabled_variantr+rr9UbuntuProErrorLOG exceptionrr ENABLE_FAILEDrProgressWrapperCLIEnableDisableProgresscalculate_total_disable_steps total_stepsrHr r isinstancerr<_check_for_rebootENABLE_REBOOT_REQUIRED_TMPLDISABLE_FAILED_TMPLmsg_coder?joinvalid_servicestextwrapwrapInvalidServiceOpErrorrUAContractClientupdate_activity_tokensortprintr0dumpsr DatetimeAwareJSONEncoder)argsrkwargsrMrNrOrP json_response json_outputinteractive_only_printnamesentitlements_foundentitlements_not_foundrrretent_nameent_clsentvarianteprogress disable_retreasonent_reboot_required valid_namesrJerrcontract_clientr)r)r*action_disable;s,                      rc Cs|jdtjd}|jtdtjjtjdd}tj |_ ||_ d|_ tj |j_tj|j_|jdddtjjd tj|d d d |jd dtjjddd|jddddgdtjjddd|jddtjd|S)z5Build or extend an arg parser for disable subcommand.rH)help)actionzdisable [])rcommandrstore+r@r:)options)rnargsrr2 store_true)r)rrz--formatclir0)default)rchoicesrrr1) add_parserr CLI_ROOT_DISABLE set_defaultsrr USAGE_TMPLr!NAMECLI_DISABLE_DESC descriptionusageprogCLI_ARGS _positionalsr9 CLI_FLAGS _optionals add_argumentCLI_DISABLE_SERVICErjrrkCLI_ASSUME_YESCLI_FORMAT_DESC CLI_PURGE) subparsersrparserrr)r)r*rsH      r)(r0loggingrltypingrruaclientrrrrrr r r r +uaclient.api.u.pro.services.dependencies.v1r r-uaclient.api.u.pro.status.enabled_services.v1r uaclient.clirr(uaclient.entitlements.entitlement_statusr getLoggerreplace_top_level_logger_name__name__r^UAConfigstrr+verify_json_format_args assert_rootassert_attached&_raise_enable_disable_unattached_errorassert_lock_filerrr)r)r)r*s<,    2