Ë
    ÇVhœ5  ã                   ó†   — 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mZ d dlmZmZ d dlmZ d	„ Zd
„ Zedk(  r e«        yy)é    )Úabsolute_importÚdivisionÚprint_functiona4  
module: dpkg_divert
short_description: Override a debian package's version of a file
version_added: '0.2.0'
author:
  - quidame (@quidame)
description:
  - A diversion is for C(dpkg) the knowledge that only a given package (or the local administrator) is allowed to install
    a file at a given location. Other packages shipping their own version of this file will be forced to O(divert) it, that
    is to install it at another location. It allows one to keep changes in a file provided by a debian package by preventing
    it being overwritten on package upgrade.
  - This module manages diversions of debian packages files using the C(dpkg-divert) commandline tool. It can either create
    or remove a diversion for a given file, but also update an existing diversion to modify its O(holder) and/or its O(divert)
    location.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: full
options:
  path:
    description:
      - The original and absolute path of the file to be diverted or undiverted. This path is unique, in other words it is
        not possible to get two diversions for the same O(path).
    required: true
    type: path
  state:
    description:
      - When O(state=absent), remove the diversion of the specified O(path); when O(state=present), create the diversion if
        it does not exist, or update its package O(holder) or O(divert) location, if it already exists.
    type: str
    default: present
    choices: [absent, present]
  holder:
    description:
      - The name of the package whose copy of file is not diverted, also known as the diversion holder or the package the
        diversion belongs to.
      - The actual package does not have to be installed or even to exist for its name to be valid. If not specified, the
        diversion is hold by 'LOCAL', that is reserved by/for dpkg for local diversions.
      - This parameter is ignored when O(state=absent).
    type: str
  divert:
    description:
      - The location where the versions of file will be diverted.
      - Default is to add suffix C(.distrib) to the file path.
      - This parameter is ignored when O(state=absent).
    type: path
  rename:
    description:
      - Actually move the file aside (when O(state=present)) or back (when O(state=absent)), but only when changing the state
        of the diversion. This parameter has no effect when attempting to add a diversion that already exists or when removing
        an unexisting one.
      - Unless O(force=true), renaming fails if the destination file already exists (this lock being a dpkg-divert feature,
        and bypassing it being a module feature).
    type: bool
    default: false
  force:
    description:
      - When O(rename=true) and O(force=true), renaming is performed even if the target of the renaming exists, in other words
        the existing contents of the file at this location will be lost.
      - This parameter is ignored when O(rename=false).
    type: bool
    default: false
requirements:
  - dpkg-divert >= 1.15.0 (Debian family)
a}  
- name: Divert /usr/bin/busybox to /usr/bin/busybox.distrib and keep file in place
  community.general.dpkg_divert:
    path: /usr/bin/busybox

- name: Divert /usr/bin/busybox by package 'branding'
  community.general.dpkg_divert:
    path: /usr/bin/busybox
    holder: branding

- name: Divert and rename busybox to busybox.dpkg-divert
  community.general.dpkg_divert:
    path: /usr/bin/busybox
    divert: /usr/bin/busybox.dpkg-divert
    rename: true

- name: Remove the busybox diversion and move the diverted file back
  community.general.dpkg_divert:
    path: /usr/bin/busybox
    state: absent
    rename: true
    force: true
aé  
commands:
  description: The dpkg-divert commands ran internally by the module.
  type: list
  returned: on_success
  elements: str
  sample: "/usr/bin/dpkg-divert --no-rename --remove /etc/foobarrc"
messages:
  description: The dpkg-divert relevant messages (stdout or stderr).
  type: list
  returned: on_success
  elements: str
  sample: "Removing 'local diversion of /etc/foobarrc to /etc/foobarrc.distrib'"
diversion:
  description: The status of the diversion after task execution.
  type: dict
  returned: always
  contains:
    divert:
      description: The location of the diverted file.
      type: str
    holder:
      description: The package holding the diversion.
      type: str
    path:
      description: The path of the file to divert/undivert.
      type: str
    state:
      description: The state of the diversion.
      type: str
  sample:
    {
      "divert": "/etc/foobarrc.distrib",
      "holder": "LOCAL",
      "path": "/etc/foobarrc",
      "state": "present"
    }
N)ÚAnsibleModule)Úto_bytesÚ	to_native)ÚLooseVersionc                 óæ   — t        |dd d ¬«      }| j                  |d|gd¬«      \  }}}|rEd|d<   |j                  «       |d<   | j                  |d	|gd¬«      \  }}}|j                  «       |d
<   |S )NÚabsent)ÚpathÚstateÚdivertÚholderz--listpackageT©Úcheck_rcÚpresentr   r   z
--truenamer   )ÚdictÚrun_commandÚrstrip)ÚmoduleÚcommandr   Ú	diversionÚrcÚoutÚerrs          úq/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/dpkg_divert.pyÚdiversion_stater   š   s‹   € Ü˜$ h°tÀDÔI€IØ×%Ñ% w°ÀÐ&FÐQUÐ%ÓVL€BˆˆSÙ
Ø&ˆ	'ÑØ!Ÿj™j›lˆ	(ÑØ×)Ñ)¨7°LÀ$Ð*GÐRVÐ)ÓW‰ˆˆCØ!Ÿj™j›lˆ	(ÑØÐó    c                  ó¨  — t        t        t        dd¬«      t        dddddg¬«      t        dd¬«      t        dd¬«      t        dd	d¬
«      t        dd	d¬
«      ¬«      d¬«      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }t        ||¬«      }d}| j                  dd¬«      }	|	g}
| j	                  |	dgd¬«      \  }}}|j                  «       d   j                  «       D cg c]  }t        j                  d|«      sŒ|‘Œ c}\  }t        |«      t        d«      k  r| j                  d¬«       t        |«      t        d«      k\  }t        |d¬«      }t        j                  j                  |«      }d}d}t        | |	|«      }|d   dk(  r/t        |d   d¬«      }t        j                  j                  |«      }|r|
j!                  d«       n|r|
j!                  d «       |dk(  r˜|r|d!k7  r|
j#                  d"|g«       ||d<   n|
j!                  d#«       d!|d<   |r|
j#                  d$|g«       |}nd%|z  }|
j#                  d&|g«       ||d<   t        |d¬«      }t        j                  j                  |«      }n|
j#                  d'|g«       d |d<   d |d<   |j%                  «       }d(j'                  |
«      }|g}| j(                  s||k(  r|
j+                  d)d*«       |}| j	                  |
«      \  }}}|dk(  r|j-                  «       g}n"||d   k7  r«|r-|r+|dk(  r|s|dk(  r|r|s5d+}| j                  |||||||¬,«       nd-}| j                  |||||||¬,«       |}|dk(  r}| j(                  s:	 t        |d¬«      } t        j.                  | «       | j	                  |
d¬«      \  }}}|j-                  «       g}no|	d'|g}"|r|"j+                  d)d «       d(j'                  |"«      }#| j(                  r|"j+                  d)d*«       |r6|
j5                  d«       |r|
j+                  d)d «       d(j'                  |
«      }|#|g}| j	                  |"d¬«      \  }}$}%| j(                  r|$j-                  «       d0g}nµ| j	                  |
d¬«      \  }}}|$j-                  «       |j-                  «       g}|d   }&|d   }'|'|&k7  rot        |&d¬«      }(t        |'d¬«      })t        j                  j                  |(«      r6t        j                  j                  |)«      s	 t        j6                  |(|)«       | j(                  st        | |	|«      }j%                  «       }t        «       }*| j8                  r
||*d1<   ||*d2<   ||k7  rd}||k(  r| j;                  |||||*¬3«       y d4}| j                  |||||||¬,«       y c c}w # t0        $ r4}!d.|›d/t3        |!«      ›}| j                  |||||||¬,«       Y d }!~!Œ]d }!~!ww xY w# t0        $ r
}!Y d }!~!ŒÚd }!~!ww xY w)5NTr   )ÚrequiredÚtypeFÚstrr   r   )r    r!   ÚdefaultÚchoicesÚbool)r    r!   r#   )r   r   r   r   ÚrenameÚforce)Úargument_specÚsupports_check_moder   r   r   r&   r'   )r   r   zdpkg-divert)r    z	--versionr   r   z^[0-9]+[.][0-9]z1.15.0z#Unsupported dpkg version (<1.15.0).)Úmsgz1.19.1Úsurrogate_or_strict)Úerrorsz--renamez--no-renameÚLOCALz	--packagez--localz--divertz
%s.distribz--addz--removeú é   z--testz5Set 'force' param to True to force renaming of files.)ÚchangedÚcmdr   r*   ÚstderrÚstdoutr   z7Unexpected error while changing state of the diversion.zFailed to remove z: zRunning in check modeÚbeforeÚafter)r0   r   ÚcommandsÚmessagesÚdiffz4Unexpected error: see stdout and stderr for details.)r   r   ÚparamsÚget_bin_pathr   Ú
splitlinesÚsplitÚreÚmatchr	   Ú	fail_jsonr   Úosr   Úexistsr   ÚappendÚextendÚcopyÚjoinÚ
check_modeÚinsertr   ÚunlinkÚOSErrorr   Úremover&   Ú_diffÚ	exit_json)+r   r   r   r   r   r&   r'   Údiversion_wantedr0   ÚDPKG_DIVERTÚMAINCOMMANDr   r3   r2   ÚxÚcurrent_versionÚno_rename_is_supportedÚb_pathÚpath_existsÚtarget_existsÚtruename_existsÚdiversion_beforeÚb_divertÚtargetÚb_targetr   Úmaincommandr6   Údiversion_afterr7   r*   Ú	to_removeÚb_removeÚeÚRMDIVERSIONÚrmdiversionÚrmdoutÚrmderrÚoldÚnewÚb_oldÚb_newr8   s+                                              r   Úmainrh   ¥   sª  € ÜÜÜ˜t¨&Ô1Ü ¨E¸9ÈxÐYbÐNcÔdÜ ¨UÔ3Ü ¨VÔ4Ü ¨V¸UÔCÜ ¨F¸EÔBô
ð !ô
€Fð =‰=˜Ñ €DØM‰M˜'Ñ"€EØ]‰]˜8Ñ$€FØ]‰]˜8Ñ$€FØ]‰]˜8Ñ$€FØM‰M˜'Ñ"€Eä ¨UÔ3ÐØ€Gà×%Ñ% m¸dÐ%ÓC€KØ-€Kð  ×+Ñ+¨[¸+Ð,FÐQUÐ+ÓVÑ€BˆØ$*×$5Ñ$5Ó$7¸Ñ$:×$@Ñ$@Ó$BÖe˜qÄbÇhÁhÐO`ÐbcÕFdšÒeÑ€_ÜOÓ$¤|°HÓ'=Ò=Ø×ÑÐBÐÔCÜ*¨?Ó;¼|ÈHÓ?UÑUÐädÐ#8Ô9€FÜ—'‘'—.‘. Ó(€Kð €MØ€Oä& v¨{¸DÓAÐØ˜Ñ  IÒ-ÜÐ,¨XÑ6Ð?TÔUˆÜŸ'™'Ÿ.™.¨Ó2ˆñ Ø×Ñ˜:Õ&Ù	Ø×Ñ˜=Ô)à	ÒÙf Ò'Ø×Ñ ¨VÐ4Ô5Ø)/Ð˜XÒ&à×Ñ˜yÔ)Ø)0Ð˜XÑ&áØ×Ñ 
¨FÐ3Ô4Ø‰Fà! DÑ(ˆFà×Ñ˜G T˜?Ô+Ø%+Ð˜Ñ"Ü˜FÐ+@ÔAˆÜŸ™Ÿ™ xÓ0‰ð 	×Ñ˜J¨Ð-Ô.Ø%)Ð˜Ñ"Ø%)Ð˜Ñ"ð !×%Ñ%Ó'€IØ—(‘(˜;Ó'€KØˆ}€Hà×ÒÐ,Ð0@Ò@Ø×Ñ˜1˜hÔ'Ø*ˆð  ×+Ñ+¨KÓ8Ñ€Bˆà	ˆQ‚wØ—M‘M“OÐ$Šð 
Ð" 7Ñ+Ò	+ñ ‘kØ˜(Ò"¡Ø˜)Ò#©ÙØMØ× Ñ ¨°kÀbÈcØ(.°vÈð !õ Tð LˆCØ×Ñ W°+À"È#Ø$*°6ÀYð ô Pð ˆ	ØIÒØˆIà× Ò ðTÜ# IÐ6KÔLÜ—	‘	˜(Ô#ð
 "(×!3Ñ!3°KÈ$Ð!3Ó!OÑˆB˜à—M‘M“OÐ$Šð # J°Ð5ˆÙ!Ø×Ñ˜q -Ô0Ø—h‘h˜{Ó+ˆà×ÒØ×Ñ˜q (Ô+áØ×Ñ˜zÔ*Ù%Ø×"Ñ" 1 mÔ4ØŸ(™( ;Ó/ˆKà Ð-ˆØ#×/Ñ/°ÀdÐ/ÓKÑˆˆFFà×ÒØŸ™›Ð)@ÐA‰Hà!'×!3Ñ!3°KÈ$Ð!3Ó!OÑˆB˜ØŸ™›¨¯©«Ð9ˆHð
 # 8Ñ,ˆCØ" 8Ñ,ˆCØcŠzÜ  Ð-BÔCÜ  Ð-BÔCÜ—7‘7—>‘> %Ô(´·±·±ÀÔ1FðÜŸ	™	 %¨Ô/ð ×ÒÜ)¨&°+¸tÓDˆà×$Ñ$Ó&€IÜ‹6€DØ‡|‚|Ø)ˆˆX‰Ø'ˆˆW‰àÐ*Ò*ØˆàÐ*Ò*Ø×Ñ °IØ"*°XÀDð 	õ 	Jð EˆØ×Ñ ¨k¸bÀcØ &¨vÀð 	õ 	Lùò føôz ó TÚ3<¼iÈ¼lÐKØ× Ñ ¨°kÀbÈcØ(.°vÈð !÷ Tò TûðTûô\ #ò Üûðús6   Ä W9Ä<W9Î7"W> ÕX> ×>	X;Ø)X6Ø6X;Ø>	YÙYÚ__main__)Ú
__future__r   r   r   r!   Ú__metaclass__ÚDOCUMENTATIONÚEXAMPLESÚRETURNr=   r@   Úansible.module_utils.basicr   Ú+ansible.module_utils.common.text.convertersr   r   ÚBansible_collections.community.general.plugins.module_utils.versionr	   r   rh   Ú__name__© r   r   ú<module>rt      s]   ð÷ AÑ @Ø€ðC€ðJ€ð0%
€óP 
Û 	å 4ß Kå [òò|Lð~ ˆzÒÙ…Fð r   