o nnh4@szddlmZdZdZdZddlZddlZddlmZddl m Z ddl m Z Gd d d e Zd d Zed kr;edSdS)) annotationsa --- 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 O(checkout=no), O(update=no), and O(export=no). type: path revision: description: - Specific revision to checkout. type: str default: HEAD aliases: [ rev, version ] force: description: - If V(true), modified files will be discarded. If V(false), module will fail if it encounters modified files. Prior to 1.9 the default was V(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 V(false), do not check out the repository if it does not exist locally. type: bool default: "yes" version_added: "2.3" update: description: - If V(false), do not retrieve new revisions from the origin repository. type: bool default: "yes" version_added: "2.3" export: description: - If V(true), do export instead of checkout/update. type: bool default: "no" version_added: "1.6" switch: description: - If V(false), do not call svn switch before update. default: "yes" version_added: "2.0" type: bool validate_certs: description: - If V(false), passes the C(--trust-server-cert) flag to svn. - If V(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~eZdZdZddZddZdddZd d Zd d d Zd ddZ ddZ ddZ ddZ ddZ ddZddZddZdS)! Subversionz^\w+\s?:\s+\d+$c Cs4||_||_||_||_||_||_||_||_dS)N)moduledestreporevisionusernamepasswordsvn_pathvalidate_certs) selfrr r r r r rrrE/usr/local/lib/python3.10/dist-packages/ansible/modules/subversion.py__init__s zSubversion.__init__cCs.|jj|jddgdd\}}}t|tdkS)Nz --version--quietTcheck_rcz1.10.0)r run_commandrr)rrcversionerrrrrhas_option_password_from_stdinsz)Subversion.has_option_password_from_stdinTcCs|jddg}|js|dd}|jr|d|jg|jr9|r+|d|j}n|jd|d|jg|||jj |||d \}}}|rP| S|S) 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-stdinzThe 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) rrappendr extendr rrwarnr splitlines)rargsrbits stdin_dataroutrrrr_execs(    zSubversion._execcCs|jd|jgdd}|dkS)zChecks if path is a SVN Repo.infoFrr)r%r )rrrrr is_svn_reposzSubversion.is_svn_repoFcC:dg}|r |d|d|j|j|jg||dS)z?Creates new svn working directory if it does not already exist.checkout--force-rNrrr r r r%rforcecmdrrrr)s  zSubversion.checkoutcCr()zExport svn repo to directoryexportr*r+Nr,r-rrrr0s  zSubversion.exportcCs:|dd|j|j|jg}|D] }td|rdSqdS)z Change working directory's repo.switchz --revision ^[ABDUCGE]\sTF)r%r r r researchroutputlinerrrr1s  zSubversion.switchcCs6|dd|j|jg}|D] }td|rdSq dS)z&Update existing svn working directory.updater+r2TF)r%r r r3r4r5rrrr8s  zSubversion.updatecCs6|dd|jg}|D] }td|durdSq dS)zRevert svn working directory.revertz-Rz ^Reverted NTF)r%r r3r4r5rrrr9s zSubversion.revertcCsnd|d|jg}t|j|tj}|r|d}nd}td|tj}|r1|d}||fSd}||fS)1Revision and URL of subversion working directory. r&rUnable to get revisionz ^URL\s?:.*$zUnable to get URL)joinr%r r3r4 REVISION_RE MULTILINEgroup)rtextrevurlrrr get_revisions  zSubversion.get_revisioncCsBd|d|jg}t|j|tj}|r|d}|Sd}|S)r:r;r&rzUnable to get remote revision)r=r%r r3r4r>r?r@)rrArBrrrget_remote_revisions zSubversion.get_remote_revisioncCs6|ddd|jg}td}ttt|j|dkS)zUTrue if revisioned files have been added or modified. Unrevisioned files are ignored.statusrz--ignore-externalsz^[^?X]r)r%r r3compilelenlistfiltermatch)rlinesregexrrrhas_local_mods s zSubversion.has_local_modscCs|\}}d|dd|j|jg}t|j|tj}|r%| d}nd}t | dd }t | dd }d}||krEd }|||fS) Nr;r&r+rr<:FT) rDr=r%r r r3r4r>r?r@intsplitstrip)rcurrrCout2headrev1rev2changerrr needs_updates   zSubversion.needs_updateN)T)F)__name__ __module__ __qualname__r>rrr%r'r)r0r1r8r9rDrErNrZrrrrrs       rcCs8tttddtddddgdtddd d gd td d dtddtdddtddtd d dtd ddtd ddtd ddtd d dtd d dd dd}|jd}|jd}|jd}|jd}|jd}|jd}|jdpt|dd}|jd}|jd} |jd} |jd} |jd} |jd} t|}t||d |_|s| s| s|r|jd!d"t|||||||| }|s| s| s|jd | d#|st j |sd}d }|j r|jdd$n |s| s|jd d$|s| r|d}n|j|d%d}n|rY| s|jd d$|j r)|r|s|jd&d"|\}}}|j|||d'd }|}|}| r=|p<|}|rQ|rK|pI|}n|jd&d"|pW|}n%| rud}|jdd%d}|}|rt|rt|n |jd(|fd"|r|jdd$dS|}|p|}|j|||d'dS))Npath)typestrTname repository)r_requiredaliasesHEADrBr)r_defaultrdboolF)r_rf)r_no_log) r r r r.r r executabler0r)r8r1in_placer) argument_specsupports_check_moder r r r.r r risvnr0r1r)r8rjr)LANG LC_MESSAGESzXthe destination directory must be specified unless checkout=no, update=no, and export=no)msg)changedafter)rq)r.z.ERROR: modified files exist in the repository.)rqbeforerrzEERROR: %s folder already exists, but its not a subversion repository.)rdictparams get_bin_pathrrun_command_environ_update fail_jsonr exit_jsonrEosr^exists check_moder)r0r'rNrZrDr1r9r8)rr r r r.r r rr0r1r)r8rjrlocalermrs local_mods files_changedcheckrrrqrrrmain$s                               r__main__) __future__r DOCUMENTATIONEXAMPLESRETURNrzr3ansible.module_utils.basicr"ansible.module_utils.common.localer#ansible.module_utils.compat.versionrobjectrrr[rrrrs f   c