
    Vh                     l    d dl mZmZmZ eZdZdZdZd dl	Z
d dlZd dlZd dlmZ d Zedk(  r e        yy)	    )absolute_importdivisionprint_functiona  
author:
  - Jeroen Hoekx (@jhoekx)
  - Matt Robinson (@ribbons)
  - Dag Wieers (@dagwieers)
module: iso_extract
short_description: Extract files from an ISO image
description:
  - This module has two possible ways of operation.
  - If 7zip is installed on the system, this module extracts files from an ISO into a temporary directory and copies files
    to a given destination, if needed.
  - If the user has mount-capabilities (CAP_SYS_ADMIN on Linux) this module mounts the ISO image to a temporary location,
    and copies files to a given destination, if needed.
requirements:
  - Either 7z (from C(7zip) or C(p7zip) package)
  - Or mount capabilities (root-access, or CAP_SYS_ADMIN capability on Linux)
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  image:
    description:
      - The ISO image to extract files from.
    type: path
    required: true
    aliases: [path, src]
  dest:
    description:
      - The destination directory to extract files to.
    type: path
    required: true
  files:
    description:
      - A list of files to extract from the image.
      - Extracting directories does not work.
    type: list
    elements: str
    required: true
  force:
    description:
      - If V(true), which will replace the remote file when contents are different than the source.
      - If V(false), the file will only be extracted and copied if the destination does not already exist.
    type: bool
    default: true
  executable:
    description:
      - The path to the C(7z) executable to use for extracting files from the ISO.
      - If not provided, it will assume the value V(7z).
    type: path
  password:
    description:
      - Password used to decrypt files from the ISO.
      - Will only be used if 7z is used.
      - The password is used as a command line argument to 7z. This is a B(potential security risk) that allows passwords
        to be revealed if someone else can list running processes on the same machine in the right moment.
    type: str
    version_added: 10.1.0
notes:
  - Only the file checksum (content) is taken into account when extracting files from the ISO image. If O(force=false), only
    checks the presence of the file.
z
- name: Extract kernel and ramdisk from a LiveCD
  community.general.iso_extract:
    image: /tmp/rear-test.iso
    dest: /tmp/virt-rear/
    files:
      - isolinux/kernel
      - isolinux/initrd.cgz
z
#
N)AnsibleModulec                  	   t        t        t        ddddg      t        dd      t        ddd      t        d	d
      t        dd      t        d            d      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }t        d||      }|d}| j                  |d       }| j                  d   |s| j	                  d|z         t
        j                  j                  |      s| j                  d|z         t
        j                  j                  t
        j                  j                  |            s| j                  d|z         g |d<   t        |      }	|s|D ]  }
t
        j                  j                  |t
        j                  j                  |
            }t
        j                  j                  |      s`|d   j                  t        d ||
             |	j                  |
        |	s | j                  d/i | t!        j"                         }|r|d|d|z  g}|r	|d|z  gz  }||	z  }n| j                  d       d!d"||g}| j%                  |      \  }}}|d#k7  ro|j'                  t        ||||$             t)        j*                  |       |r | j                  d/d%d&|d'|d(i| n | j                  d/d%d)|d'|d*|d+i| 	 |	D ](  }
t
        j                  j                  ||
      }t
        j                  j                  |      s | j                  d/d%d,|
z  i| | j-                  |      }t
        j                  j                  |t
        j                  j                  |
            }t
        j                  j                  |      r| j-                  |      }nd }|d   j                  t        |||
             ||k7  s| j.                  st)        j0                  ||       d|d-<   + 	 |s"| j%                  | j                  d.      |g       t)        j*                  |        | j                  d/i | y # |s"| j%                  | j                  d.      |g       t)        j*                  |       w xY w)0NpathTsrc)typerequiredaliases)r
   r   liststr)r
   elementsr   bool)r
   default)r
   no_log)r
   )imagedestfilesforcepassword
executable)argument_specsupports_check_moder   r   r   r   r   r   F)changedr   r   7zzHExecutable '%s' is not found on the system, trying to mount ISO instead.zDirectory '%s' does not exist)msgzISO image '%s' does not exist)checksumr   r	   xz-o%sz-p%smountz-ozloop,ror   )cmdrcstderrstdoutr   z"Failed to extract from ISO image 'z' to ''zFailed to mount ISO image 'z%', and we could not find executable 'z'.z%Failed to extract '%s' from ISO imager   umount )r   dictparamsget_bin_pathwarnosr   exists	fail_jsondirnamer   joinbasenameappendremove	exit_jsontempfilemkdtemprun_commandupdateshutilrmtreesha1
check_modecopy)moduler   r   r   r   r   r   resultbinaryextract_filesf	dest_filetmp_dirr!   r"   outerrtmp_srcsrc_checksumdest_checksums                       q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/iso_extract.pymainrK   e   sx   FTFE?K6D1FUTBFD1uT2(
 !
F MM'"E== DMM'"EMM'"E}}Z(H|,JF 
  T2F }}\".v^akkl77>>$<tCD77>>"''//%01<uDEF7OKM 	(AT277+;+;A+>?Iww~~i(w&&t!"( 
 $$Q'	( "6" G sE6G#34FX%&&C}""7+T9eWM%%c*LBS	Qwd	
 	 	gFnTY[b!cngmnF  \uz  }D  FP  "Q  \  U[  \ 	)Aggll7A.G77>>'*   [%Lq%P[TZ[!;;w/LT277+;+;A+>?Iww~~i( &I 6 $7O""4%$  },((KK3$(y!1	)4  3 3H =wGHgFv  3 3H =wGHgs   DR *R ;S__main__)
__future__r   r   r   r
   __metaclass__DOCUMENTATIONEXAMPLESRETURNos.pathr,   r9   r5   ansible.module_utils.basicr   rK   __name__r'       rJ   <module>rV      sS    A @@D
    4up zF rU   