U (fw*@sddlZddlZddlZddlmZmZddlmZmZm Z m Z m Z m Z m Z mZddlmZddlmZmZddlmZddlmZddlmZmZmZdd lmZdd lmZe Z!e"e#e$Z%ej&e'eeee'e'e'd d d Z(ddddZ)ej*ej+e,ej-e.dddZ/ede j0e j1e/ej2eede j3j4d5e j6e&dddddede j7j4dddd ed!e j8j4d"d#dd"d$gd"d%ed&e j9dd gd'gd(Z:dS))N)DictList)configcontract entitlements event_logger exceptionsmessagesstatusutil)ProgressWrapper)ServiceWithDependencies _dependencies)_enabled_services)cli_util) ProArgumentProArgumentGroup ProCommand) HelpCategory)CanDisableFailure)cfgserviceall_dependenciesenabled_service_names called_name service_titlec Csg}|D]<}|j|ks|j|kr"q|jD]}|j|kr(||jq(q|D]:} t|| } tjj|| d} tj | dsJt j || dqJdS)N)Zservice_being_disableddependent_service)msg) nameZ depends_onappendrZ get_titler ZDEPENDENT_SERVICEformatr Zprompt_for_confirmationrZDependentServiceStopsDisable) rrrrrrZdependent_servicessZ requirementrZdependent_service_titleZuser_msgr"6/usr/lib/python3/dist-packages/uaclient/cli/disable.pyprompt_for_dependency_handlings*   r$T) update_statusc Cs|j}|dk r|}|rt}nttj|d}||\}}|st|j|dk rt|t r|j dk rt |j j tj |j j |j j|jdn t|j|rtj|d|S)aPerform 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 N assume_yes)Z error_msgZ error_coderr)enabled_variantr rCLIEnableDisableProgressdisableeventZservice_failedr isinstancermessageinforerrorZservice_processedr ) Z entitlementr json_outputr'r%variantprogressretreasonr"r"r#perform_disable>s.      r6z pro disablec Ks~g}g}g}g}tjddd}|jdk}|j} t|} |jrP| rPtjdddt |dg} t | |\} } d d t |j D}t|j}d }| D]}t j|||jd }|j}|d k r|}| s:zt||j||||jdWnZtjk r8}z8t|| |j| tjj|jdd}WYqW5d }~XYnX|rHt}nttj| d}||_z||\}}t j |d|sd}|!||d k rt"|t#r|j$d k r| |j$j|!d|j|j$j|j$jdn2|!||%}|rd |d<| tj&jddWqtjk r}zNd}|!|| |j| tj'j|jd|!d|j|j|j(|j)dW5d }~XYqXq| rd}dd*t j+|dd}d*t,j-|dddd}tj.dd*| |d}| |j|!dd |j|j(|j)dt/0|}|1|rp|2|2|r2dnd |d!<||d"<||d#<||d$<||d%<t3t4j5|t6j7d d&|rzd'Sd(S))zbPerform the disable action on a list of entitlements. @return: 0 on success, 1 otherwise ZsuccessF)Z_schema_versionresult needs_rebootjson--purge --assume-yes)Zoption1Zoption2rcSsg|] }|jqSr")r).0r!r"r"r# sz"action_disable..T)rrpurgeN)rr)titler&r()typerr. message_coder8zdisable operation) operation)r@rr.rAadditional_infozTry , . P)widthZbreak_long_wordsZbreak_on_hyphensr+)rBZinvalid_service service_msgsystemZfailurer7processed_servicesfailed_serviceserrorswarnings)clsZ sort_keysr)8rZJSON_SCHEMA_VERSIONr r'rZ&create_interactive_only_print_functionr>rZInvalidOptionCombinationgetattrrZget_valid_entitlement_namesrZenabled_servicesrZservicesZentitlement_factoryr)r$rr?ZUbuntuProErrorLOGZ exceptionrr Z ENABLE_FAILEDr r*Zcalculate_total_disable_stepsZ total_stepsr+r rr-rr.Z_check_for_rebootZENABLE_REBOOT_REQUIRED_TMPLZDISABLE_FAILED_TMPLZmsg_coderCjoinvalid_servicestextwrapZwrapZInvalidServiceOpErrorrZUAContractClientZupdate_activity_tokensortprintr9dumpsr ZDatetimeAwareJSONEncoder)argsrkwargsrKrLrMrNZ json_responser1r'Zinteractive_only_printnamesZentitlements_foundZentitlements_not_foundrrr4Zent_nameZentr2er3Z disable_retr5Zent_reboot_requiredZ valid_namesrIerrZcontract_clientr"r"r#action_disablels(                       r^r+rrDr()ZoptionsZstore+)helpactionnargsr;)Zcommand store_true)r`raz--formatZcli)defaultr9)r`rachoicesrdr:)Z arguments)r`Z descriptionraZ help_categoryZargument_groups);r9ZloggingrUtypingrrZuaclientrrrrrr r r Z uaclient.apir Z+uaclient.api.u.pro.services.dependencies.v1r rZ-uaclient.api.u.pro.status.enabled_services.v1rZ uaclient.clirZuaclient.cli.commandsrrrZuaclient.cli.parserrZ(uaclient.entitlements.entitlement_statusrZget_event_loggerr,Z getLoggerZreplace_top_level_logger_name__name__rRZUAConfigstrr$r6Zverify_json_format_argsZ assert_rootZassert_attachedZ&_raise_enable_disable_unattached_errorZassert_lock_filer^ZCLI_ROOT_DISABLEZCLI_DISABLE_DESCZOTHERZCLI_DISABLE_SERVICEr rSrTZCLI_ASSUME_YESZCLI_FORMAT_DESCZ CLI_PURGEZdisable_commandr"r"r"r#s(       . 6