a )g:- @szddlmZmZmZeZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZmZddlmZddlmZmZddlmZddlmZddlmZeZzFddlZddlZzed ZWn ej e!ej"fyd ZYn0Wne#yd ZYn0d Z$d Z%er.e&d pe$Z$e&dp,e%Z%e j'fddZ(Gddde)Z*ddZ+ddZ,dddZ-GdddeZ.dS))absolute_importdivisionprint_functionN)getpgrpisatty tcgetpgrp) AnsibleError)to_text to_native)boolean) ActionBase)DisplayTF sZcrelcCst|}|tjtjtjBtjBtjBtjB@|tj<|tj tj tj B@|tj <|tj tj B|tj <|tj tjtjBtjBtjB@|tj <d|tjtj<d|tjtj<t|||dS)aPut terminal into a raw mode. Copied from ``tty`` from CPython 3.11.0, and modified to not remove OPOST from OFLAG OPOST is kept to prevent an issue with multi line prompts from being corrupted now that display is proxied via the queue from forks. The problem is a race condition, in that we proxy the display over the fork, but before it can be displayed, this plugin will have continued executing, potentially setting stdout and stdin to raw which remove output post processing that commonly converts NL to CRLF rN)termios tcgetattrttyZIFLAGZBRKINTZICRNLZINPCKZISTRIPZIXONZCFLAGZCSIZEZPARENBZCS8ZLFLAGECHOZICANONZIEXTENZISIGZCCZVMINZVTIME tcsetattr)fdZwhenmoder@/usr/lib/python3.9/site-packages/ansible/plugins/action/pause.pysetraw=s 0*rc@s eZdZdS)AnsibleTimeoutExceededN)__name__ __module__ __qualname__rrrrrRsrcCstdS)N)r)Zsignumframerrrtimeout_handlerVsr cCs |dt|dtdS)Ns[%s)write MOVE_TO_BOL CLEAR_TO_EOL)stdoutrrr clear_lineZsr%cCs*|dur dSt|r"tt|kSdSdS)NF)rrr)rrrris_interactive_s r&cs.eZdZdZdZdfdd ZddZZS) ActionModulezC pauses execution for a length or time, or until input is received TNc s4|durt}tt|||}~|jddddtidtiddiddd \}}d }d}d}|d } d } |td dd d ddd| d| sd} |drd|j |d| f}nd|j d| f}|d dur|d d}n|ddur|d}d}t } t t j |d<d|d<d} d} zhz|dur|dkrHd}ttjtt|td|| ftdf|drt|n t|d} d}z&|jjj}tjj}|} |}Wnttfyd}Yn0t| }|rzt| dtj}Wnty(d}Yn0zt| dtj }Wnty^ddg}Yn0t| } t!| t"|rt!||s| rt| }|d tj#B|d <t$| tj%|t&|tj'|s|durt(d!|durt )|dqz|*d}||kr"t+|t,|s|d"vrBt+|WqnT||vr|ddd#|d<t+|| r||-|d|.n|d|7<WnTt,ytdtd$f|/|rt+|Yqt+|t0d%Yn0qWnt1yYn0Wd| | fvr4t"| r4t$| tj2| t | }t t j |d&<t||d'<|d krxt3|d(d)}n t3|d)}d*||f|d+<nd| | fvrt"| rt$| tj2| t | }t t j |d&<t||d'<|d krt3|d(d)}n t3|d)}d*||f|d+<0t |dd,d-|d<|S).z run the pause action module NboolT)typedefaultr)str)echominutessecondsprompt))r-r.)Z argument_specZmutually_exclusiver-r,Fr)Zchangedrcstderrr$startstopdeltar,z (output is hidden)r/z [%s] %s%s:z,Press enter to continue, Ctrl+C to interrupt<r.r3Z user_inputrzPausing for %d seconds%sz<(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort) z>Not waiting for response to prompt as stdin is not interactive)r z0Press 'C' to continue the play or 'A' to abort zuser requested abort!r4r5gN@zPaused for %s %sr$Zsurrogate_or_strict)errors)4dictsuperr'runZvalidate_argument_specintupdateZ_taskZget_namestriptimer datetimeZnowsignalSIGALRMr alarmdisplayZ _connectionZ _new_stdinbuffersysr$fileno ValueErrorAttributeErrorr&rrZVINTR ExceptionZVERASErrrrZTCSANOWZtcflushZTCIFLUSHZwarningsleepreadr%KeyboardInterruptr!flush_c_or_arrZ TCSADRAINround)selftmpZ task_varsresultZvalidation_resultZnew_module_argsZ duration_unitr/r.r,Z echo_promptr3Zstdin_fdZ old_settingsZ stdout_fdstdinr$ interactiveZintrZ backspaceZ new_settings key_pressedZduration __class__rrrCqs                                       zActionModule.runcCs0|d}|dkrdS|dkrdSqdS)NraFcT)rTlower)rYr\r^rrrrW1s    zActionModule._c_or_a)NN)rrr__doc__ZBYPASS_HOST_LOOPrCrW __classcell__rrr_rr'ls Ar')N)/Z __future__rrrr)Z __metaclass__rHrIrNrrGrosrrrZansible.errorsrZansible.module_utils._textr r Z)ansible.module_utils.parsing.convert_boolr Zansible.plugins.actionr Zansible.utils.displayr rLZcursesioZ setuptermZ HAS_CURSESerror TypeErrorUnsupportedOperation ImportErrorr"r#ZtigetstrZ TCSAFLUSHrrRrr r%r&r'rrrrsF