removed logger, removed superfluous mkdir

reviewable/pr18780/r1
Dane Summers 12 years ago
parent fc9fd48843
commit 648f740b95

@ -26,12 +26,6 @@
# requires subversion on the client. # requires subversion on the client.
import re import re
import logging
logger = logging.getLogger('subversion')
#hdlr = logging.FileHandler('/tmp/subversion.log')
#hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
#logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
# TODO test scenarios: # TODO test scenarios:
# hacking/test-module -m library/subversion ; cat /tmp/subversion.log # hacking/test-module -m library/subversion ; cat /tmp/subversion.log
@ -50,25 +44,16 @@ logger.setLevel(logging.DEBUG)
def get_version(dest): def get_version(dest):
''' samples the version of the git repo ''' ''' samples the version of the git repo '''
logger.debug('get_version')
os.chdir(dest) os.chdir(dest)
cmd = "svn info | grep Revision" cmd = "svn info | grep Revision"
logger.debug(cmd)
return os.popen(cmd).read() return os.popen(cmd).read()
def checkout(repo, dest): def checkout(repo, dest):
''' makes a new svn repo if it does not already exist ''' ''' makes a new svn repo if it does not already exist '''
logger.debug('checkout')
try:
os.makedirs(os.path.dirname(dest))
except:
pass
cmd = "svn co %s %s" % (repo, dest) cmd = "svn co %s %s" % (repo, dest)
logger.debug(cmd)
cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = cmd.communicate() (out, err) = cmd.communicate()
rc = cmd.returncode rc = cmd.returncode
logger.debug('rc, error: %s, %s ' % (rc,err))
return (rc, out, err) return (rc, out, err)
def reset(dest): def reset(dest):
@ -78,10 +63,8 @@ def reset(dest):
TODO throw away non-tracked files? TODO throw away non-tracked files?
-- svn st | grep '?' | awk '{print $2}' | xargs rm -rf -- svn st | grep '?' | awk '{print $2}' | xargs rm -rf
''' '''
logger.debug('reset')
os.chdir(dest) os.chdir(dest)
cmd = "svn revert -R ." cmd = "svn revert -R ."
logger.debug(cmd)
cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = cmd.communicate() (out, err) = cmd.communicate()
rc = cmd.returncode rc = cmd.returncode
@ -89,14 +72,12 @@ def reset(dest):
def update(module, dest, version): def update(module, dest, version):
''' update an existing svn repo ''' ''' update an existing svn repo '''
logger.debug('update')
os.chdir(dest) os.chdir(dest)
cmd = '' cmd = ''
if version != 'HEAD': if version != 'HEAD':
cmd = "svn up -r %s" % version cmd = "svn up -r %s" % version
else: else:
cmd = "svn up" cmd = "svn up"
logger.debug(cmd)
cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = cmd.communicate() (out, err) = cmd.communicate()
rc = cmd.returncode rc = cmd.returncode
@ -123,10 +104,8 @@ def main():
# else update. # else update.
before = None before = None
if not os.path.exists("%s/.svn" % (dest)): if not os.path.exists("%s/.svn" % (dest)):
logger.debug('.svn exists')
(rc, out, err) = checkout(repo, dest) (rc, out, err) = checkout(repo, dest)
if rc != 0: if rc != 0:
logger.debug('checkout failure')
module.fail_json(msg=err) module.fail_json(msg=err)
else: else:
# else do an update # else do an update
@ -136,9 +115,7 @@ def main():
module.fail_json(msg=err) module.fail_json(msg=err)
# handle errors from checkout or pull # handle errors from checkout or pull
logger.debug('ERROR: %s' % (err.find('ERROR') != -1))
if err.find('ERROR') != -1: if err.find('ERROR') != -1:
logger.debug('err:\n%s' % (err))
module.fail_json(msg=err) module.fail_json(msg=err)
# switch to version specified regardless of whether # switch to version specified regardless of whether
@ -154,7 +131,7 @@ def main():
if before != after: if before != after:
changed = True changed = True
module.exit_json(changed=changed, before=before, after=after, msg="fell thru the bag") module.exit_json(changed=changed, before=before, after=after, msg="")
# include magic from lib/ansible/module_common.py # include magic from lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>> #<<INCLUDE_ANSIBLE_MODULE_COMMON>>

Loading…
Cancel
Save