Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
f2893b64
Commit
f2893b64
authored
12 years ago
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1746 from njharman/subversion
Subverion module improvements
parents
5d31e8d1
ddc0507f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
103 deletions
+102
-103
library/subversion
+102
-103
No files found.
library/subversion
View file @
f2893b64
...
@@ -23,8 +23,12 @@ DOCUMENTATION = '''
...
@@ -23,8 +23,12 @@ DOCUMENTATION = '''
module: subversion
module: subversion
short_description: Deploys a subversion repository.
short_description: Deploys a subversion repository.
description:
description:
-
This module is really simple, it checks out from the given branch of a repo or at a particular tag
.
-
Deploy given repository URL / revision to dest
.
version_added: "0.7"
version_added: "0.7"
author: Dane Summers, njharman@gmail.com
notes:
- Requres I(svn) to be installed on the client.
requirements: []
options:
options:
repo:
repo:
description:
description:
...
@@ -36,92 +40,102 @@ options:
...
@@ -36,92 +40,102 @@ options:
- Absolute path where the repository should be deployed.
- Absolute path where the repository should be deployed.
required: true
required: true
default: null
default: null
revision:
description:
- Specific revision to checkout.
required: false
default: HEAD
force:
force:
description:
description:
- If C(yes),
any modified files in the working repository will be discarded. If C(no), this
module will fail if it encounters modified files.
- If C(yes),
modified files will be discarded. If C(no),
module will fail if it encounters modified files.
required: false
required: false
default: yes
default: yes
choices: [ "yes", "no" ]
choices: [ "yes", "no" ]
username:
description:
- --username parameter passed to svn.
required: false
default: null
password:
description:
- --password parameter passed to svn.
required: false
default: null
examples:
examples:
- code: "subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/src/checkout"
- code: "subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/src/checkout"
description: Export subversion repository in a specified folder
description: Checkout subversion repository to specified folder.
notes:
- Requires I(subversion) and I(grep) on the client.
requirements: [ ]
author: Dane Summers
'''
'''
import
re
import
re
def
get_version
(
dest
):
''' samples the version of the git repo '''
os
.
chdir
(
dest
)
cmd
=
"svn info"
revision
=
filter
(
lambda
l
:
re
.
search
(
'Revision'
,
l
)
!=
None
,
os
.
popen
(
cmd
)
.
read
()
.
splitlines
())
url
=
filter
(
lambda
l
:
re
.
search
(
'^URL'
,
l
)
!=
None
,
os
.
popen
(
cmd
)
.
read
()
.
splitlines
())
return
[
revision
[
0
],
url
[
0
]]
def
checkout
(
repo
,
dest
):
''' makes a new svn repo if it does not already exist '''
cmd
=
"svn co
%
s
%
s"
%
(
repo
,
dest
)
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
cmd
.
communicate
()
rc
=
cmd
.
returncode
return
(
rc
,
out
,
err
)
def
switch
(
repo
,
dest
):
class
Subversion
(
object
):
''' makes a new svn repo if it does not already exist '''
def
__init__
(
self
,
module
,
dest
,
repo
,
revision
,
username
,
password
):
cmd
=
"svn sw
%
s
%
s"
%
(
repo
,
dest
)
self
.
module
=
module
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
self
.
dest
=
dest
(
out
,
err
)
=
cmd
.
communicate
()
self
.
repo
=
repo
self
.
revision
=
revision
self
.
username
=
username
self
.
password
=
password
def
_exec
(
self
,
args
):
bits
=
[
"svn --non-interactive --no-auth-cache"
,
]
if
self
.
username
:
bits
.
append
(
"--username '
%
s'"
%
self
.
username
)
if
self
.
password
:
bits
.
append
(
"--password '
%
s'"
%
self
.
password
)
bits
.
append
(
args
)
cmd
=
subprocess
.
Popen
(
' '
.
join
(
bits
),
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
cmd
.
communicate
()
rc
=
cmd
.
returncode
rc
=
cmd
.
returncode
return
(
rc
,
out
,
err
)
if
rc
!=
0
:
self
.
module
.
fail_json
(
msg
=
err
)
def
has_local_mods
(
dest
):
return
out
.
splitlines
()
os
.
chdir
(
dest
)
cmd
=
"svn status"
def
checkout
(
self
):
lines
=
os
.
popen
(
cmd
)
.
read
()
.
splitlines
()
'''Creates new svn working directory if it does not already exist.'''
filtered
=
filter
(
lambda
c
:
re
.
search
(
'^
\\
?.*$'
,
c
)
==
None
,
lines
)
self
.
_exec
(
"checkout -r
%
s '
%
s' '
%
s'"
%
(
self
.
revision
,
self
.
repo
,
self
.
dest
))
return
len
(
filtered
)
>
0
def
switch
(
self
):
def
reset
(
dest
,
force
):
'''Change working directory's repo.'''
'''
# switch to ensure we are pointing at correct repo.
Reset the repo:
self
.
_exec
(
"switch '
%
s' '
%
s'"
%
(
self
.
repo
,
self
.
dest
))
force: if true, then remove any local modifications. Else, fail if there are local modifications
'''
def
update
(
self
):
if
has_local_mods
(
dest
):
'''Update existing svn working directory.'''
if
force
:
self
.
_exec
(
"update -r
%
s '
%
s'"
%
(
self
.
revision
,
self
.
dest
))
cmd
=
"svn revert -R ."
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
def
revert
(
self
):
(
out
,
err
)
=
cmd
.
communicate
()
'''Revert svn working directory.'''
rc
=
cmd
.
returncode
self
.
_exec
(
"revert -R '
%
s'"
%
self
.
dest
)
return
(
rc
,
out
,
err
)
else
:
def
get_revision
(
self
):
return
(
-
1
,
"ERROR: modified files exist in the repository."
,
""
)
'''Revision and URL of subversion working directory.'''
return
(
0
,
""
,
""
)
text
=
'
\n
'
.
join
(
self
.
_exec
(
"info '
%
s'"
%
self
.
dest
))
rev
=
re
.
search
(
r'^Revision:.*$'
,
text
,
re
.
MULTILINE
)
.
group
(
0
)
def
update
(
module
,
dest
,
version
):
url
=
re
.
search
(
r'^URL:.*$'
,
text
,
re
.
MULTILINE
)
.
group
(
0
)
''' update an existing svn repo '''
return
rev
,
url
os
.
chdir
(
dest
)
cmd
=
''
def
has_local_mods
(
self
):
if
version
!=
'HEAD'
:
'''True if revisioned files have been added or modified. Unrevisioned files are ignored.'''
cmd
=
"svn up -r
%
s"
%
version
lines
=
self
.
_exec
(
"status '
%
s'"
%
self
.
dest
)
else
:
# Match only revisioned files, i.e. ignore status '?'.
cmd
=
"svn up"
regex
=
re
.
compile
(
r'^[^?]'
)
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
# Has local mods if more than 0 modifed revisioned files.
(
out
,
err
)
=
cmd
.
communicate
()
return
len
(
filter
(
regex
.
match
,
lines
))
>
0
rc
=
cmd
.
returncode
return
(
rc
,
out
,
err
)
# ===========================================
# ===========================================
def
main
():
def
main
():
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
dest
=
dict
(
required
=
True
),
dest
=
dict
(
required
=
True
),
repo
=
dict
(
required
=
True
,
aliases
=
[
'name'
]),
repo
=
dict
(
required
=
True
,
aliases
=
[
'name'
,
'repository'
]),
revision
=
dict
(
default
=
'HEAD'
),
revision
=
dict
(
default
=
'HEAD'
,
aliases
=
[
'rev'
]),
force
=
dict
(
default
=
'yes'
,
choices
=
[
'yes'
,
'no'
],
aliases
=
[
'force'
])
force
=
dict
(
default
=
'yes'
,
choices
=
[
'yes'
,
'no'
]),
username
=
dict
(
required
=
False
),
password
=
dict
(
required
=
False
),
)
)
)
)
...
@@ -129,48 +143,33 @@ def main():
...
@@ -129,48 +143,33 @@ def main():
repo
=
module
.
params
[
'repo'
]
repo
=
module
.
params
[
'repo'
]
revision
=
module
.
params
[
'revision'
]
revision
=
module
.
params
[
'revision'
]
force
=
module
.
boolean
(
module
.
params
[
'force'
])
force
=
module
.
boolean
(
module
.
params
[
'force'
])
username
=
module
.
params
[
'username'
]
password
=
module
.
params
[
'password'
]
rc
,
out
,
err
,
status
=
(
0
,
None
,
None
,
None
)
svn
=
Subversion
(
module
,
dest
,
repo
,
revision
,
username
,
password
)
# if there is no .svn folder, do a checkout
if
not
os
.
path
.
exists
(
dest
):
# else update.
before
=
None
before
=
None
local_mods
=
False
local_mods
=
False
if
not
os
.
path
.
exists
(
"
%
s/.svn"
%
(
dest
)):
svn
.
checkout
()
if
os
.
path
.
exists
(
dest
):
elif
os
.
path
.
exists
(
"
%
s/.svn"
%
(
dest
,
)):
module
.
fail_json
(
msg
=
"
%
s folder already exists, but its not a subversion repository."
%
(
dest
))
# Order matters. Need to get local mods before switch to avoid false
# positives. Need to switch before revert to ensure we are reverting to
# correct repo.
before
=
svn
.
get_revision
()
local_mods
=
svn
.
has_local_mods
()
svn
.
switch
()
if
local_mods
:
if
force
:
svn
.
revert
()
else
:
else
:
(
rc
,
out
,
err
)
=
checkout
(
repo
,
dest
)
module
.
fail_json
(
msg
=
"ERROR: modified files exist in the repository."
)
if
rc
!=
0
:
svn
.
update
()
module
.
fail_json
(
msg
=
err
)
else
:
else
:
local_mods
=
has_local_mods
(
dest
)
module
.
fail_json
(
msg
=
"ERROR:
%
s folder already exists, but its not a subversion repository."
%
(
dest
,
))
# else do an update
before
=
get_version
(
dest
)
(
rc
,
out
,
err
)
=
reset
(
dest
,
force
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
(
rc
,
out
,
err
)
=
switch
(
repo
,
dest
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
# handle errors from switch or pull
if
err
.
find
(
'ERROR'
)
!=
-
1
:
module
.
fail_json
(
msg
=
err
)
# switch to version specified regardless of whether
# we cloned or pulled
(
rc
,
out
,
err
)
=
update
(
module
,
dest
,
revision
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
# determine if we changed anything
after
=
get_version
(
dest
)
changed
=
False
if
before
!=
after
or
local_mods
:
changed
=
True
after
=
svn
.
get_revision
()
changed
=
before
!=
after
or
local_mods
module
.
exit_json
(
changed
=
changed
,
before
=
before
,
after
=
after
)
module
.
exit_json
(
changed
=
changed
,
before
=
before
,
after
=
after
)
# include magic from lib/ansible/module_common.py
# include magic from lib/ansible/module_common.py
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment