From 50975c9e13552a76420035d522a3a8725af98b7e Mon Sep 17 00:00:00 2001 From: Robin Wittler Date: Mon, 8 Aug 2011 15:15:41 +0200 Subject: [PATCH] add dput stuff --- testgit_build.py | 75 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/testgit_build.py b/testgit_build.py index 99384b8..db11768 100755 --- a/testgit_build.py +++ b/testgit_build.py @@ -9,20 +9,22 @@ import git 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 @@ -72,6 +74,15 @@ SMTP_BUILD_SUCCESS = 'SUCCESSFULL' 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( @@ -103,6 +114,55 @@ def read_file(path): 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] @@ -202,9 +262,12 @@ if __name__ == '__main__': 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): -- 2.39.5