]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
fix the rm bug
authorRobin Wittler <robin.wittler@profitbricks.com>
Thu, 4 Aug 2011 11:37:08 +0000 (13:37 +0200)
committerRobin Wittler <robin.wittler@profitbricks.com>
Thu, 4 Aug 2011 11:37:08 +0000 (13:37 +0200)
testgit_build.py

index cc2c6ff7e86cafba9d79b11789462222ccf1074c..511ad7334f6277c9c01e046e738b5726d7834308 100755 (executable)
@@ -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'