Hcf"ddlmZddlmZddlmZmZmZmZm Z ddl m Z GddejZ dZdefd Zdd Zd Zd ZddZdZdZy )wraps)Optional)api entitlements exceptionslockutil) _is_attachedc BeZdZdZdededeedeefdZdefdZy ) CLIEnableDisableProgresscd|_y)NT)is_interactive)selfs 7/usr/lib/python3/dist-packages/uaclient/cli/cli_util.py__init__z!CLIEnableDisableProgress.__init__ s " total_steps done_stepsprevious_step_messagecurrent_step_messagec | t|yyN)print)rrrrrs rprogressz!CLIEnableDisableProgress.progress s + & ' ,reventc|dk(r t|y|dk(r/tj|tstjyy)Ninfomessage_operation)rr handle_message_operationsrPromptDeniedError)rrpayloads r _on_eventz"CLIEnableDisableProgress._on_eventsC F? 'N ) )11'5A 2244B*rN) __name__ __module__ __qualname__rintrstrrr#rrr r sH# ( ( ( (} ( 'sm (5s5rr cyrr))argskwargss r _null_printr-sr json_outputc|rtStSr)r-r)r.s r&create_interactive_only_print_functionr0#s rNcfd}|S)z1Decorator asserting exclusive access to lock filec2tfd}|S)Ncvtjd5|d|i|}ddd|S#1swYSxYw)N) lock_holder sleep_timecfg)r RetryLock)r7r+r,retvalfr5s rnew_fz0assert_lock_file..wrapper..new_f.s?KAF 5D4c4V4 5M 5Ms .8r)r:r;r5s` rwrapperz!assert_lock_file..wrapper-s q     rr))r5r<s` rassert_lock_filer=*s Nrc.tfd}|S)zDecorator asserting root usercdtjstj|i|Sr)r we_are_currently_rootrNonRootUserError)r+r,r:s rr;zassert_root..new_f<s.))+--/ /d%f% %rrr:r;s` r assert_rootrC9s" 1X&& Lrc.tfd}|S)z>Decorator to verify if correct params are used for json formatc|s |g|i|S|jdk(r |jstj|g|i|S)Njson)format assume_yesrCLIJSONFormatRequireAssumeYes)cmd_argsr+r,r:s rr;z&verify_json_format_args..new_fIsSX/// / ??f $X-@-@::< <X/// /rrrBs` rverify_json_format_argsrKFs" 1X00 Lrcfd}|S)zDecorator asserting attached config. :param msg_function: Optional function to generate a custom message if raising an UnattachedError c2tfd}|S)Nct|js<r&t|dd}t|dd}|||ntj|fd|i|S)Ncommandservice)rO service_namesr7r7)r is_attachedgetattrrUnattachedError)r+r7r,rOrRr:raise_custom_error_functions rr;z/assert_attached..wrapper..new_f]se$00.%dIr:G$+D)R$@M/ '}#%4466T-s-f- -rr)r:r;rVs` rr<z assert_attached..wrapper\s q .  . rr))rVr<s` rassert_attachedrWVs  Nrc.tfd}|S)z&Decorator asserting unattached config.ct|jr:tj|jj j dd|fd|i|S)NnamerP) account_namer7)r rSrAlreadyAttachedErrormachine_token_fileaccountget)r+r7r,r:s rr;z"assert_not_attached..new_frsW   ( (11 33;;??K )3)&))rrrBs` rassert_not_attachedr`os" 1X** LrcJtj||\}}|r9|r7tjdj ||dj |d|r&tj dj ||tj |dj |d)zRaises a custom error for enable/disable commands when unattached. Takes into consideration if the services exist or not, and notify the user accordingly.)namesr7z, rP) valid_service operationinvalid_service service_msg)rcrd)rdrerf)rget_valid_entitlement_namesrUnattachedMixedServicesErrorjoinUnattachedValidServicesErrorUnattachedInvalidServicesError)rOrRr7entitlements_foundentitlements_not_founds r&_raise_enable_disable_unattached_errorrn}s 00}#N455))$67 II&<=   55))$677  77 II&<=  rr) functoolsrtypingruaclientrrrr r (uaclient.api.u.pro.status.is_attached.v1r AbstractProgressr r-boolr0r=rCrKrWr`rnr)rrrusU>>A5s335.     2  r