
    Vh#                        d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZ  ej(                  d      Z G d	 d
e      Zy)    )annotationsN)MappingSequence)AnsibleError)	to_native)	text_typestring_types)AnsiblePluginz^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$c                       e Zd Z fdZd Zd fd	Zed        Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd ZddZd ZddZddZd ZddZd Zd Zd Zd Z xZS )	ShellBasec                T    t         t        |           i | _        d | _        d | _        y N)superr   __init__envtmpdir
executable)self	__class__s    N/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/shell/__init__.pyr   zShellBase.__init__%   s'    i')
     c                    | j                  d      D cg c]  }|j                  d       }}t        d |D              s#t        dj	                  t        |                  | j                  d|       y c c}w )Nsystem_tmpdirs/c              3  Z   K   | ]#  }t         j                  j                  |       % y wr   )ospathisabs).0ds     r   	<genexpr>z6ShellBase._normalize_system_tmpdirs.<locals>.<genexpr>8   s     >277==#>s   )+z`The configured system_tmpdirs contains a relative path: {0}. All system_tmpdirs must be absolute)
get_optionrstripallr   formatr   
set_option)r   r    normalized_pathss      r   _normalize_system_tmpdirsz#ShellBase._normalize_system_tmpdirs0   sx     48??CS3TUaAHHSMUU >-=>>  BBH&ScIdBeg g 	(*:; Vs   A6c                r    t         t        |   |||       	 | j                          y # t        $ r Y y w xY w)N)	task_keysvar_optionsdirect)r   r   set_optionsr(   KeyError)r   r*   r+   r,   r   s       r   r-   zShellBase.set_options>   s=    i*YK`f*g
	**, 		s   * 	66c                     dt        j                          dt        j                         dt        j                  d      S )Nzansible-tmp--l          )timer   getpidsecrets	randbelow r   r   _generate_temp_dir_namez!ShellBase._generate_temp_dir_nameJ   s'    )-biik7CTCTUZC[\\r   c                    dj                  |j                         D cg c]$  \  }}|d| j                  t        |            & c}}      S c c}}w )N =)joinitemsquoter   )r   kwargskvs       r   
env_prefixzShellBase.env_prefixN   s;    xxV\\^\TQAtzz)A,'?@\]]\s   )A
c                :    t        j                  j                  | S r   )r   r   r:   )r   argss     r   	join_pathzShellBase.join_pathQ   s    ww||T""r   c                |    t         j                  j                  |j                               }|j                         S r   )r   r   basenamestrip)r   pathname	base_names      r   get_remote_filenamezShellBase.get_remote_filenameU   s*    GG$$X^^%56	  r   c                $    |j                  d      S )Nr   )endswith)r   r   s     r   path_has_trailing_slashz!ShellBase.path_has_trailing_slashY   s    }}S!!r   c                N    d|g}|j                  |       | j                  |      S )Nchmodextendr:   )r   pathsmodecmds       r   rN   zShellBase.chmod\   %    o

5yy~r   c                N    d|g}|j                  |       | j                  |      S )NchownrO   )r   rQ   userrS   s       r   rV   zShellBase.chowna   rT   r   c                N    d|g}|j                  |       | j                  |      S )NchgrprO   )r   rQ   grouprS   s       r   rY   zShellBase.chgrpf   s&    

5yy~r   c                \    ddd|d|g}|j                  |       | j                  |      S )z5Only sets acls for users as that's really all we needsetfaclz-mzu::rO   )r   rQ   rW   rR   rS   s        r   set_user_faclzShellBase.set_user_faclk   s-    $T4 89

5yy~r   c                ^    | j                  |      }d}|r|dz  }||d| j                  z   S )Nzrm -f z-r r8   )r<   _SHELL_REDIRECT_ALLNULL)r   r   recurserS   s       r   removezShellBase.removeq   s7    zz$5LCd&B&BCCCr   c                L    dd| j                  |      g}dj                  |      S )Ntestz-er8   )r<   r:   )r   r   rS   s      r   existszShellBase.existsx   s%    tTZZ-.xx}r   c                l   |s| j                   j                         }|r>|r|j                  d      }|| j                  d      v r|}n+| j                  d      d   }n|| j                  d      }n|}| j	                  ||      }d| j
                  d|d| j                  }|| j                  d| j
                  d|d| j                  z  }|d| j                  d|d	| j
                  d|d| j                  
z  }|r.d
| z  }d| j                  || j                  || j                  fz  }|S )Nr   r   r   
remote_tmpz	mkdir -p z echo r8   z mkdir r9   i  z%s umask %o %s %s %s)
r   r6   r#   r"   rC   _SHELL_SUB_LEFT_SHELL_SUB_RIGHT
_SHELL_AND_SHELL_GROUP_LEFT_SHELL_GROUP_RIGHT)	r   basefilesystemrR   r   
basetmpdirbasetmprS   	tmp_umasks	            r   mkdtempzShellBase.mkdtemp|   s"   ~~==?H s+)9::#
!__-=>qA
~!__\:
#
..X6 +/*>*>
DLaLab4??D<P<PRY[_[p[pqqdooxI]I]_fhlh}h}~~ I(D,B,BIt`ceie|e|+}}C
r   c                z    |dk7  r+t         j                  |      s| j                  |      }d|z  S |r||z  }d|z  S )a   Return a command to expand tildes in a path

        It can be either "~" or "~username". We just ignore $HOME
        We use the POSIX definition of a username:
            http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_426
            http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_276

            Falls back to 'current working directory' as we assume 'home is where the remote user ends up'
        ~zecho %s)_USER_HOME_PATH_REmatchr<   )r   user_home_pathusernames      r   expand_userzShellBase.expand_user   sO     S %++N;!%N!;
 >))	 h&N>))r   c                :    d| j                   d| j                  S )z-Return the working directory after connectingzecho pwd)rh   ri   )r   s    r   r{   zShellBase.pwd   s    !%!5!5t7L7LMMr   c                    |j                         }|r|dz  }|d}|j                  d      j                         |j                         |g}| j                  fd|D              }dj                  ||f      S )Nr8    z#!c              3  J   K   | ]  }|r|j                         xr  y wr   )rF   )r   raw_cmd_partstripped_cmd_parts     r   r!   z1ShellBase.build_module_command.<locals>.<genexpr>   s0      #
".l6H6H6J!J!2!J #
s    #)rF   removeprefixr:   )r   
env_stringshebangrS   arg_path	cmd_partscleaned_up_cmdr   s          @r   build_module_commandzShellBase.build_module_command   s    %%'
#J?G   &,,.IIK
	  #
2;#
 
 ww
N344r   c                H    | j                   r|d| j                   d|z  }|S )z6Append an additional command if supported by the shellr8   )rj   )r   rS   cmd_to_appends      r   append_commandzShellBase.append_command   s#     ??t>>C
r   c                    |S )z_wrap script execution with any necessary decoration (eg '&' for quoted powershell script paths)r5   r   rS   s     r   wrap_for_execzShellBase.wrap_for_exec   s    
r   c                ,    t        j                  |      S )z[Returns a shell-escaped string that can be safely used as one token in a shell command line)shlexr<   r   s     r   r<   zShellBase.quote   s    {{3r   c                ,    t        j                  |      S )zZReturns a shell-escaped string from a list that can be safely used in a shell command line)r   r:   )r   r   s     r   r:   zShellBase.join   s    zz)$$r   )NNN)F)NFi  N)r}   r   )__name__
__module____qualname__r   r(   r-   staticmethodr6   r@   rC   rI   rL   rN   rV   rY   r^   rb   re   rr   ry   r{   r   r   r   r<   r:   __classcell__)r   s   @r   r   r   $   s    	<
 ] ]^#!"


D(T**N5( %r   r   )
__future__r   r   os.pathrer3   r   r1   collections.abcr   r   ansible.errorsr   +ansible.module_utils.common.text.convertersr   ansible.module_utils.sixr   r	   ansible.pluginsr
   compileru   r   r5   r   r   <module>r      sK   " # 	  	    - ' A < )RZZ BC A% A%r   