From: Robin Wittler Date: Thu, 4 Aug 2011 11:37:08 +0000 (+0200) Subject: fix the rm bug X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=82e6e9ad8d84368295bb3c1ec3bc1fa23b5ffc21;p=profitbricks%2Fjenkins-build-scripts.git fix the rm bug --- diff --git a/testgit_build.py b/testgit_build.py index cc2c6ff..511ad73 100755 --- a/testgit_build.py +++ b/testgit_build.py @@ -6,6 +6,7 @@ import re import pwd import sys import git +import errno import atexit import shutil import subprocess @@ -20,6 +21,8 @@ from ftplib import FTP from multiprocessing import cpu_count GIT = '/usr/bin/git' +BIN_RM = '/bin/rm' +BIN_SUDO = '/usr/bin/sudo' MAKE_KPKG = '/usr/bin/make-kpkg' DEFAULT_PARALLEL_JOBS = cpu_count() + 1 @@ -69,14 +72,6 @@ SMTP_BUILD_SUCCESS = 'SUCCESSFULL' SMTP_BUILD_ERROR = 'NOT SUCCESSFULL' SMTP_FROM = '%s@profitbricks.com' %(pwd.getpwuid(os.geteuid()).pw_name) -#logger = logging.getLogger(sys.argv[0]) -#logger.setLevel(logging.DEBUG) -#stream_handler = logging.StreamHandler() -#stream_handler.setLevel(logging.DEBUG) -#formatter = Formatter('%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s') -#stream_handler.setFormatter(formatter) -#logger.addHandler(stream_handler) - log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s' formatter = Formatter(log_format) logging.basicConfig( @@ -85,10 +80,6 @@ logging.basicConfig( ) logger = logging.getLogger(__file__) logger.setLevel(logging.DEBUG) -#stream_handler = logging.StreamHandler() -#stream_handler.setLevel(logging.DEBUG) -#stream_handler.setFormatter(formatter) -#logger.addHandler(stream_handler) def send_email(result): smtp = smtplib.SMTP(SMTP_SERVER) @@ -116,8 +107,46 @@ def remove_git_target_workspace(): try: shutil.rmtree(GIT_TARGET_WORKSPACE) except IOError, error: - if error.errno == 2: - pass + 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) + ) + + 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 else: raise logger.info('deleted %s' %(GIT_TARGET_WORKSPACE)) @@ -132,7 +161,7 @@ def exit_error(): if __name__ == '__main__': logger.debug( - 'Initialised with that items: %s' + 'Initialised with Enviroment: %s' %( ', '.join( map( @@ -181,6 +210,7 @@ if __name__ == '__main__': arch='amd64' ) + logger.info('starting git-buildpackage') ret = gbp.build() logger.debug( 'This is the return value of git-buildpackage: %s'