def remove_git_target_workspace():
try:
- shutil.rmtree(GIT_TARGET_WORKSPACE)
- except IOError, error:
- logger.debug('IOError happend. errno is: %s' %(error.errno))
- if error.errno == errno.ENOENT:
- logger.debug(
- '"%s" does not exists - and can be ignored'
- %(GIT_TARGET_WORKSPACE)
- )
- elif error.errno == errno.EACCES:
- logger.debug(
- 'Unsufficient rights to delete "%s"'
- %(GIT_TARGET_WORKSPACE)
- )
- cmd = [BIN_SUDO, BIN_RM, '-rvf', GIT_TARGET_WORKSPACE]
- cmdobj = subprocess.Popen(
- cmd,
- shell=False,
- cwd='/',
- close_fds=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env={'':''}
- )
-
- logger.debug(
- 'Trying to call "%s" to delete "%s"'
- %(cmd, GIT_TARGET_WORKSPACE)
- )
+ cmd = [BIN_SUDO, BIN_RM, '-rvf', GIT_TARGET_WORKSPACE]
+ cmdobj = subprocess.Popen(
+ cmd,
+ shell=False,
+ cwd='/',
+ close_fds=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ env={'':''}
+ )
- ret = cmdobj.wait()
+ logger.debug(
+ 'Trying to call "%s" to delete "%s"'
+ %(cmd, GIT_TARGET_WORKSPACE)
+ )
- if ret:
- stderr_msg = cmdobj.stderr.read()
- stdout_msg = cmdobj.stdout.read()
- _str = (
- 'Cmd "%s" returned non-zero (exitcode: %s). '
- %(cmd, ret) +
- 'Output was: stdout="%s", stderr="%s"'
- %(stdout_msg, stderr_msg)
- )
- logger.debug(_str)
- raise Exception(_str)
- return cmdobj
- else:
- raise
- logger.info('deleted %s' %(GIT_TARGET_WORKSPACE))
+ ret = cmdobj.wait()
+ if ret:
+ stderr_msg = cmdobj.stderr.read()
+ stdout_msg = cmdobj.stdout.read()
+ _str = (
+ 'Cmd "%s" returned non-zero (exitcode: %s). '
+ %(cmd, ret) +
+ 'Output was: stdout="%s", stderr="%s"'
+ %(stdout_msg, stderr_msg)
+ )
+ logger.debug(_str)
+ raise Exception(_str)
+ return cmdobj
+ except Exception, error:
+ logger.exception(error)
+ raise
+ else:
+ logger.info('deleted %s' %(GIT_TARGET_WORKSPACE))
def exit_ok():
send_email(SMTP_BUILD_SUCCESS)