a ì)gÞ4ã@s‚ddlmZmZmZeZdZdZdZddl Z ddl Z ddl m Z ddl mZddlmZGd d „d eƒZd d „Zed kr~eƒdS)é)Úabsolute_importÚdivisionÚprint_functionaÄ --- module: subversion short_description: Deploys a subversion repository description: - Deploy given repository URL / revision to dest. If dest exists, update to the specified revision, otherwise perform a checkout. version_added: "0.7" author: - Dane Summers (@dsummersl) options: repo: description: - The subversion URL to the repository. type: str required: true aliases: [ name, repository ] dest: description: - Absolute path where the repository should be deployed. - The destination directory must be specified unless I(checkout=no), I(update=no), and I(export=no). type: path revision: description: - Specific revision to checkout. type: str default: HEAD aliases: [ rev, version ] force: description: - If C(true), modified files will be discarded. If C(false), module will fail if it encounters modified files. Prior to 1.9 the default was C(true). type: bool default: "no" in_place: description: - If the directory exists, then the working copy will be checked-out over-the-top using svn checkout --force; if force is specified then existing files with different content are reverted. type: bool default: "no" version_added: "2.6" username: description: - C(--username) parameter passed to svn. type: str password: description: - C(--password) parameter passed to svn when svn is less than version 1.10.0. This is not secure and the password will be leaked to argv. - C(--password-from-stdin) parameter when svn is greater or equal to version 1.10.0. type: str executable: description: - Path to svn executable to use. If not supplied, the normal mechanism for resolving binary paths will be used. type: path version_added: "1.4" checkout: description: - If C(false), do not check out the repository if it does not exist locally. type: bool default: "yes" version_added: "2.3" update: description: - If C(false), do not retrieve new revisions from the origin repository. type: bool default: "yes" version_added: "2.3" export: description: - If C(true), do export instead of checkout/update. type: bool default: "no" version_added: "1.6" switch: description: - If C(false), do not call svn switch before update. default: "yes" version_added: "2.0" type: bool validate_certs: description: - If C(false), passes the C(--trust-server-cert) flag to svn. - If C(true), does not pass the flag. default: "no" version_added: "2.11" type: bool extends_documentation_fragment: action_common_attributes attributes: check_mode: support: full diff_mode: support: none platform: platforms: posix notes: - This module does not handle externals. requirements: - subversion (the command line tool with C(svn) entrypoint) a+ - name: Checkout subversion repository to specified folder ansible.builtin.subversion: repo: svn+ssh://an.example.org/path/to/repo dest: /src/checkout - name: Export subversion directory to folder ansible.builtin.subversion: repo: svn+ssh://an.example.org/path/to/repo dest: /src/export export: yes - name: Get information about the repository whether or not it has already been cloned locally ansible.builtin.subversion: repo: svn+ssh://an.example.org/path/to/repo dest: /src/checkout checkout: no update: no ú#N)Ú AnsibleModule)Úget_best_parsable_locale)Ú LooseVersionc@s~eZdZdZdd„Zdd„Zddd„Zd d „Zd d d „Zd!dd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)"Ú Subversionz^\w+\s?:\s+\d+$c Cs4||_||_||_||_||_||_||_||_dS)N)ÚmoduleÚdestÚrepoÚrevisionÚusernameÚpasswordÚsvn_pathÚvalidate_certs) Úselfr r r r rrrr©rú>/usr/lib/python3.9/site-packages/ansible/modules/subversion.pyÚ__init__–szSubversion.__init__cCs.|jj|jddgdd�\}}}t|ƒtdƒkS)Nz --versionú--quietT©Úcheck_rcz1.10.0)r Ú run_commandrr)rÚrcÚversionÚerrrrrÚhas_option_password_from_stdin sz)Subversion.has_option_password_from_stdinTcCs¨|jddg}|js| d¡d}|jr6| d|jg¡|jrr| ¡rV| d¡|j}n|j d¡| d|jg¡| |¡|jj |||d �\}}}|r |  ¡S|SdS) zuExecute a subversion command, and return output. If check_rc is False, returns the return code instead of the output.z--non-interactivez--no-auth-cachez--trust-server-certNz --usernamez--password-from-stdinz›The authentication provided will be used on the svn command line and is not secure. To securely pass credentials, upgrade svn to version 1.10.0 or greater.z --password)Údata) rrÚappendrÚextendrrr ÚwarnrÚ splitlines)rÚargsrÚbitsZ stdin_datarÚoutrrrrÚ_exec¤s(ý    zSubversion._execcCs|jd|jgdd�}|dkS)zChecks if path is a SVN Repo.ÚinfoFrr)r&r )rrrrrÚ is_svn_repoÀszSubversion.is_svn_repoFcCs:dg}|r| d¡| d|j|j|jg¡| |¡dS)z?Creates new svn working directory if it does not already exist.Úcheckoutú--forceú-rN©rr r r r r&©rÚforceÚcmdrrrr)Ås  zSubversion.checkoutcCs:dg}|r| d¡| d|j|j|jg¡| |¡dS)zExport svn repo to directoryÚexportr*r+Nr,r-rrrr0Ís  zSubversion.exportcCs:| dd|j|j|jg¡}|D]}t d|¡rdSqdS)z Change working directory's repo.Úswitchz --revisionú ^[ABDUCGE]\sTF)r&r r r ÚreÚsearch©rÚoutputÚlinerrrr1Ös  zSubversion.switchcCs6| dd|j|jg¡}|D]}t d|¡rdSqdS)z&Update existing svn working directory.Úupdater+r2TF)r&r r r3r4r5rrrr8às  zSubversion.updatecCs6| dd|jg¡}|D]}t d|¡durdSqdS)zRevert svn working directory.Úrevertz-Rz ^Reverted NTF)r&r r3r4r5rrrr9és zSubversion.revertcCshd | d|jg¡¡}t |j|tj¡}|r8| d¡}nd}t d|tj¡}|r\| d¡}nd}||fS)ú1Revision and URL of subversion working directory.Ú r'rúUnable to get revisionz ^URL\s?:.*$zUnable to get URL)Újoinr&r r3r4Ú REVISION_REÚ MULTILINEÚgroup)rÚtextÚrevÚurlrrrÚ get_revisionñs  zSubversion.get_revisioncCs@d | d|jg¡¡}t |j|tj¡}|r8| d¡}nd}|S)r:r;r'rzUnable to get remote revision)r=r&r r3r4r>r?r@)rrArBrrrÚget_remote_revisions  zSubversion.get_remote_revisioncCs6| ddd|jg¡}t d¡}ttt|j|ƒƒƒdkS)zUTrue if revisioned files have been added or modified. Unrevisioned files are ignored.Ústatusrz--ignore-externalsz^[^?X]r)r&r r3ÚcompileÚlenÚlistÚfilterÚmatch)rÚlinesZregexrrrÚhas_local_mods s zSubversion.has_local_modscCs”| ¡\}}d | dd|j|jg¡¡}t |j|tj¡}|rJ|  d¡}nd}t |  d¡d  ¡ƒ}t |  d¡d  ¡ƒ}d}||krŠd }|||fS) Nr;r'r+rr<ú:éFT) rDr=r&r r r3r4r>r?r@ÚintÚsplitÚstrip)rZcurrrCZout2ÚheadZrev1Zrev2ZchangerrrÚ needs_updates  zSubversion.needs_updateN)T)F)F)Ú__name__Ú __module__Ú __qualname__r>rrr&r(r)r0r1r8r9rDrErMrTrrrrr Žs        r cCsTtttdd�tddddgd�tddd d gd �td d d�tdd�tddd�tdd�td d d�td dd�td dd�td dd�td d d�td d d�d� dd�}|jd}|jd}|jd}|jd}|jd}|jd}|jdpè| dd¡}|jd}|jd} |jd} |jd} |jd} |jd} t|ƒ}t||d �|_|�s`| �sT| �sT|�r`|jd!d"�t|||||||| ƒ}|�sš| �sš| �sš|jd |  ¡d#�|�s®t j   |¡�sd}d }|j �rÌ|jdd$�n|�sä| �sä|jd d$�|�sþ| �rþ| ¡d}n|j|d%�d}�n| ¡�rÐ| �s.|jd d$�|j �rp| ¡�rR|�sR|jd&d"�| ¡\}}}|j|||d'�d }| ¡}| ¡}| �r˜| ¡�p–|}|�rÀ|�r´| ¡�p°|}n |jd&d"�| ¡�pÌ|}nJ| �rd}|jdd%�d}| ¡}|�r|�r| ¡n|jd(|fd"�|�r.|jdd$�n"| ¡}|�p>|}|j|||d'�dS))NÚpath)ÚtypeÚstrTÚnameZ repository)rYÚrequiredÚaliasesZHEADrBr)rYÚdefaultr]ÚboolF)rYr^)rYZno_log) r r r r.rrÚ executabler0r)r8r1Úin_placer)Z argument_specZsupports_check_moder r r r.rrr`Úsvnr0r1r)r8rar)ÚLANGÚ LC_MESSAGESzXthe destination directory must be specified unless checkout=no, update=no, and export=no)Úmsg)ÚchangedÚafter)rf)r.z.ERROR: modified files exist in the repository.)rfÚbeforergzEERROR: %s folder already exists, but its not a subversion repository.)rÚdictÚparamsZ get_bin_pathrZrun_command_environ_updateZ fail_jsonr Z exit_jsonrEÚosrXÚexistsZ check_moder)r0r(rMrTrDr1r9r8)r r r r r.rrrr0r1r)r8rarÚlocalerbrhZ local_modsZ files_changedÚcheckrgrfrrrÚmain%s¢        óð                         roÚ__main__)Z __future__rrrrYZ __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNrkr3Zansible.module_utils.basicrZ"ansible.module_utils.common.localerZ#ansible.module_utils.compat.versionrÚobjectr rorUrrrrÚsf   c