From fd9524fd8436a7959788f4b33788284807764f55 Mon Sep 17 00:00:00 2001 From: Mathias Klette Date: Thu, 2 May 2013 13:42:39 +0200 Subject: [PATCH] debian_build, common_code: cleanup #4 - new figlet() function instead of using subprocess --- common_code.py | 10 ++++++++-- debian_build.py | 37 ++++++++++++++----------------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/common_code.py b/common_code.py index dc560c4..23f49d7 100755 --- a/common_code.py +++ b/common_code.py @@ -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', diff --git a/debian_build.py b/debian_build.py index 75125ff..5ac743f 100755 --- a/debian_build.py +++ b/debian_build.py @@ -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() -- 2.39.5