
    Vh                     v    d dl mZmZmZ eZd dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ  G d d	e      Zy)
    )absolute_importdivisionprint_functionN)import_module)	to_native)
ActionBase)AnsibleArgSpecValidator)DOCUMENTATIONc                   J     e Zd ZdZdZ fdZd Zd Zd Zd Z	d	 fd	Z
 xZS )
ActionModulezaction moduleFc                 H    t        t        | 
  |i | d| _        d | _        y )NT)superr   __init___supports_async
_task_vars)selfargskwargs	__class__s      j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/ansible/utils/plugins/action/fact_diff.pyr   zActionModule.__init__   s&    lD*D;F;#    c                    t        | j                  j                  t        d| j                  j                        }|j                         \  }}| j                  _        |sd| j                  d<   || j                  d<   y y )Ndoc)dataschemaschema_formatnameTfailedmsg)r	   _taskr   r
   actionvalidate_result)r   aavvaliderrorss       r   _check_argspeczActionModule._check_argspec"   sh    % ""	
 *-&vtzz%)DLL""(DLL r   c                     dj                  | j                  | j                  |      }| j                  j	                  |       y)zdOutput text using ansible's display

        :param msg: The message
        :type msg: str
        z%<{phost}> [fact_diff][{plugin}] {msg})phostpluginr   N)format	_playhost_plugin_displayvvvv)r   r   s     r   _debugzActionModule._debug.   s>     6<<..<< = 

 	3r   c                 D   t        |j                  d            dk7  r!d}d| j                  d<   || j                  d<   yt        t	        g d|j                  d                  }|j                  |	        d
j                  di |}	 t        t        |      |      } || j                  j                  | j                  | j                        }|S # t        $ rB}	d| j                  d<   dj                  |t        |	            | j                  d<   Y d}	~	yd}	~	ww xY w)a  Load a plugin from the fs

        :param plugin: The name of the plugin in collection format
        :type plugin: string
        :param directory: The name of the plugin directory to use
        :type directory: string
        :param class_name: The name of the class to load from the plugin
        :type class_name: string
        :return: An instance of class class_name
        :rtype: class_name
        .   zBPlugin name should be provided as a full name including collectionTr   r   N)corgcnamer*   )	directoryzKansible_collections.{corg}.{cname}.plugins.sub_plugins.{directory}.{plugin})	task_args	task_varsdebugz&Error loading plugin '{plugin}': {err}r*   err )lensplitr#   dictzipupdater+   getattrr   r    r   r   r0   	Exceptionr   )
r   r*   r6   
class_namer   cref	parserlib	class_objclass_instanceexcs
             r   _load_pluginzActionModule._load_plugin;   s    v||C !Q&VC%)DLL""%DLLC3V\\#5FGHi(`Y``  	
	i 8*EI&**////kkN
 "! 	%)DLL""J"Q"QcN #R #DLL 	s   
A	C 	D8DDc                 F   	 |j                         }d|v r!d| j                  d<   |d   | j                  d<   |S # t        $ r^}dj                  | j                  j
                  d   d   t        |            }d| j                  d<   || j                  d<   Y d }~y d }~ww xY w)	Nr&   Tr   r   z8Unhandled exception from plugin '{plugin}'. Error: {err}r*   r   r:   )diffr#   rC   r+   r    r   r   )r   plugin_instanceresultrI   r   s        r   	_run_diffzActionModule._run_diffc   s    	$))+F6!)-X&&,X&6U#M 	LSSzzx08cN T C &*DLL""%DLL	s   69 	B ABB c                 $   d| j                   _        t        t        |   ||      | _        || _        |j                  d      | _        | j                          | j
                  j                  d      r| j
                  S | j                   j                  d   d   | _        | j                  | j                  dd      }| j
                  j                  d      r| j
                  S | j                  |      }| j
                  j                  d      r| j
                  S t        j                  d      }|j!                  d	|d
         }| j
                  j#                  d|d
   it%        |d
         |j'                         |d       | j
                  S )NTinventory_hostnamer   r*   r   	fact_diffFactDiffz\x1B[@-_][0-?]*[ -/]*[@-~] rL   prepared)rL   changed
diff_lines	diff_text)r    rL   r   r   runr#   r   getr,   r'   r   r-   rJ   rO   recompilesubrA   bool
splitlines)r   tmpr8   rM   rN   ansi_escaperX   r   s          r   rY   zActionModule.runt   sG   

\44S)D#"';<<<H%<<zzx08++DLL+zR<<H%<<0<<H%<<jj!>?OOBv7	#VF^4v/'224&		
 ||r   )NN)__name__
__module____qualname____doc___requires_connectionr   r'   r0   rJ   rO   rY   __classcell__)r   s   @r   r   r      s0     

) &P" r   r   )
__future__r   r   r   type__metaclass__r[   	importlibr   ansible.module_utils._textr   ansible.plugins.actionr   Nansible_collections.ansible.utils.plugins.module_utils.common.argspec_validater	   ;ansible_collections.ansible.utils.plugins.modules.fact_diffr
   r   r<   r   r   <module>rp      s:    A @  	 # 0 - Vy: yr   