Merge branch 'subversion_export' of https://github.com/maniaplanet/ansible into maniaplanet-subversion_export

This commit is contained in:
James Cammarata 2014-03-25 21:25:50 -05:00
commit 98c62f6b1c

View file

@ -70,11 +70,20 @@ options:
description: description:
- Path to svn executable to use. If not supplied, - Path to svn executable to use. If not supplied,
the normal mechanism for resolving binary paths will be used. the normal mechanism for resolving binary paths will be used.
export:
required: false
default: False
version_added: "1.5"
description:
- If True, do export instead of checkout/update.
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Checkout subversion repository to specified folder. # Checkout subversion repository to specified folder.
- subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/src/checkout - subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/src/checkout
# Export subversion directory to folder
- subversion: repo=svn+ssh://an.example.org/path/to/repo dest=/src/export export=True
''' '''
import re import re
@ -110,6 +119,10 @@ class Subversion(object):
def checkout(self): def checkout(self):
'''Creates new svn working directory if it does not already exist.''' '''Creates new svn working directory if it does not already exist.'''
self._exec(["checkout", "-r", self.revision, self.repo, self.dest]) self._exec(["checkout", "-r", self.revision, self.repo, self.dest])
def export(self, force=False):
'''Export svn repo to directory'''
self._exec(["export", "-r", self.revision, self.repo, self.dest])
def switch(self): def switch(self):
'''Change working directory's repo.''' '''Change working directory's repo.'''
@ -163,6 +176,7 @@ def main():
username=dict(required=False), username=dict(required=False),
password=dict(required=False), password=dict(required=False),
executable=dict(default=None), executable=dict(default=None),
export=dict(default=False, required=False),
), ),
supports_check_mode=True supports_check_mode=True
) )
@ -174,6 +188,7 @@ def main():
username = module.params['username'] username = module.params['username']
password = module.params['password'] password = module.params['password']
svn_path = module.params['executable'] or module.get_bin_path('svn', True) svn_path = module.params['executable'] or module.get_bin_path('svn', True)
export = module.params['export']
os.environ['LANG'] = 'C' os.environ['LANG'] = 'C'
svn = Subversion(module, dest, repo, revision, username, password, svn_path) svn = Subversion(module, dest, repo, revision, username, password, svn_path)
@ -183,7 +198,10 @@ def main():
local_mods = False local_mods = False
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) module.exit_json(changed=True)
svn.checkout() if not export:
svn.checkout()
else:
svn.export()
elif os.path.exists("%s/.svn" % (dest, )): elif os.path.exists("%s/.svn" % (dest, )):
# Order matters. Need to get local mods before switch to avoid false # Order matters. Need to get local mods before switch to avoid false
# positives. Need to switch before revert to ensure we are reverting to # positives. Need to switch before revert to ensure we are reverting to