import errno
import atexit
import shutil
-import subprocess
import logging
-import platform
import smtplib
-from lib import git_helper
-from lib import git_buildpackage
+import platform
+import subprocess
from glob import glob
-from logging import Formatter
from ftplib import FTP
+from lib import git_helper
+from logging import Formatter
+from lib import git_buildpackage
from multiprocessing import cpu_count
+from ConfigParser import SafeConfigParser
GIT = '/usr/bin/git'
BIN_RM = '/bin/rm'
BIN_SUDO = '/usr/bin/sudo'
+BIN_DPUT = '/usr/bin/dput'
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)
+DPUT_OPTIONS = {
+ 'fqdn': 'minden.profitbricks.localdomain',
+ 'method': 'scp',
+ 'login': 'jenkins',
+ 'incoming': '/srv/debian-repository/incoming',
+ 'allow_unsigned_uploads': 0
+}
+DPUT_CF = os.path.join(GIT_TARGET_WORKSPACE, 'dput.cf')
+
log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s'
formatter = Formatter(log_format)
logging.basicConfig(
fh.close()
return result
+def dput_package_upload(changes_path):
+ cmd = [BIN_DPUT, '-c', '%s' %(DPUT_CF), '%s' %(changes_path)]
+ logger.debug(
+ 'Trying to execute: "%s"'
+ %(cmd)
+ )
+ cmd_obj = subprocess.Popen(
+ cmd,
+ shell=False,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ close_fds=True,
+ cwd=os.path.dirname(DPUT_CF)
+ )
+
+ ret = cmd_obj.wait()
+
+ if ret:
+ errormsg = cmd_obj.stderr.read()
+ if not errormsg:
+ errormsg = cmd_obj.stdout.read()
+ if not errormsg:
+ errormsg = None
+ message = (
+ '"%s" returned non-zero (returned with: %s). Error Msg was: %s'
+ %(cmd, ret, errormsg)
+ )
+ logger.debug(message)
+ raise Exception(message)
+
+ output = cmd_obj.stdout.read() or None
+ message = (
+ '"%s" returned zero. Output was: %s'
+ %(cmd, ret, output)
+ )
+ logger.debug(message)
+ return True
+
+def create_dput_cfg():
+ fh = open(DPUT_CF, 'w')
+ config = SafeConfigParser()
+ config.add_section('origin')
+ for option, value in DPUT_OPTIONS.iteritems():
+ config.set('origin', option, value)
+ config.write(fh)
+ fh.close()
+ return True
+
+
def remove_git_target_workspace():
try:
cmd = [BIN_SUDO, BIN_RM, '-rvf', GIT_TARGET_WORKSPACE]
logger.info('starting git-buildpackage')
ret = gbp.build()
logger.debug(
- 'This is the return value of git-buildpackage: %s'
+ 'This is the output of git-buildpackage: \n%s'
%(ret)
)
+ create_dput_cfg()
+ dput_package_upload()
+
exit_ok()
#class GitBuildPackage(object):