
    Vh'              
      X   d dl mZ dZdZd dlZd dlmZ d dlm	Z	 d dl
mZ dad	d
ej                  ej                      dddd
ej                  ej                      dd
ej                  ej                       dd	d
ej                  ej"                      ddZd Zd Z G d de	      Zy)    )annotationsa  
author: Unknown (!UNKNOWN)
name: selective
type: stdout
requirements:
  - set as main display callback
short_description: only print certain tasks
description:
  - This callback only prints tasks that have been tagged with C(print_action) or that have failed. This allows operators
    to focus on the tasks that provide value only.
  - Tasks that are not printed are placed with a C(.).
  - If you increase verbosity all tasks are printed.
options:
  nocolor:
    default: false
    description: This setting allows suppressing colorizing output.
    env:
      - name: ANSIBLE_NOCOLOR
      - name: ANSIBLE_SELECTIVE_DONT_COLORIZE
    ini:
      - section: defaults
        key: nocolor
    type: boolean
z}
- ansible.builtin.debug: msg="This will not be printed"
- ansible.builtin.debug: msg="But this will"
  tags: [print_action]
N)	constants)CallbackBase)to_textFz[0mz[mz[1mz	[1m[34m)normalokboldnot_so_boldchangedfailedendcskippedc                "   t        t        | j                               t        |j                               z         }i }|D ]K  }| j                  |      |j                  |      k7  s'| j                  |      |j                  |      f||<   M |S )z=Return a dict of keys that differ with another config object.)setlistkeysget)prvnxtr   resultks        p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/callback/selective.py	dict_diffr   <   sx    tCHHJ$sxxz"223DF 1771:#SWWQZ0F1I1 M    c                >    t         r| S t        |    |  t        d    S )z8Given a string add necessary codes to format the string.r   )DONT_COLORIZECOLORS)msgcolors     r   colorizer!   F   s&    
-fVn%566r   c                       e Zd ZdZdZdZdZd fd	Zd fd	ZddZ	d Z
d	 Zd
 Zd Zd ZddZd Zd Zd Zd Zd ZeZ xZS )CallbackModuleselective.py callback plugin.g       @stdoutzcommunity.general.selectivec                V    t         t        |   |       d| _        d| _        d| _        y)r$   FN)superr#   __init__last_skippedlast_task_nameprinted_last_task)selfdisplay	__class__s     r   r(   zCallbackModule.__init__U   s*    nd,W5!"!&r   c                T    t         t        |   |||       | j                  d      ay )N)	task_keysvar_optionsdirectnocolor)r'   r#   set_options
get_optionr   )r,   r0   r1   r2   r.   s       r   r4   zCallbackModule.set_options\   s+    nd/)Q\ek/l 	2r   c                    || j                   }| j                  sPd| _        d}| j                  r
t                d| d}t	        | d|t        |      z
  z   d      }t        |       y y )NTx   z#  *r
   )r*   r+   r)   printr!   len)r,   	task_nameline_lengthliner   s        r   _print_taskzCallbackModule._print_taskc   su    ++I%%%)D"K  	{!$DdVC;T+B$C#DEvNC#J &r   c                    |j                         }g }|D ]  }|j                  d|z   |         dj                  |      S )Nr8   
)
splitlinesappendjoin)r,   textindent_levellinesresult_linesls         r   _indent_textzCallbackModule._indent_textp   sN    ! 	<A3#5"6qc :;	<yy&&r   c           
        t        |t              r^	 dj                  t        j                  |d   j                         |d   j                         |j                  dd      |d               }|r4t        t        |      d      }t        | j                  ||d	z                y y # t        $ r t        |d   |d         }Y Tw xY w)
NrA   beforeafterbefore_headernew_fileafter_header)fromfiletofiler      )
isinstancedictrD   difflibunified_diffrB   r   AttributeErrorr   r!   strr:   rJ   )r,   diffrF   s      r   _print_diffzCallbackModule._print_diffw   s    dD!@yy!5!5d8n6O6O6Q6:7m6N6N6P?CxxHR@T=A.=Q	"S T CIy1D$##D,*:;<  " @ hg?@s   AB& &CCc	           	     &   |rd}	t        |j                  d      }
n>d}	t        |t              rd|j	                         v r|d   }t        t        |      d      }
|rd}t        d|      }n|rdnd	}t        d
| |      }t        ||      }d}ddt        |
      z
  |	z
  z  }d|	z   d|
 | d| }t        |      dk  r)|d| z  }t        | dd|t        |      z
  z   d       n=t        | dd|t        |      z
  z          t        | j                  ||	dz                |r| j                  ||	       |r*t        |d      }t        | j                  ||	dz                |r+t        |d      }t        | j                  ||	dz                y y )Nr   r   rS   keyr
   r   z	FAILED!!!r   r	   zchanged=r7   r8   (     * - 2    -- -	---------)
r!   namerT   rU   r   r   r;   r:   rJ   r[   )r,   host_or_itemr   r   rZ   is_hosterrorr%   stderrrF   re   r    change_stringr=   spacesr>   s                   r   _print_host_or_itemz"CallbackModule._print_host_or_item   s   LL--}=DL,-L--//#/#6LGL16:DE$[%8M!(IdE$xy%95AMsE"SY56$%T$xr-Is8b=d3%L DTF!C;T#:;<IFGTF!C;T#:;<=>$##C)9:;T<0fh/F$##FL1,<=>fh/F$##FL1,<=> r   c                     y)zRun on start of the play.N )r,   plays     r   v2_playbook_on_play_startz(CallbackModule.v2_playbook_on_play_start   s    r   c                <    |j                         | _        d| _        y)zRun when a task starts.FN)get_namer*   r+   )r,   taskkwargss      r   v2_playbook_on_task_startz(CallbackModule.v2_playbook_on_task_start   s    "mmo!&r   c                (   d|j                   j                  v s|s| j                  j                  dkD  r@| j	                          d| _        t        |j                  j                  dd            xs% t        |j                  j                  dd            }|j                  j                  dd      |j                  j                  d	d      g}d
j                  |D cg c]  }|s|	 c}      j                         }| j                  |j                  |j                  j                  dd      ||j                  j                  dd      d||j                  j                  dd      |j                                d|j                  v r|j                  d   D ]  }d|v xr |d   }|j                  dd      |j                  d	d      g}d
j                  |D cg c]  }|s|	 c}      j                         }| j                  |d   |j                  dd      t        |j                  dd            |j                  dd      d||j                  dd      |j                                 yyd| _        t        dd       yc c}w c c}w )z#Run when a task finishes correctly.print_action   Fr    reason	exceptionNmodule_stderrrA   r   rZ   Tmodule_stdout)rg   rh   r%   ri   resultsr   item.)end)_tasktags_display	verbosityr?   r)   r   _resultr   rD   striprl   _hostr:   )	r,   r   rh   rt   r   ri   err   s	            r   _print_task_resultz!CallbackModule._print_task_result   s=    V\\...%4==;R;RUV;V %D&..,,UB78 :**8R89  nn((d;nn(($?AFYY67aQ78>>@F$$V\\%+^^%7%7	5%I%(%+^^%7%7%E-1+0,2NN,>,>PT,U,2LLN % ' FNN*	2 /A%]:q{FeeK6ot8TUF!YY6'?aQ'?@FFHF,,QvY-.UU9e-D-4QUU5"5E-F-.UU64-@5:3945EE/44P4:LLN - // +" !%D#2;  8  (@s   J
'J
J
%J
c                f   t                d| _        | j                  d       t        |j                  j                               }|D ]g  }|j                  |      }|d   s|d   rd}n
|d   rd}nd}| d|d    d	|d    d
|d    d|d    d|d    d|d    }t        t        ||             i y)z'Display info about playbook statistics.FSTATSfailuresunreachabler   r   r	   z	    : ok=z		changed=z	failed=z	unreachable=z		rescued=rescuedz		ignored=ignoredN)r:   r+   r?   sorted	processedr   	summarizer!   )r,   statshostshostsr    r   s          r   v2_playbook_on_statsz#CallbackModule.v2_playbook_on_stats   s    !&!u++-. 	(D%A}- 0 9! &	!D'*Qy\N)AjM?Zh]#$Jq|nJq|nV  (3&'	(r   c           	        | j                   j                  dkD  r*| j                          d| _        d}ddt	        |j
                  j                        z
  dz
  z  }dt        |j
                  j                  d       | d	t        d
d
       }|j                  j                  dd      xs |j                  j                  dd      }t	        |      dk  r)|d| z  }t        | dd|t	        |      z
  z   d       yt        | dd|t	        |      z
  z          t        | j                  |d             t        |       yy)zRun when a task is skipped.rx   Fr7   r8      rS   r_   r   r`   r   skipped_reasonry   skip_reasonra   rb   rc   rd      N)r   r   r?   r)   r;   r   re   r!   r   r   r:   rJ   )r,   r   rt   r=   rk   r>   rz   s          r   v2_runner_on_skippedz#CallbackModule.v2_runner_on_skipped   s9   ==""Q& %DKBV\\%6%6!77!;<F(6<<#4#4mDEfXRPXYbdmPnOopD^^''(8"= 6""="5 6{R$vh'a{SY'> ?@	JKa{SY'> ?@ABd''23f# 'r   c                .     | j                   |fddi| y )Nrh   Fr   r,   r   rt   s      r   v2_runner_on_okzCallbackModule.v2_runner_on_ok  s    >e>v>r   c                .     | j                   |fddi| y Nrh   Tr   r   s      r   v2_runner_on_failedz"CallbackModule.v2_runner_on_failed      =d=f=r   c                .     | j                   |fddi| y r   r   r   s      r   v2_runner_on_unreachablez'CallbackModule.v2_runner_on_unreachable  r   r   )N)NNN)F)__name__
__module____qualname____doc__CALLBACK_VERSIONCALLBACK_TYPECALLBACK_NAMEr(   r4   r?   rJ   r[   rl   rp   ru   r   r   r   r   r   r   !v2_playbook_on_handler_task_start__classcell__)r.   s   @r   r#   r#   N   sg    'M1M'3'=&?P'
(T(.*?>> )B%r   r#   )
__future__r   DOCUMENTATIONEXAMPLESrV   ansibler   Cansible.plugins.callbackr   +ansible.module_utils.common.text.convertersr   r   COLOR_CODESCOLOR_OKCOLOR_CHANGEDCOLOR_ERROR
COLOR_SKIPr   r   r!   r#   rn   r   r   <module>r      s    #2  " 1 ? !--

+,A
.$q}}Q__56a8ammAMM2315q}}Q\\2315	
7GB\ GBr   