From: Robin Wittler Date: Thu, 4 Aug 2011 11:59:20 +0000 (+0200) Subject: error handling X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=2a826495fd83da4b5ef4a2a7e3512b5fe37e4ba5;p=profitbricks%2Fjenkins-build-scripts.git error handling --- diff --git a/testgit_build.py b/testgit_build.py index 99656ac..03f4668 100755 --- a/testgit_build.py +++ b/testgit_build.py @@ -105,52 +105,40 @@ def read_file(path): 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)