
    VhG                     v    d dl mZmZmZ eZdZdZd dlm	Z	 d Z
d Zd Zd Zdd	Zd
 Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: urpmi
short_description: Urpmi manager
description:
  - Manages packages with C(urpmi) (such as for Mageia or Mandriva).
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  name:
    description:
      - A list of package names to install, upgrade or remove.
    required: true
    aliases: [package, pkg]
    type: list
    elements: str
  state:
    description:
      - Indicates the desired package state.
    choices: [absent, present, installed, removed]
    default: present
    type: str
  update_cache:
    description:
      - Update the package database first C(urpmi.update -a).
    type: bool
    default: false
  no_recommends:
    description:
      - Corresponds to the C(--no-recommends) option for C(urpmi).
    type: bool
    default: true
  force:
    description:
      - Assume "yes" is the answer to any question urpmi has to ask. Corresponds to the C(--force) option for C(urpmi).
    type: bool
    default: true
  root:
    description:
      - Specifies an alternative install root, relative to which all packages are installed. Corresponds to the C(--root)
        option for C(urpmi).
    aliases: [installroot]
    type: str
author:
  - Philippe Makowski (@pmakowski)
a  
- name: Install package foo
  community.general.urpmi:
    pkg: foo
    state: present

- name: Remove package foo
  community.general.urpmi:
    pkg: foo
    state: absent

- name: Remove packages foo and bar
  community.general.urpmi:
    pkg: foo,bar
    state: absent

- name: Update the package database (urpmi.update -a -q) and install bar (bar will be the updated if a newer version exists)
- community.general.urpmi:
    name: bar
    state: present
    update_cache: true
)AnsibleModulec                     | j                  dd      }|d|dt        |      }| j                  |d      \  }}}|dk(  ryy)NrpmTz -q  Fcheck_rcr   get_bin_pathroot_optionrun_commandmodulenamerootrpm_pathcmdrcstdoutstderrs           k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/urpmi.pyquery_packager   \   sP     ""5$/H#T;t+<
=C++C%+@B	Qw    c                     | j                  dd      }|d|dt        |      }| j                  |d      \  }}}|dk(  S )Nr   Tz -q --whatprovides r	   Fr
   r   r   r   s           r   query_package_providesr   h   sL     ""5$/H*2D+d:K
LC++C%+@B7Nr   c                     | j                  dd      }|d}| j                  |d      \  }}}|dk7  r| j                  d       y y )	Nzurpmi.updateTz -a -qFr
   r   zcould not update package dbmsg)r   r   	fail_json)r   urpmiupdate_pathr   r   r   r   s         r   update_package_dbr#   q   sW    **>4@(
*C++C%+@B	Qw:; r   c                 D   d}|D ]k  }t        | ||      s| j                  dd      }|dt        |      d|}| j                  |d      \  }}}	|dk7  r| j	                  d|z  	       |d
z  }m |dkD  r| j                  dd|z         | j                  dd       y )Nr   urpmeT --auto r	   Fr
   zfailed to remove %sr      zremoved %s package(s)changedr    zpackage(s) already absent)r   r   r   r   r!   	exit_json)
r   packagesr   remove_cpackage
urpme_pathr   r   r   r   s
             r   remove_packagesr/   z   s    H VWd3(($7
#-{4/@'J#//e/DFF7!6'!BCA !|+BX+MN
U(CDr   c           	         d}|D ]  }t        | ||      r|d|z  z  } t        |      dk7  r|rd}nd}|rd}nd}| j                  dd      }	|	d|d	|d
t        |      d
|	}
| j	                  |
      \  }}}|D ](  }t        | ||      r| j                  d|d|       * |r| j                  d|d|       y | j                  dd|z         y | j                  d       y )N z'%s' r   z--no-recommendsz--forceurpmiTr&   z	 --quiet r	   z'urpmi z
' failed: r   z%s present(s)r(   F)r)   )r   lenr   r   r   r!   r*   )r   pkgspecr   forceno_recommendsr+   r-   no_recommends_yes	force_yes
urpmi_pathr   r   outerrs                 r   install_packagesr<      s   H *%fgt<'))H* 8} 1 "!II(($7
2<i2C2=d2C2:<
 ))#.C 	OG)&'4@  %M N	O
 Hc!JKT/IJ'r   c                     | rd| z  S y)Nz	--root=%sr1    )r   s    r   r   r      s    d##r   c                     t        t        t        ddg d      t        dd      t        dd      t        dd      t        d	ddd
dg      t        ddg                  } | j                  }|d   rt        |        |d   dv rt	        | |d   |d   |d   |d          y |d   dv rt        | |d   |d          y y )Nstrpresent)absent	installedrA   removed)typedefaultchoicesboolF)rE   rF   Tlistr-   pkg)rE   elementsrequiredaliasesinstallroot)rE   rM   )stateupdate_cacher5   r6   r   r   )argument_specrP   rO   )rC   rA   r   r   r5   r6   )rD   rB   )r   dictparamsr#   r<   r/   )r   ps     r   mainrU      s    E9LN659FD1FD96ED9V[J\]5=/:

F 	A&!z--6AfIqz1_CUV	
7,	,&	1V95 
-r   __main__N)TT)
__future__r   r   r   rE   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   r   r   r#   r/   r<   r   rU   __name__r>   r   r   <module>r]      s`    A @1f0 5	<E2$(N62 zF r   