
    Vh&                     z    d dl mZmZmZ eZdZdZd dlZd dl	m
Z
 d dlmZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: hg
short_description: Manages Mercurial (hg) repositories
description:
  - Manages Mercurial (hg) repositories. Supports SSH, HTTP/S and local address.
author: "Yeukhon Wong (@yeukhon)"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  repo:
    description:
      - The repository address.
    required: true
    aliases: [name]
    type: str
  dest:
    description:
      - Absolute path of where the repository should be cloned to. This parameter is required, unless clone and update are
        set to no.
    type: path
  revision:
    description:
      - Equivalent C(-r) option in hg command which could be the changeset, revision number, branch name or even tag.
    aliases: [version]
    type: str
  force:
    description:
      - Discards uncommitted changes. Runs C(hg update -C).
    type: bool
    default: false
  purge:
    description:
      - Deletes untracked files. Runs C(hg purge).
    type: bool
    default: false
  update:
    description:
      - If V(false), do not retrieve new revisions from the origin repository.
    type: bool
    default: true
  clone:
    description:
      - If V(false), do not clone the repository if it does not exist locally.
    type: bool
    default: true
  executable:
    description:
      - Path to hg executable to use. If not supplied, the normal mechanism for resolving binary paths will be used.
    type: str
notes:
  - This module does not support push capability. See U(https://github.com/ansible/ansible/issues/31156).
  - 'If the task seems to be hanging, first verify remote host is in C(known_hosts). SSH will prompt user to authorize the
    first contact with a remote host. To avoid this prompt, one solution is to add the remote host public key in C(/etc/ssh/ssh_known_hosts)
    before calling the hg module, with the following command: C(ssh-keyscan remote_host.com >> /etc/ssh/ssh_known_hosts).'
  - As per 01 Dec 2018, Bitbucket has dropped support for TLSv1 and TLSv1.1 connections. As such, if the underlying system
    still uses a Python version below 2.7.9, you will have issues checking out bitbucket repositories. See
    U(https://bitbucket.org/blog/deprecating-tlsv1-tlsv1-1-2018-12-01).
a  
- name: Ensure the current working copy is inside the stable branch and deletes untracked files if any.
  community.general.hg:
    repo: https://bitbucket.org/user/repo1
    dest: /home/user/repo1
    revision: stable
    purge: true

- name: Get information about the repository whether or not it has already been cloned locally.
  community.general.hg:
    repo: git://bitbucket.org/user/repo
    dest: /srv/checkout
    clone: false
    update: false
N)AnsibleModule)	to_nativec                   d    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zed        Zy)Hgc                 J    || _         || _        || _        || _        || _        y N)moduledestreporevisionhg_path)selfr   r   r   r   r   s         h/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/hg.py__init__zHg.__init__c   s%    		     c                 f    | j                   j                  | j                  g|z         \  }}}|||fS r   )r   run_commandr   )r   	args_listrcouterrs        r   _commandzHg._commandj   s3    00$,,)1KLS#C~r   c                 H    dddd| j                   dg}| j                  |      S )Npurge--configextensions.purge=-Rz--print)r   r   )r   argss     r   _list_untrackedzHg._list_untrackedn   s(    %8$		9U}}T""r   c                     | j                  ddddd| j                  g      \  }}}|dk7  r| j                  j                  |       y	t	        |      j                  d      S )
a[  
        hg id -b -i -t returns a string in the format:
           "<changeset>[+] <branch_name> <tag>"
        This format lists the state of the current working copy,
        and indicates whether there are uncommitted changes by the
        plus sign. Otherwise, the sign is omitted.

        Read the full description via hg id --help
        idz-b-iz-tr    r   msg
N)r   r   r   	fail_jsonr   stripr   r   r   r   s       r   get_revisionzHg.get_revisionr   sZ     dD$dii'PQS#7KK!!c!*S>''--r   c                     | j                  d| j                  g      \  }}}|dk7  r| j                  j                  |       y t	        |      j                  d      S )Nr$   r   r&   r(   )r   r   r   r)   r   r*   r+   s       r   get_remote_revisionzHg.get_remote_revision   sP    dii'89S#7KK!!c!*S>''--r   c                 .    | j                         }d|v ryy)N+TF)r,   )r   nows     r   has_local_modszHg.has_local_mods   s    !#:r   c                     | j                         }|syddd| j                  ddg}| j                  |      \  }}}|dk7  r| j                  j	                  |       | j                         }||k7  r|sy	y y )
NFupdatez-Cr    -r.r   r&   T)r2   r   r   r   r)   )r   beforer!   r   r   r   afters          r   discardz
Hg.discard   s}    $$&$diis;t,S#7KK!!c!*##%U?5 $)?r   c                    | j                         \  }}}|dk7  r| j                  j                  |       |dk7  rHdddd| j                  g}| j	                  |      \  }}}|dk7  r| j                  j                  |       yy	)
Nr   r&    r   r   r   r    TF)r"   r   r)   r   r   )r   rc1out1err1r!   rc2out2err2s           r   r   zHg.purge   s     002dD!8KK!!d!+ 2:Z)<dDIIND $d 3S$ax%%$%/r   c                 ^    d}d}|r| j                         }|r| j                         }|s|ryy)NFT)r9   r   )r   forcer   	discardedpurgeds        r   cleanupz
Hg.cleanup   s3    	IZZ\Fr   c                 T    | j                  dd| j                  | j                  g      S )Npullr    )r   r   r   r   s    r   rH   zHg.pull   s'    }}T499dii02 	2r   c                     | j                   *| j                  dd| j                   d| j                  g      S | j                  dd| j                  g      S )Nr4   r5   r    )r   r   r   rI   s    r   r4   z	Hg.update   sH    ==$==(D$--tyy!QRR}}hdii899r   c                     | j                   4| j                  d| j                  | j                  d| j                   g      S | j                  d| j                  | j                  g      S )Ncloner5   )r   r   r   r   rI   s    r   rL   zHg.clone   sP    ==$=='499diit}}!UVV}}gtyy$))<==r   c                    | j                   t        | j                         dk  ry| j                  dddd| j                  g      \  }}}|dk7  r| j                  j                  |       |j                  | j                         ry	y)
z
        There is no point in pulling from a potentially down/slow remote site
        if the desired changeset is already the current changeset.
           Fz--debugr$   r%   r    r   r&   T)r   lenr   r   r   r)   
startswithr+   s       r   at_revisionzHg.at_revision   sv     == C$6$:	4tTYY'OPS#7KK!!c!*>>$--(r   N)__name__
__module____qualname__r   r   r"   r,   r.   r2   r9   r   rF   rH   r4   rL   propertyrQ    r   r   r	   r	   b   sR    #. . 2:
>
  r   r	   c                     t        t        t        dddg      t        d      t        dd dg      t        d	d
      t        d	d
      t        d	d      t        d	d      t        dd                   } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   xs | j                  dd      }| t        j
                  j                  |d      }	d}
d
}d
}|s|s|r| j                  d       t        | ||||      }|s%|s#|j                         }| j                  |d
       t        j
                  j                  	      sA|r,|j                         \  }}}|dk7  r| j                  |       n| j                  d
       n|s|j                         }
n|j                  r#|j                         }
|j                  ||      }nx|j                         }
|j                  ||      }|j!                         \  }}}|dk7  r| j                  |       |j#                         \  }}}|dk7  r| j                  |       |j                         }|
|k7  s|rd}| j                  |
|||       y )NstrTname)typerequiredaliasespath)rZ   version)rZ   defaultr\   boolF)rZ   r_   )r   r   r   rC   r   r4   rL   
executable)argument_specr   r   r   rC   r   r4   rL   ra   hgz.hg/hgrcr;   zOthe destination directory must be specified unless clone=false and update=falser&   )r8   changedr   )rd   )r7   r8   rd   cleaned)r   dictparamsget_bin_pathosr]   joinr)   r	   r.   	exit_jsonexistsrL   r,   rQ   rF   rH   r4   )r   r   r   r   rC   r   r4   rL   r   hgrcr7   rd   re   rc   r   r   r   r8   s                     r   mainrn      s   54&B6"udYKHFE2FE2VT2FD15	
F == D== D}}Z(HMM'"EMM'"E]]8$FMM'"EmmL)LV-@-@t-LGww||D*- FGGUfno	FD$'	2B $$&sE277>>$XXZNRcQw  S )U+"	" **UE* " **UE*S#7%S#7%OOE'
F%'Rr   __main__)
__future__r   r   r   rZ   __metaclass__DOCUMENTATIONEXAMPLESri   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   objectr	   rn   rR   rV   r   r   <module>rw      sX    A @>@  
 4 Au utJSZ zF r   