
    Vh4                        d dl m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
 d dlmZ  G d	 d
e      Zd Zedk(  r e        yy)    )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) <njharman@gmail.com>
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
        C(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                  d    e Zd ZdZd Zd ZddZd ZddZddZ	d Z
d	 Zd
 Zd Zd Zd Zd Zy)
Subversionz^\w+\s?:\s+\d+$c	                t    || _         || _        || _        || _        || _        || _        || _        || _        y )N)moduledestreporevisionusernamepasswordsvn_pathvalidate_certs)	selfr   r   r   r   r   r   r   r   s	            J/home/dcms/DCMS/lib/python3.12/site-packages/ansible/modules/subversion.py__init__zSubversion.__init__   s;    		    ,    c                    | j                   j                  | j                  ddgd      \  }}}t        |      t        d      k\  S )Nz	--version--quietTcheck_rcz1.10.0)r   run_commandr   r   )r   rcversionerrs       r   has_option_password_from_stdinz)Subversion.has_option_password_from_stdin   sD    ;;22DMM;PY3Zei2jGSG$X(>>>r   c                "   | j                   ddg}| j                  s|j                  d       d}| j                  r|j	                  d| j                  g       | j
                  rf| j                         r|j                  d       | j
                  }n8| j                  j                  d       |j	                  d| j
                  g       |j	                  |       | j                  j                  |||	      \  }}}|r|j                         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)r   r   appendr   extendr   r   r   warnr   
splitlines)r   argsr   bits
stdin_datar   outr   s           r   _execzSubversion._exec   s     MM

 ""KK-.
==KKt}}56==22434!]]
   "k l\4==9:D{{..tXJ.OC>>##Ir   c                J    | j                  d| j                  gd      }|dk(  S )zChecks if path is a SVN Repo.infoFr   r   )r*   r   )r   r   s     r   is_svn_repozSubversion.is_svn_repo   s&    ZZ+eZ<Qwr   c                    dg}|r|j                  d       |j                  d| j                  | j                  | j                  g       | j                  |       y)z?Creates new svn working directory if it does not already exist.checkout--force-rNr"   r#   r   r   r   r*   r   forcecmds      r   r/   zSubversion.checkout   sD    lJJy!

D$--DII>?

3r   c                    dg}|r|j                  d       |j                  d| j                  | j                  | j                  g       | j                  |       y)zExport svn repo to directoryexportr0   r1   Nr2   r3   s      r   r7   zSubversion.export   sD    jJJy!

D$--DII>?

3r   c                    | j                  dd| j                  | j                  | j                  g      }|D ]  }t	        j
                  d|      s y y)z Change working directory's repo.switchz
--revision^[ABDUCGE]\sTF)r*   r   r   r   researchr   outputlines      r   r9   zSubversion.switch   sN     X|T]]DIItyyYZ 	Dyy$/	 r   c                    | j                  dd| j                  | j                  g      }|D ]  }t        j                  d|      s y y)z&Update existing svn working directory.updater1   r:   TF)r*   r   r   r;   r<   r=   s      r   rA   zSubversion.update   sF    XtT]]DIIFG 	Dyy$/	 r   c                ~    | j                  dd| j                  g      }|D ]  }t        j                  d|       y y)zRevert svn working directory.revertz-Rz
^Reverted TF)r*   r   r;   r<   r=   s      r   rC   zSubversion.revert   sC    XtTYY78 	Dyy-5	 r   c                h   dj                  | j                  d| j                  g            }t        j                  | j
                  |t        j                        }|r|j                  d      }nd}t        j                  d|t        j                        }|r|j                  d      }||fS d}||fS )1Revision and URL of subversion working directory.
r,   r   Unable to get revisionz^URL\s?:.*$zUnable to get URL)joinr*   r   r;   r<   REVISION_RE	MULTILINEgroup)r   textrevurls       r   get_revisionzSubversion.get_revision   s    yyVTYY$789ii(($=))A,C*Ciibll;))A,C Cx &CCxr   c                    dj                  | j                  d| j                  g            }t        j                  | j
                  |t        j                        }|r|j                  d      }|S d}|S )rE   rF   r,   r   zUnable to get remote revision)rH   r*   r   r;   r<   rI   rJ   rK   )r   rL   rM   s      r   get_remote_revisionzSubversion.get_remote_revision  sa    yyVTYY$789ii(($=))A,C 
 2C
r   c                    | j                  ddd| j                  g      }t        j                  d      }t	        t        t        |j                  |                  dkD  S )zUTrue if revisioned files have been added or modified. Unrevisioned files are ignored.statusr   z--ignore-externalsz^[^?X]r   )r*   r   r;   compilelenlistfiltermatch)r   linesregexs      r   has_local_modszSubversion.has_local_mods  sN    

Hi1EtyyQR 

9%4u{{E234q88r   c                   | j                         \  }}dj                  | j                  dd| j                  | j                  g            }t        j                  | j                  |t
        j                        }|r|j                  d      }nd}t        |j                  d      d   j                               }t        |j                  d      d   j                               }d}||k  rd	}|||fS )
NrF   r,   r1   r   rG   :   FT)rO   rH   r*   r   r   r;   r<   rI   rJ   rK   intsplitstrip)r   currrN   out2headrev1rev2changes           r   needs_updatezSubversion.needs_update  s    %%'	cyyVT4==$))$LMNyy))4>::a=D+D4::c?1%++-.4::c?1%++-.$;FtT!!r   N)T)F)__name__
__module____qualname__rI   r   r   r*   r-   r/   r7   r9   rA   rC   rO   rQ   r[   rh    r   r   r	   r	      sJ     %K-?8
"9"r   r	   c                    t        t        t        d      t        ddddg      t        ddd	d
g      t        dd      t        d      t        dd      t        d      t        dd      t        dd      t        dd      t        dd      t        dd      t        dd            d      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   xs | j                  dd      }| j                  d   }| j                  d   }	| j                  d   }
| j                  d   }| j                  d   }| j                  d   }t	        |       }t        ||       | _        |s|
s|s|r| j                  d!"       t        | |||||||      }|s%|s#|
s!| j                  d|j                         #       |st        j                  j                  |      sgd }d}| j                  r| j                  d$       n|s|
s| j                  d$       |s|
r|j                          d}n]|j                  |%       d}nG|j!                         r|s| j                  d$       | j                  rL|j#                         r|s| j                  d&"       |j%                         \  }}}| j                  |||'       d}|j'                         }|j#                         }|	r|j)                         xs |}|r)|r|j+                         xs |}n| j                  d&"       |j-                         xs |}nS|r;d }|j                  d%       d}|j#                         }|r)|r'|j+                          n| j                  d(|d)"       |r| j                  d$       y |j'                         }xs }| j                  ||'       y )*Npath)typestrTname
repository)ro   requiredaliasesHEADrM   r   )ro   defaultrt   boolF)ro   rv   )ro   no_log)r   r   r   r4   r   r   
executabler7   r/   rA   r9   in_placer   )argument_specsupports_check_moder   r   r   r4   r   r   ry   svnr7   r9   r/   rA   rz   r   )LANGLC_MESSAGESzXthe destination directory must be specified unless checkout=no, update=no, and export=no)msg)changedafter)r   )r4   z.ERROR: modified files exist in the repository.)r   beforer   zERROR: z< folder already exists, but its not a subversion repository.)r   dictparamsget_bin_pathr   run_command_environ_update	fail_jsonr	   	exit_jsonrQ   osrn   exists
check_moder/   r7   r-   r[   rh   rO   r9   rC   rA   )r   r   r   r   r4   r   r   r   r7   r9   r/   rA   rz   r   localer}   r   
local_modsfiles_changedcheckr   r   s                         r   mainr   $  s   6"54&,9OPufui>PQFE2u%uT2(VU3vt4VT2VT2vu5VU;
 !!F& == D== D}}Z(HMM'"E}}Z(H}}Z(H}}\*Nf.A.A%.NH]]8$F]]8$F}}Z(H]]8$F}}Z(H]]#34N &f-F(,&f(MF%X6wx
VT48XxQ_
`C&c.E.E.GHRWW^^D)
T*U+(LLN MJJUJ# M		 U+!!#E  %U V#&#3#3#5 E65U6G!!#'')
JJL9MM #

 =  %U V

5	4 '')
%JJLhlno&  "-:uEr   __main__)
__future__r   DOCUMENTATIONEXAMPLESRETURNr   r;   ansible.module_utils.basicr   "ansible.module_utils.common.localer   #ansible.module_utils.compat.versionr   objectr	   r   ri   rl   r   r   <module>r      s[    #dL( 
 	 	 4 G <T" T"n`FF zF r   