
    Vh[                     v    d dl mZmZmZ eZdZdZd dlZd dl	Z	d dl
mZ  G d de      Zd Zed	k(  r e        yy)
    )absolute_importdivisionprint_functionu  
module: bzr
author:
  - André Paramés (@andreparames)
short_description: Deploy software (or files) from bzr branches
description:
  - Manage C(bzr) branches to deploy files or software.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  name:
    description:
      - SSH or HTTP protocol address of the parent branch.
    aliases: [parent]
    required: true
    type: str
  dest:
    description:
      - Absolute path of where the branch should be cloned to.
    required: true
    type: path
  version:
    description:
      - What version of the branch to clone. This can be the bzr revno or revid.
    default: head
    type: str
  force:
    description:
      - If V(true), any modified files in the working tree will be discarded.
    type: bool
    default: false
  executable:
    description:
      - Path to bzr executable to use. If not supplied, the normal mechanism for resolving binary paths will be used.
    type: str
z
- name: Checkout
  community.general.bzr:
    name: bzr+ssh://foosball.example.org/path/to/branch
    dest: /srv/checkout
    version: 22
N)AnsibleModulec                   >    e Zd Zd Zd
dZd Zd Zd Zd Zd Z	d	 Z
y)Bzrc                 J    || _         || _        || _        || _        || _        y N)moduleparentdestversionbzr_path)selfr   r   r   r   r   s         i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/bzr.py__init__zBzr.__init__E   s%    	     Nc                 n     | j                   j                  | j                  g|z   fd|i|\  }}}|||fS )Ncwd)r   run_commandr   )r   	args_listr   kwargsrcouterrs          r   _commandzBzr._commandL   sA    000$--91L`RU`Y_`S#C~r   c                     d| j                   z  }| j                  j                  || j                        \  }}}|j	                         }|S )z%samples the version of the bzr branchz%s revnor   )r   r   r   r   strip)r   cmdr   stdoutstderrrevnos         r   get_versionzBzr.get_versionP   sF     4==(![[44Sdii4HFFr   c                 ~   t         j                  j                  | j                        }	 t        j                  |       | j                  j                         dk7  r&dd| j                  | j                  | j                  g}nd| j                  | j                  g}| j                  |d|      S # t
        $ r Y {w xY w)z3makes a new bzr branch if it does not already existheadbranch-rTcheck_rcr   )
ospathdirnamer   makedirs	Exceptionr   lowerr   r   )r   dest_dirnamer   s      r   clonez	Bzr.cloneX   s    wwtyy1	KK% <<6)!4t{{DIINI!4;;		:I}}Y<}HH  		s   B0 0	B<;B<c                     d| j                   z  }| j                  j                  || j                        \  }}}|j	                         }t        d |      }t        |      dkD  S )Nz%s status -Sr   c                 0    t        j                  d|        S )Nz^\?\?.*$)research)cs    r   <lambda>z$Bzr.has_local_mods.<locals>.<lambda>k   s    RYY|Q%?!? r   r   )r   r   r   r   
splitlinesfilterlen)r   r    r   r!   r"   liness         r   has_local_modszBzr.has_local_modse   s]    t}},![[44Sdii4HFF!!#?G5zA~r   c                     |s,| j                         r| j                  j                  d       | j                  dgd| j                        S )z
        Resets the index and working tree to head.
        Discards any changes to tracked files in the working
        tree since that commit.
        z2Local modifications exist in branch (force=false).msgrevertTr)   )r=   r   	fail_jsonr   r   )r   forces     r   resetz	Bzr.resetn   sC     ,,.KK!!&Z![}}hZ$DII}FFr   c                 *   | j                   j                         dk7  r/| j                  dd| j                   g| j                        \  }}}n"| j                  dg| j                        \  }}}|dk7  r| j                  j                  d       |||fS )z"updates branch from remote sourcesr&   pullr(   r   r   zFailed to pullr?   )r   r0   r   r   r   rB   )r   r   r   r   s       r   fetchz	Bzr.fetchx   s    <<6)!]]FD$,,+GTYY]WNRc!]]F8]CNRc7KK!!&6!7C~r   c                     | j                   j                         dk7  rdd| j                   g}ndg}| j                  |d| j                        S )z2once pulled, switch to a particular revno or revidr&   rA   r(   Tr)   )r   r0   r   r   )r   r   s     r   switch_versionzBzr.switch_version   sG    <<6)!46I!
I}}Y499}EEr   r
   )__name__
__module____qualname__r   r   r$   r2   r=   rD   rG   rI    r   r   r   r   D   s-    !IGFr   r   c                     t        t        t        dd      t        dddg      t        dd      t        d	d
      t        d                  } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   xs | j                  dd      }t        j
                  j                  |ddd      }d\  }}}	t        | ||||      }
d }d
}t        j
                  j                  |      s|
j                         \  }}}	nw|
j                         }|
j                         }|
j                  |      \  }}}	|dk7  r| j                  |	       |
j                         \  }}}	|dk7  r| j                  |	       |
j                         \  }}}	|
j                         }d
}||k7  s|rd}| j!                  |||       y )Nr,   T)typerequiredstrr   )rO   rP   aliasesr&   )rO   defaultboolF)rO   )r   namer   rC   
executable)argument_specr   rU   r   rC   rV   bzrz.bzrr'   zbranch.conf)r   NNr   r?   )changedbeforeafter)r   dictparamsget_bin_pathr+   r,   joinr   existsr2   r=   r$   rD   rB   rG   rI   	exit_json)r   r   r   r   rC   r   	bzrconfigr   r   r   rX   rZ   
local_modsr[   rY   s                  r   mainrd      s   6D154(DeV4FE2'
F == D]]6"FmmI&GMM'"E}}\*Nf.A.A%.NHT68]CI"LBS
ffdGX
6C FJ77>>)$S# '')
"5)S#7%S#7% '')NRc OOEG*
WV5Ar   __main__)
__future__r   r   r   rO   __metaclass__DOCUMENTATIONEXAMPLESr+   r5   ansible.module_utils.basicr   objectr   rd   rJ   rM   r   r   <module>rl      sY    A @(T 
 	 4DF& DFR4Bn zF r   