
    Vh$                     ~    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d Zd Zd Zd	 Zd
 Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: pkgutil
short_description: OpenCSW package management on Solaris
description:
  - This module installs, updates and removes packages from the OpenCSW project for Solaris.
  - Unlike the M(community.general.svr4pkg) module, it will resolve and download dependencies.
  - See U(https://www.opencsw.org/) for more information about the project.
author:
  - Alexander Winkler (@dermute)
  - David Ponessa (@scathatheworm)
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
    details:
      - In order to check the availability of packages, the catalog cache under C(/var/opt/csw/pkgutil) may be refreshed even
        in check mode.
  diff_mode:
    support: none
options:
  name:
    description:
      - The name of the package.
      - When using O(state=latest), this can be V('*'), which updates all installed packages managed by pkgutil.
    type: list
    required: true
    elements: str
    aliases: [pkg]
  site:
    description:
      - The repository path to install the package from.
      - Its global definition is in C(/etc/opt/csw/pkgutil.conf).
    required: false
    type: str
  state:
    description:
      - Whether to install (V(present)/V(installed)), or remove (V(absent)/V(removed)) packages.
      - The upgrade (V(latest)) operation will update/install the packages to the latest version available.
    type: str
    required: true
    choices: [absent, installed, latest, present, removed]
  update_catalog:
    description:
      - If you always want to refresh your catalog from the mirror, even when it is not stale, set this to V(true).
    type: bool
    default: false
  force:
    description:
      - To allow the update process to downgrade packages to match what is present in the repository, set this to V(true).
      - This is useful for rolling back to stable from testing, or similar operations.
    type: bool
    default: false
    version_added: 1.2.0
a  
- name: Install a package
  community.general.pkgutil:
    name: CSWcommon
    state: present

- name: Install a package from a specific repository
  community.general.pkgutil:
    name: CSWnrpe
    site: ftp://myinternal.repo/opencsw/kiel
    state: latest

- name: Remove a package
  community.general.pkgutil:
    name: CSWtop
    state: absent

- name: Install several packages
  community.general.pkgutil:
    name:
      - CSWsudo
      - CSWtop
    state: present

- name: Update all packages
  community.general.pkgutil:
    name: '*'
    state: latest

- name: Update all packages and force versions to match latest in catalog
  community.general.pkgutil:
    name: '*'
    state: latest
    force: true
z # )AnsibleModulec                 l    g }|D ],  }t        | dd|g      \  }}}|dk7  s|j                  |       . |S )zG Check if each package is installed and return list of the ones absent pkginfo-qr   )run_commandappendmodulenamespkgspkgrcouterrs          m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/pkgutil.pypackages_not_installedr   p   sI    D "6ItS+ABC7KK K    c                     g }|D ]>  }|j                  d      st        | dd|g      \  }}}|dk(  s.|j                  |       @ |S )zH Check if each package is installed and return list of the ones present CSWr   r	   r   )
startswithr
   r   r   s          r   packages_installedr   z   sX    D ~~e$"6ItS+ABC7KK Kr   c                    dg}|r|j                  d       |j                  d       ||j                  d|g       |dgk7  r|j                  |       t        | |      \  }}}g }|j                  d      dd D ]/  }	d	|	vsd
|	vs|j                  |	j                  d      d          1 t	        t        |            S )zT Check status of each package and return list of the ones with an upgrade available pkgutil-Uz-c-t*
   catalogSAME r   )r   extendr
   splitlistset)
r   r   siteupdate_catalogcmdr   r   r   packageslines
             r   packages_not_latestr/      s    +C

4JJt

D$< ~

5vs+LBS H		$"% 0D V4%7OODJJsOA./0
 Hr   c                 `    |d   }| j                  |ddg      |d<    | j                  |fi |S )Nr   Tz/opt/csw/bin)get_bin_pathr
   )r   r,   kwargsprognames       r   r
   r
      s>    1vH  4.1ABCF6c,V,,r   c                    dg}| j                   r|j                  d       |j                  d       |r|j                  d       ||j                  d|g       |r|j                  d       |j                  |       t        | |      S )Nr   -nz-iyr   r   -f
check_moder   r&   r
   )r   stater   r*   r+   forcer,   s          r   package_installr;      sw    +C

4JJu

4

D$< 

4JJtvs##r   c                     dg}| j                   r|j                  d       |j                  d       |r|j                  d       ||j                  d|g       |r|j                  d       ||z  }t        | |      S )Nr   r5   z-uyr   r   r6   r7   )r   r   r*   r+   r:   r,   s         r   package_upgrader=      st    +C

4JJu

4

D$< 

44KCvs##r   c                     dg}| j                   r|j                  d       |j                  d       |j                  |       t        | |      S )Nr   r5   z-ryr7   )r   r   r,   s      r   package_uninstallr?      sC    +C

4JJuJJtvs##r   c                     t        t        t        ddddg      t        ddg d      t        d      t        d	d
      t        d	d
            d      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }d }d}d}t        ||      }	|dv rm|dgk(  r| j                  d       t	        | |      }
|
g k(  r| j                  d
       t        | ||
|||      \  }}}|dk7  r-| j                  |xs |       n|dv r|dgk(  rVt        | |||      }
|
g k(  r| j                  d
       g }
t        | |
|||      \  }}}|dk7  r| j                  |xs |       nt	        | |      }
|
t        | |||      z  }
|
g k(  r| j                  d
       t        | |
|||      \  }}}|dk7  ri| j                  |xs |       nR|dv rNt        | |      }
|
g k(  r| j                  d
       t        | |
      \  }}}|dk7  r| j                  |xs |       |d
|	d<   n|dk(  rd|	d<   n
d
|	d<   d|	d<   |r||	d<   |r||	d <    | j
                  d!i |	 y )"Nr(   strTr   )typeelementsrequiredaliases)absent	installedlatestpresentremoved)rB   rD   choices)rB   boolF)rB   default)namer9   r*   r+   r:   )argument_specsupports_check_moderN   r9   r*   r+   r:    )rN   r9   )rG   rI   r   z+Can not use 'state: present' with name: '*')msg)changedr   )rH   )rF   rJ   rS   failedstdoutstderr )r   dictparams	fail_jsonr   	exit_jsonr;   r/   r=   r   r?   )r   rN   r9   r*   r+   r:   r   r   r   resultr   s              r   mainr]      s   6ED5'RED:qr5!VU;FE2
 !	F == DMM'"E== D]]#34NMM'"E	B
C
CF
 ((C5=!NO &fd3 2:U+(dNTYZS#7#*.	*	C5=&vtT>JD rz   / D,VT4QVWNRcQw  cjS 2 *&$7D'dNKKD rz   /,VT4QVWNRcQw  cjS 2	'	'!&$/ 2:U+*648S#7#*.	z!y	q y!yx
x
xFvr   __main__N)
__future__r   r   r   rB   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   r   r   r/   r
   r;   r=   r?   r]   __name__rW   r   r   <module>rf      sk    A @6p"H 
 4	,-$$$`F zF r   