From: Robin Wittler Date: Tue, 9 Aug 2011 15:31:27 +0000 (+0200) Subject: add distribution feature X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=5b5fc2c69fcbb2ccc7f4196750313faf3e001018;p=profitbricks%2Fjenkins-build-scripts.git add distribution feature --- diff --git a/build.py b/build.py index 22d678b..2434b05 100755 --- a/build.py +++ b/build.py @@ -11,6 +11,8 @@ import atexit import shutil import logging import smtplib +import optparse +import datetime import platform import subprocess from glob import glob @@ -215,6 +217,19 @@ def exit_error(): send_email(SMTP_BUILD_ERROR) sys.exit(1) +def getopts(): + usage = '%prog [options]' + parser = optparse.OptionParser(usage=usage, version='%prog 0.1') + parser.add_option( + '--distribution', + dest='distribution', + choices = ['stable', 'testing', 'unstable', 'experimental'], + default='unstable', + help='The pkg distribution. Default: %default' + ) + + return parser.parse_args() + if __name__ == '__main__': logger.debug( 'Initialised with Enviroment: %s' @@ -228,6 +243,7 @@ if __name__ == '__main__': ) ) logging.getLogger('lib.git_helper').setLevel(logging.DEBUG) + options, args = getopts() if git_helper.git_clone_remote_repository(GIT_REPO_PATH, GIT_TARGET_DIR): logger.info('git clone was successfull') else: @@ -248,6 +264,73 @@ if __name__ == '__main__': if repo.active_branch != 'master' and GIT_DEBIAN_BRANCH != 'master': git_helper.git_checkout_branch(GIT_DEBIAN_BRANCH) + pb_version_path = os.path.join('debian', 'pb_version') + + if not os.path.exists(pb_version_path): + pb_version = '0.0' + else: + fh = open(pb_version_path) + pb_version = fh.read().rstrip() + fh.close() + + if options.distribution in ('unstable', 'experimental'): + daily_date = datetime.datetime.now().strftime('%Y%m%d-%H%M%S') + version = '%s-%s' %(pb_version, daily_date) + os.unlink('debian/changelog') + fh = open('debian/control') + for line in fh: + if line.startswith('Source:'): + pkg_name = line.split(':')[-1].lstrip().rstrip() + fh.close() + + cmd = ['/usr/bin/git', 'log'] + git_log = subprocess.Popen( + cmd, + shell=False, + close_fds=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd='./' + ) + + ret = git_log.wait() + + if ret: + raise Exception('git log was not successfull') +# git_log_output = map( +# lambda x: x.rstrip(), +# cmd_obj.stdout.readlines() +# ) + + + cmd = [ + '/usr/bin/dch', + '--create', + '--package', + pkg_name, + '--newversion', + '%s' %(version), + '--distribution', + '%s' %(options.distribution), + '--', + '%s' %(git_log.stdout.read()) + ] + + dch = subprocess.Popen( + cmd, + shell=True, + close_fds=True, + stdin=git_log.stdout, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd='./' + ) + ret = dch.wait() + + if ret: + raise Exception('git dch was not successfull') + logger.info('debian/changelog written') + if not GIT_COMMITTER_EMAIL: for commit in repo.commits(): if commit.id == GIT_NEW_ID: diff --git a/lib/git_buildpackage.py b/lib/git_buildpackage.py index e02a6bf..5a8fc3a 100644 --- a/lib/git_buildpackage.py +++ b/lib/git_buildpackage.py @@ -26,7 +26,8 @@ class GitBuildPackage(object): BIN_SUDO, BIN_GIT_BUILDPACKAGE, '--git-upstream-branch=%s' %(self.upstream_branch), - '--git-debian-branch=%s' %(self.debian_branch) + '--git-debian-branch=%s' %(self.debian_branch), + '--git-ignore-new' ] env = os.environ