From: Holger Levsen Date: Wed, 14 Sep 2011 08:16:45 +0000 (+0200) Subject: 'merge' in changes from sebastian done in the other repo in another branch X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=e4c00eaecf3d9e8aed05132cbf50a2d0bef1486b;p=profitbricks%2Fjenkins-build-scripts.git 'merge' in changes from sebastian done in the other repo in another branch --- diff --git a/kernel_build.py b/kernel_build.py index a3e4a7b..1f79527 100644 --- a/kernel_build.py +++ b/kernel_build.py @@ -4,34 +4,19 @@ import os import re import sys -import git import atexit import shutil import subprocess import logging -import platform import smtplib from glob import glob from logging import Formatter -from ftplib import FTP -from multiprocessing import cpu_count from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy import Table, Column, Integer, String, MetaData, Sequence from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm.exc import NoResultFound -GIT = '/usr/bin/git' -MAKE_KPKG = '/usr/bin/make-kpkg' -DEFAULT_PARALLEL_JOBS = cpu_count() + 1 - -BUILD_ARCH_MAP = { - 'x86_64': 'amd64', - 'i386': '686' -} - -BUILD_ARCH = BUILD_ARCH_MAP.get(platform.machine(), '686') - CWD = os.environ.get('WORKSPACE') BUILD_NUMBER = os.environ.get('BUILD_NUMBER') BUILD_ID = os.environ.get('BUILD_ID') @@ -42,21 +27,9 @@ GIT_REPO_NAME = os.path.basename(GIT_REPO_PATH) GIT_OLD_ID = os.environ.get('GIT_OLD_ID') GIT_NEW_ID = os.environ.get('GIT_NEW_ID') GIT_BRANCH_NAME = os.environ.get('GIT_BRANCH_NAME') -GIT_REMOTE_BRANCH_NAME = os.path.join('origin', '%s' %(GIT_BRANCH_NAME)) -GIT_TARGET_WORKSPACE = os.path.join( - CWD, - '%s-build%s' %(BUILD_ID, BUILD_NUMBER) -) - -GIT_TARGET_DIR = os.path.join( - GIT_TARGET_WORKSPACE, - os.path.basename(GIT_REPO_PATH) -) GIT_COMMITTER_EMAIL = os.environ.get('GIT_COMMITTER_EMAIL') -KERNEL_CONFIG_PATH = os.path.join(GIT_TARGET_DIR, '.config') -CREG_KERNEL_CONFIG_DELIM = re.compile(ur'\s*=\s*') PERSISTENCE_FILE = os.path.join(CWD, '..', '.persistence') SMTP_SERVER = 'roma.profitbricks.localdomain' SMTP_SUBJECT = 'Kernel build for branch %s, buildnumber %s was %s' @@ -182,13 +155,8 @@ def build_kernel_with_pbuilder(revision, pbuilder_script, dist='stable'): ) logger.info('calling "%s" ...', ' '.join(cmd)) -# ret = cmdobj.wait() ret = os.system('%s' %(' '.join(cmd))) if ret: -# errormsg = 'stdout: %s\n\n\nstderr: %s' %(cmdobj.stdout.read(), -# cmdobj.stderr.read()) -# if not errormsg: -# errormsg = None logger.error( '"%s" returned non-zero (exitcode was: %s).', ' '.join(cmd), @@ -196,33 +164,22 @@ def build_kernel_with_pbuilder(revision, pbuilder_script, dist='stable'): ) return False -# message = cmdobj.stdout.read() -# if not message: -# message = None logger.info( '"%s" returned zero.', ' '.join(cmd)) return True -def read_file(path): - try: - fh = open(path, 'r', 1) - except: - raise - else: - result = dict(enumerate(fh)) - fh.close() - return result - def remove_git_target_workspace(): - try: - shutil.rmtree(GIT_TARGET_WORKSPACE) - except IOError, error: - logger.debug('Got exception with error code: %s', error.errno) - if error.errno == 2: - pass - else: - raise - logger.info('deleted %s' %(GIT_TARGET_WORKSPACE)) + rmpath = '/tmp/%s-build%s' %(BUILD_ID, BUILD_NUMBER) + if os.path.isdir(rmpath): + try: + shutil.rmtree(rmpath) + except IOError, error: + logger.debug('Got exception with error code: %s', error.errno) + if error.errno == 2: + pass + else: + raise + logger.info('deleted %s' %(rmpath)) def exit_ok(): send_email(SMTP_BUILD_SUCCESS) @@ -245,7 +202,7 @@ if __name__ == '__main__': exit_error() if not build_kernel_with_pbuilder( - new_version, 'kernel_inpbuilder.py', + new_version, 'kernel_inpbuilder.py', dist='stable'): exit_error() exit_ok() diff --git a/kernel_inpbuilder.py b/kernel_inpbuilder.py index a39c18b..69dded2 100644 --- a/kernel_inpbuilder.py +++ b/kernel_inpbuilder.py @@ -5,7 +5,6 @@ import os import re import sys import git -import atexit import shutil import subprocess import logging @@ -14,10 +13,10 @@ import smtplib import optparse from glob import glob from logging import Formatter -#from ftplib import FTP +from ftplib import FTP from multiprocessing import cpu_count -__version__ = '0.0.1' +__version__ = '0.0.2' GIT = '/usr/bin/git' MAKE_KPKG = '/usr/bin/make-kpkg' @@ -205,7 +204,7 @@ def build_kernel(revision, parallel_jobs='auto', distcc=False): cmd = [MAKE_KPKG, '-j', '%s' %(parallel_jobs), '--arch', '%s' %(BUILD_ARCH), '--rootcmd', 'fakeroot', '--revision', - '%s' %(revision), '--initrd', '--arch-in-name', 'kernel_debug', + '%s' %(revision), '--initrd', '--arch_in_name', 'kernel_debug', 'kernel_image', 'kernel_source', 'kernel_headers', 'modules'] logger.info('start compile process') @@ -280,21 +279,10 @@ def add_local_version_to_config(kernel_build_revision): return localversion return False -def remove_git_target_workspace(): - try: - shutil.rmtree(GIT_TARGET_WORKSPACE) - except IOError, error: - if error.errno == 2: - pass - else: - raise - logger.info('deleted %s' %(GIT_TARGET_WORKSPACE)) - def exit(retcode): logger.info('Exit with %s', retcode) sys.exit(retcode) - def has_extra_modules(): return os.path.exists(EXTRA_MODULES_PATH) @@ -342,9 +330,6 @@ if __name__ == '__main__': # FIXME: Do we realy need BUILD_URL here? BUILD_URL = os.environ.get('BUILD_URL') or options.build_url - if not BUILD_URL: - logger.error('No build url given') - exit(ERROR) GIT_REPO_PATH = os.environ.get('GIT_REPO_PATH') or options.git_repo_path if not GIT_REPO_PATH: @@ -396,11 +381,10 @@ if __name__ == '__main__': else: logger.info('git clone was not successfull') exit(ERROR) - #atexit.register(remove_git_target_workspace) + if not git_checkout_branch(): exit(ERROR) - #kernel_revision_obj = get_last_kernel_revision_obj() - #new_version = kernel_revision_obj.last_version + 1 + new_version = REVISION try: add_local_version_to_config(new_version) @@ -412,12 +396,6 @@ if __name__ == '__main__': 'updated CONFIG_LOCALVERSION in %s to %s' %(KERNEL_CONFIG_PATH, new_version) ) -# if not update_kernel_revision_obj(kernel_revision_obj, new_version): -# logger.info( -# 'Could not update persistence version to %s for %s' -# %(new_version, GIT_BRANCH_NAME) -# ) -# exit(ERROR) logger.debug('changing dir to %s' %(GIT_TARGET_DIR)) os.chdir(GIT_TARGET_DIR) @@ -430,26 +408,30 @@ if __name__ == '__main__': if not build_kernel(new_version): exit(ERROR) else: - #ftp = FTP( - # 'alexandria.profitbricks.localdomain', - # 'debian-uploader', - # 'vae6tooZe1ec' - #) - - #logger.info('FTP Login on %s successfull' %(ftp.host)) - - #ftp.cwd('squeeze') - #for package in glob( - # os.path.join(GIT_TARGET_WORKSPACE, '*.deb') - #): - # fh = open(package, 'rb', 1) - # ftp.storbinary( - # 'STOR %s' %(os.path.basename(package)), - # fh - # ) - # fh.close() - # logger.info('Successfully uploaded %s' %(package)) - #ftp.quit() + ftp = FTP( + 'alexandria.profitbricks.localdomain', + 'debian-uploader', + 'vae6tooZe1ec' + ) + + logger.info('FTP Login on %s successfull' %(ftp.host)) + + if GIT_BRANCH_NAME.startswith('master-'): + ftp.cwd('stable-proposed-updates') + else: + ftp.cwd('unstable-proposed-updates'); + + for package in glob( + os.path.join(GIT_TARGET_WORKSPACE, '*.deb') + ): + fh = open(package, 'rb', 1) + ftp.storbinary( + 'STOR %s' %(os.path.basename(package)), + fh + ) + fh.close() + logger.info('Successfully uploaded %s' %(package)) + ftp.quit() logger.info('Build successfull') logger.info('dirlist: %s' %(os.listdir(GIT_TARGET_WORKSPACE))) exit(OK)