
    Vh                     n    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ ddlmZ d	 Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionaX  
module: podman_save
short_description: Saves podman image to tar file
author: Sagi Shnaidman (@sshnaidm)
description:
  - podman save saves an image to either docker-archive, oci-archive, oci-dir
    (directory with oci manifest type), or docker-dir (directory with v2s2 manifest type)
    on the local machine, default is docker-archive.

options:
  image:
    description:
    - Image to save.
    type: list
    elements: str
    required: true
  compress:
    description:
    - Compress tarball image layers when pushing to a directory using the 'dir' transport.
      (default is same compression type, compressed or uncompressed, as source)
    type: bool
  dest:
    description:
    - Destination file to write image to.
    type: str
    required: true
    aliases:
      - path
  format:
    description:
    - Save image to docker-archive, oci-archive (see containers-transports(5)), oci-dir
      (oci transport), or docker-dir (dir transport with v2s2 manifest type).
    type: str
    choices:
    - docker-archive
    - oci-archive
    - oci-dir
    - docker-dir
  multi_image_archive:
    description:
    - Allow for creating archives with more than one image. Additional names will be
      interpreted as images instead of tags. Only supported for docker-archive.
    type: bool
  force:
    description:
    - Force saving to file even if it exists.
    type: bool
    default: True
  executable:
    description:
      - Path to C(podman) executable if it is not in the C($PATH) on the
        machine running C(podman)
    default: 'podman'
    type: str
requirements:
  - "Podman installed on host"

z
# What modules does for example
- containers.podman.podman_save:
    image: nginx
    dest: /tmp/file123.tar
- containers.podman.podman_save:
    image:
      - nginx
      - fedora
    dest: /tmp/file456.tar
    multi_image_archive: true
N)AnsibleModule   )remove_file_or_dirc                    d}|dg}dgd| j                   d   z  gd| j                   d   z  gdgd	}| j                   D ]  }| j                   |   ||v s|||   z  }! | j                   d
   D ]  }|j                  |        | j                   d   rNd}| j                   d   }t        j                  j	                  |      rK| j
                  r|ddfS 	 t        |       n-t        j                  j	                  | j                   d          }| j
                  r|ddfS | j                  |      \  }	}
}|	dk7  r| j                  d|z         ||
|fS # t        $ r"}| j                  d|d|       Y d }~kd }~ww xY w)NFsavez
--compressz-o=%sdestz--format=%sformatz--multi-image-archive)compressr   r   multi_image_archiveimageforceT zError deleting z path: msgr   z	Error: %s)
paramsappendospathexists
check_moder	   	Exception	fail_jsonrun_command)module
executablechangedcommandcmd_argsparamimgr   ercouterrs               q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/containers/podman/plugins/modules/podman_save.pyr   r   Y   s   G6"G!N6==001 6==#::; 78	H  '==+0Ax&G' }}W% s}}W}}V$77>>$  B&O"4( ggnnV]]6%:;;B%%g.LBS	Qw[C01C  O  T1%M NNOs   E 	E?E::E?c                     t        t        t        ddd      t        d      t        dddg      t        dg d	
      t        d      t        dd      t        dd            d      } | j                  d   r#| j                  d   dvr| j                  d       | j	                  | j                  d   d      }t        | |      \  }}}|||d} | j                  di | y )NliststrT)typeelementsrequiredbool)r-   r   )r-   r/   aliases)zdocker-archivezoci-archiveoci-dir
docker-dir)r-   choices)r-   defaultpodman)r   r   r   r   r   r   r   )argument_specsupports_check_moder   r   )r2   r3   z?Compression is only supported for oci-dir and docker-dir formatr   r   )r/   )r    stdoutstderr )r   dictr   r   get_bin_pathr   	exit_json)r   r   r    r'   r(   resultss         r)   mainr@   {   s    FUTBv&54&BU,fg $& 1FD19
 !F }}Z V]]8%<D]%]^_$$V]]<%@4$PJVZ0GS# G Fw    __main__)
__future__r   r   r   r-   __metaclass__DOCUMENTATIONRETURNEXAMPLESr   ansible.module_utils.basicr   module_utils.podman.commonr	   r   r@   __name__r;   rA   r)   <module>rK      sS    A @8t
 
 4 ;D 8 zF rA   