]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
add dput stuff
authorRobin Wittler <robin.wittler@profitbricks.com>
Mon, 8 Aug 2011 13:15:41 +0000 (15:15 +0200)
committerRobin Wittler <robin.wittler@profitbricks.com>
Mon, 8 Aug 2011 13:15:41 +0000 (15:15 +0200)
testgit_build.py

index 99384b8dd97d40abb38fee6eca8f1a875256a91b..db1176867c6d8a3cc14825f75000d20e654183c1 100755 (executable)
@@ -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):