import pwd
import sys
import git
+import errno
import atexit
import shutil
import subprocess
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
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(
)
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)
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))
if __name__ == '__main__':
logger.debug(
- 'Initialised with that items: %s'
+ 'Initialised with Enviroment: %s'
%(
', '.join(
map(
arch='amd64'
)
+ logger.info('starting git-buildpackage')
ret = gbp.build()
logger.debug(
'This is the return value of git-buildpackage: %s'