]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build, common_code: cleanup #4 - new figlet() function instead of using subprocess
authorMathias Klette <mathias.klette@profitbricks.com>
Thu, 2 May 2013 11:42:39 +0000 (13:42 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Thu, 2 May 2013 11:42:39 +0000 (13:42 +0200)
common_code.py
debian_build.py

index dc560c4e0b0c30d2e15e198ae890e12df1dc14d2..23f49d7c4a325f103ab49639ebb34cff1595c18d 100755 (executable)
@@ -8,6 +8,11 @@ import platform
 import sys
 from logging import Formatter
 
+def figlet(text = None):
+    if text != None:
+        cmd = [BIN_FIGLET, '-t', text]
+        subprocess.check_call(cmd)
+
 def logger_init(
         log_name = __file__,
         log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s',
@@ -42,11 +47,12 @@ def exit_error():
 ENV = os.environ
 ENV.setdefault('ARGV',' '.join(sys.argv))
 
+BIN_DPUT = '/usr/bin/dput'
+BIN_FIGLET = '/usr/bin/figlet-figlet'
 BIN_GIT = '/usr/bin/git'
+BIN_MAKE_KPKG = '/usr/bin/make-kpkg'
 BIN_RM = '/bin/rm'
 BIN_SUDO = '/usr/bin/sudo'
-BIN_DPUT = '/usr/bin/dput'
-BIN_MAKE_KPKG = '/usr/bin/make-kpkg'
 
 BUILD_ARCH_MAP = {
     'x86_64': 'amd64',
index 75125ffc8efc8d690129dd4013313f374553374f..5ac743f6fe48305fcf01bc17e5486d8f6da63a4e 100755 (executable)
@@ -203,11 +203,14 @@ if __name__ == '__main__':
 
     # cleanup existing *orig.tar.gz
     if os.path.isdir(BUILD_AREA):
-        files = [os.path.join(BUILD_AREA,file) for file in fnmatch.filter(os.listdir(BUILD_AREA),'*.orig.tar.gz')]
+        files = [os.path.join(BUILD_AREA, file) 
+                 for file in fnmatch.filter(os.listdir(BUILD_AREA), '*.orig.tar.gz')]
+
         if len(files) > 0:
             logger.debug('Previous upstream tarball(s) found: %s' %( files ))
             cmd = [BIN_SUDO, BIN_RM, '-v']
             cmd.extend(files)
+            logger.debug('Executing "%s" ...' %(' '.join(cmd)))
             cmdobj = subprocess.Popen(
                     cmd,
                     shell=False,
@@ -216,13 +219,12 @@ if __name__ == '__main__':
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT,
                     env={'':''}
-                    )
+                    ).wait()
 
-            logger.debug('Calling "%s":' %(' '.join(cmd)))
-            ret = cmdobj.wait()
             for line in cmdobj.stdout.readlines():
                 logger.debug('%s' %(line.strip()))
-            logger.debug('Cmd returned with status %d' %(cmdobj.returncode))
+
+            logger.debug('Returned with status %d' %(cmdobj.returncode))
 
     # gather details from changelog
     cmd = ['dpkg-parsechangelog']
@@ -295,8 +297,6 @@ if __name__ == '__main__':
         raise Exception(message)
         exit_error()
 
-    DPUT_OPTIONS = DPUT_OPTIONS_DEFAULT
-
     # get the current commit id
     current_commit = git_helper.git_get_commit_id()
 
@@ -310,8 +310,6 @@ if __name__ == '__main__':
         elif GIT_BRANCH_NAME.startswith('feature/') or GIT_BRANCH_NAME.startswith('poc/') or GIT_BRANCH_NAME.startswith('bugfix/'):
             changelog_distro ='dev-'+ GIT_BRANCH_NAME.replace("/","-")
             version = '%s~experimental%s+%s+%s' %(version, daily_date, ENV['BUILD_NUMBER'], current_commit[0:7])
-            # these uploads should go to a different repo:
-            DPUT_OPTIONS = DPUT_OPTIONS_DEV
         else:
             #FIXME: enable this once Florian acks.
             #if GIT_REPO_PATH.startswith('/srv/git/dev/'):
@@ -417,11 +415,9 @@ if __name__ == '__main__':
 
 
     logger.info('dist: %s' %(pb_suite))
-    cmd = ['figlet-figlet', '-t', 'dist: %s' %(pb_suite)]
-    subprocess.check_call(cmd)
+    figlet('dist: %s' %(pb_suite))
     logger.info('version: %s' %(version))
-    cmd = ['figlet-figlet', '-t', 'version: %s' %(version)]
-    subprocess.check_call(cmd)
+    figlet('version: %s' %(version))
 
     gbp = git_buildpackage.GitBuildPackage(
             upstream_branch=GIT_UPSTREAM_BRANCH,
@@ -496,15 +492,12 @@ if __name__ == '__main__':
         else:
             logger.debug('value of NO_UPLOAD: %s' % NO_UPLOAD)
         logger.info('dist: %s' %(pb_suite))
-        cmd = ['figlet-figlet', '-t', 'dist: %s' %(pb_suite)]
-        subprocess.check_call(cmd)
+        figlet('dist: %s' %(pb_suite))
         logger.info('version: %s' %(version))
-        cmd = ['figlet-figlet', '-t', 'version: %s' %(version)]
-        subprocess.check_call(cmd)
+        figlet('version: %s' %(version))
 
     except Exception, error:
-        cmd = ['figlet-figlet', '-t', 'upload to reprepro failed:']
-        subprocess.check_call(cmd)
+        figlet('upload to reprepro failed:')
         logger.exception(error)
         exit_error()
     BUILD_END = datetime.datetime.now()
@@ -514,8 +507,7 @@ if __name__ == '__main__':
         try:
             package_instances = add_package_instances("profitbricks", ENV['JOB_NAME'], ENV['BUILD_NUMBER'], changes_file, version, BUILD_START, BUILD_END)
         except Exception as error:
-            cmd = ['figlet-figlet', '-t', 'CIDB problem:']
-            subprocess.check_call(cmd)
+            figlet('CIDB problem:')
             logger.error("package instance not added to DB", exc_info=error)
             exit_error()
         # only trigger liveboots automatically for builds from master+hotfix/* branches
@@ -526,7 +518,6 @@ if __name__ == '__main__':
                 logger.debug("liveboot request failed")
     # finally
     logger.info('---------------------------------------------------------------------------------------------------------')
-    cmd = ['figlet-figlet', '-t', 'Success!!!']
-    subprocess.check_call(cmd)
+    figlet('Success!!!')
     exit_ok()