
    Vh                        d dl mZ dZd dlmZ d dlmZ d dlm	Z	 d dl
m
Z
 d dlZd dlZej                  dk\  Zd	 Zdd
Z G d de      Zy)    )annotationsaK  
name: timestamp
type: stdout
short_description: Adds simple timestamp for each header
version_added: 9.0.0
description:
  - This callback adds simple timestamp for each header.
author: kurokobo (@kurokobo)
options:
  timezone:
    description:
      - Timezone to use for the timestamp in IANA time zone format.
      - For example V(America/New_York), V(Asia/Tokyo)). Ignored on Python < 3.9.
    ini:
      - section: callback_timestamp
        key: timezone
    env:
      - name: ANSIBLE_CALLBACK_TIMESTAMP_TIMEZONE
    type: string
  format_string:
    description:
      - Format of the timestamp shown to user in 1989 C standard format.
      - Refer to L(the Python documentation,https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes)
        for the available format codes.
    ini:
      - section: callback_timestamp
        key: format_string
    env:
      - name: ANSIBLE_CALLBACK_TIMESTAMP_FORMAT_STRING
    default: "%H:%M:%S"
    type: string
seealso:
  - plugin: ansible.posix.profile_tasks
    plugin_type: callback
    description: >-
      You can use P(ansible.posix.profile_tasks#callback) callback plugin to time individual tasks and overall execution time
      with detailed timestamps.
extends_documentation_fragment:
  - ansible.builtin.default_callback
  - ansible.builtin.result_format_callback
)CallbackModule)get_text_width)to_text)datetimeN)   	   c                .    t        j                  |       S )zC
    Returns the current timestamp with the specified timezone
    tz)r   nowr   s    p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/callback/timestamp.pyget_datetime_nowr   A   s     <<2    c                   t        | j                        j                  | j                        }t	        |      dz   }t        |      }| j                  r|r	 | j                  | d|        y|j                         }	 | j                  t	        |      z
  |z
  }|dk  rd}d|z  }| j                  d| d| d| |	       y# t        $ r | j                  d       Y qw xY w# t        $ r | j                  t        |      z
  |z
  }Y ow xY w)
aK  
    Prints a header-looking line with cowsay or stars with length depending on terminal width (3 minimum) with trailing timestamp

    Based on the banner method of Display class from ansible.utils.display

    https://github.com/ansible/ansible/blob/4403519afe89138042108e237aef317fd5f09c33/lib/ansible/utils/display.py#L511
       z @ NzFsomebody cleverly deleted cowsay or something during the PB run.  heh.r   *
 )color)r   timestamp_tzinfostrftimetimestamp_format_stringr   r   b_cowsaybanner_cowsayOSErrorwarningstripcolumnsEnvironmentErrorlendisplay)selfmsgr   cows	timestamptimestamp_lenstar_lenstarss           r   bannerr*   H   s    !!6!67@@A]A]^I"9-1M
#,C}}	c#c)56 ))+C;<<."55E 1}(NELL2cU!E7!I;/uL=  	cLLab	c  ;<<#c(*]:;s$   C ?C# C C #$D
	D
c                  6     e Zd ZdZdZdZ fdZd fd	Z xZS )r   g       @stdoutzcommunity.general.timestampc                    t         t        |           t        j                  t
        | j                        | j                  _        y )N)superr   __init__types
MethodTyper*   _display)r#   	__class__s    r   r/   zCallbackModule.__init__k   s/    nd,.  %//Fr   c                   t         t        |   |||       d }t        r.| j	                  d      rddlm}  || j	                  d            }t        | j                  d|       t        | j                  d| j	                  d             y )N)	task_keysvar_optionsdirecttimezoner   )ZoneInfor   r   format_string)	r.   r   set_options_ZONEINFO_AVAILABLE
get_optionzoneinfor9   setattrr2   )r#   r5   r6   r7   tzinfor9   r3   s         r   r;   zCallbackModule.set_optionsq   ss    nd/)Q\ek/l 4??:#>)dooj9:F 	16:8$///:Z[r   )NNN)	__name__
__module____qualname__CALLBACK_VERSIONCALLBACK_TYPECALLBACK_NAMEr/   r;   __classcell__)r3   s   @r   r   r   f   s%    M1MG\ \r   r   )NT)
__future__r   DOCUMENTATION ansible.plugins.callback.defaultr   Defaultansible.utils.displayr   +ansible.module_utils.common.text.convertersr   r   r0   sysversion_infor<   r   r*    r   r   <module>rQ      sR    #(V G 0 ?   
 &&&0 ><\W \r   