#!/usr/bin/env python
# -*- coding: utf-8 -*-
-#
-# Achtung: gewachsener code, den man mal wirklich - wenn zeit ist - aufraeumen sollte.
-#
-# wirklich. wirklich. wirklich.
-#
-# mehr kommentare waeren auch gut. wirklich gut.
-
# import standards
import datetime
import fileinput
import git
import optparse
import os
-import platform
-import pwd
import re
-import shutil
import subprocess
import sys
-import time
from ConfigParser import SafeConfigParser
-from multiprocessing import cpu_count
from pprint import pformat
# import 3rd parties
# jenkins environment - parameters
ENV.setdefault('NO_UPLOAD','')
-ENV.setdefault('DISTRIBUTION','squeeze')
+#ENV.setdefault('DISTRIBUTION','squeeze')
#GIT_REPO_PATH = ENV['GIT_REPO_PATH']
# local constants
BUILD_START = datetime.datetime.now()
-DEFAULT_PARALLEL_JOBS = cpu_count() + 1
-JOB_URL = 'http://jenkins:80/job/%(flavour)s/buildWithParameters?token=BuildIt&'
-JOB_DELAY = '0sec'
AUTO_CHANGELOG_REPONAMES = (
'ri-docs',
'so-docs',
'infrastructure-docs',
'storage-docs',
- )
+)
STABLE_DISTRIBUTIONS = (
'stable',
'production',
'production-proposed-updates'
- )
+)
STABLE_BRANCHES_RE = re.compile(
- '^(origin/)?(master|hotfix/.*)$')
+ '^(origin/)?(master|hotfix/.*)$'
+)
UNSTABLE_BRANCHES_RE = re.compile(
- '^(origin/)?(develop|pre-staging|release/.*)$')
+ '^(origin/)?(develop|pre-staging|release/.*)$'
+)
EXPERIMENTAL_BRANCHES_RE = re.compile(
- '^(origin/)?(experimental|integration|(feature|poc|bugfix)/.*)$')
+ '^(origin/)?(experimental|integration|(feature|poc|bugfix)/.*)$'
+)
COMMIT_TRIGGER_BRANCHES_RE = re.compile(
'^(origin/)?(feature/.*)$')
return parser.parse_args()
if __name__ == '__main__':
- logger.debug('Environment:\n%s' %(pformat(ENV)))
+ logger.debug('Environment:\n{env}'.format(env=pformat(ENV)))
# Act I: prepare variables
# .. command line arguments
# Act II: make decissions
# compatibility until call_jenkins was replaced
- if ENV['DISTRIBUTION'] not in ('squeeze','wheezy'):
+ if curr_dist not in ('squeeze','wheezy'):
logger.warn('Compatibility Mode: Change distribution {old} => {new}.'.format(
- old = ENV['DISTRIBUTIONS'],
+ old = curr_dist,
new = 'squeeze'
))
- ENV['DISTRIBUTION'] = 'squeeze'
+ curr_dist = 'squeeze'
if re.match(COMMIT_TRIGGER_BRANCHES_RE, ENV['GIT_BRANCH']):
do_triggers = True
))
exit_error()
new_dist = 'stable'
- new_version = '{version}'.format(version = curr_version)
- pb_suite = 'master-' + ENV['DISTRIBUTION']
- reprepro_base = '/srv/pb-' + ENV['DISTRIBUTION']
+ new_version = curr_version
+ pb_suite = 'master-{dist}'.format(dist=curr_dist)
+ reprepro_base = '/srv/pb-{dist}'.format(dist=curr_dist)
# replace valid debian version chars that are invalid for git tagging
- new_tag = curr_version.replace('~','_')
- new_tag = new_tag.replace(':',',')
+ new_tag = curr_version.replace('~', '_').replace(':', ',')
# .. only take care of changelog automation if we want it to
# FIXME: this must be reponame in ...
if ENV['GIT_BRANCH'] in AUTO_CHANGELOG_REPONAMES:
build = ENV['BUILD_NUMBER'],
commit = curr_commit_id[0:7],
)
- pb_suite = 'develop-' + ENV['DISTRIBUTION']
+ pb_suite = 'develop-{dist}'.format(dist=curr_dist)
reprepro_base = '/srv/pb-' + ENV['DISTRIBUTION']
# reset actions
# .. always include successful build packages into CIDB
- if ENV['DISTRIBUTION'] == 'squeeze':
+ if curr_dist == 'squeeze':
do_cidb = True
elif re.match(EXPERIMENTAL_BRANCHES_RE, ENV['GIT_BRANCH']):
))
exit_error()
- new_dist = 'dev-' + local_branch.replace("/","-")
+ new_dist = 'dev-{0}'.format(ENV['GIT_BRANCH'].replace("/", "-"))
new_version = '{version}~experimental{date}+{build}+{commit}'.format(
version = curr_version,
date = daily_date,
build = ENV['BUILD_NUMBER'],
commit = curr_commit_id[0:7],
)
- pb_suite = 'experimental-' + ENV['DISTRIBUTION']
+ pb_suite = 'experimental-{dist}'.format(dist=curr_dist)
reprepro_base = '/srv/dev-' + ENV['DISTRIBUTION']
else:
gitrepo.git.fetch('--force','--prune').strip()
gitrepo.git.reset('--hard','HEAD').strip()
gitrepo.git.execute(['sudo','git','clean','-fdx']).strip()
- gitrepo.git.branch('-D','%s' %(local_branch),with_exceptions=False).strip()
+ gitrepo.git.branch(
+ '-D',
+ '{branch}'.format(branch=local_branch),
+ with_exceptions=False
+ ).strip()
# .. and re-checkout the requested branch
- logger.info('Checkout branch %s.' %(remote_branch))
+ logger.info('Checkout branch {branch}.'.format(branch=remote_branch))
gitrepo.git.checkout(
- '-b','%s' %(local_branch),
- '%s' %(remote_branch),
- ).strip()
- logger.debug('Status is now:\n%s' %(gitrepo.git.status().strip()))
+ '-b',
+ '{lbranch}'.format(lbranch=local_branch),
+ '{rbranch}'.format(rbranch=remote_branch),
+ ).strip()
+ logger.debug('Status is now:\n{status}'.format(
+ status=gitrepo.git.status().strip()
+ ))
# .. and also 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'
- )]
+ for file in fnmatch.filter(
+ os.listdir(BUILD_AREA), '*.orig.tar.gz'
+ )
+ ]
if len(files) > 0:
logger.info('Delete previous upstream tarball(s)')
cmd = [
BIN_DCH,
'--newversion',
- '%s' %(new_version),
+ '{version}'.format(version=new_version),
'--force-bad-version',
'--distribution',
- '%s' %(new_dist),
+ '{dist}'.format(dist=new_dist),
'--force-distribution',
'--preserve',
'--no-auto-nmu',
'--',
'Generated by Jenkins build of commit {commit}'.format(
commit = curr_commit_id[0:7]
- ),
- ]
+ ),
+ ]
- logger.debug('Executing "%s" ...' %(' '.join(cmd)))
+ logger.debug('Executing "{command}" ...'.format(command=' '.join(cmd)))
dch = subprocess.Popen(
cmd,
shell=False,
stdout=sys.stdout,
stderr=sys.stderr,
cwd=os.getcwd()
- )
+ )
dch.stdin.write('\n')
ret = dch.wait()
if ret:
raise Exception(
- '"%s" returned with exitcode: %s' %(' '.join(cmd), ret))
+ '"{command}" returned with exitcode: {code}'.format(
+ command=' '.join(cmd),
+ code=ret
+ )
+ )
else:
logger.info('Changelog updated by Jenkins using debian_build.py!')
# TODO: use changelog python libs instead of DCH calls, see above
cl = changelog.Changelog()
cl.parse_changelog(open('debian/changelog'))
- logger.info('New changelog:\n\n%s' %(
- ''.join([block.__str__() for block in cl._blocks[0:2]])))
+ logger.info('New changelog:\n\n{changelog}'.format(
+ changelog=''.join([block.__str__() for block in cl._blocks[0:2]]))
+ )
# ACT IV: preparations are done, let's build
gbp = git_buildpackage.GitBuildPackage(
upstream_branch = local_branch,
debian_branch = local_branch,
- dist = ENV['DISTRIBUTION'],
+ dist = curr_dist,
arch = 'amd64',
pb_suite = pb_suite,
git_commit_id = curr_commit_id[0:7]
# .. now handle the result
if ret:
logger.error(
- 'git-buildpackage failed with exitcode %d' % ret)
+ 'git-buildpackage failed with exitcode {code}'.format(code=ret))
figlet('Build failed')
exit_error()
else:
try:
if os.path.exists(reports_file):
for cmd in (['/bin/tar', 'xzvf', reports_file, '-C', ENV['WORKSPACE']],
- ['/usr/bin/sudo' , '/bin/rm', '-v', reports_file]):
+ ['/usr/bin/sudo', '/bin/rm', '-v', reports_file]):
if subprocess.check_call(cmd) == 0:
logger.info(cmd + ' succeeded.')
else:
figlet('Tagging failed')
exit_error()
- logger.info('Tagged as "%s".' % new_tag)
+ logger.info('Tagged as "{tag}".'.format(tag=new_tag))
figlet('Tagging OK')
# .. and upload
new_version = new_version.split(":", 1)[1]
# construct path for changes file
- changes_file = os.path.join(
+ changes_file = os.path.join(
ENV['WORKSPACE'],
'../build-area/result/',
'{name}_{version}_amd64.changes'.format(
name = curr_name,
version = new_version,
- )
)
+ )
# display changes file
fh = open(changes_file, 'r')
- logger.info('Contents of %s\n%s' %(changes_file, fh.read()))
+ logger.info('Content of {file}\n{content}'.format(
+ file=changes_file,
+ content=fh.read()
+ ))
fh.close()
# upload changes file
if not do_cidb:
figlet('CIDB skipped')
else:
- package_instances=[]
+ package_instances = []
try:
package_instances = add_package_instances(
"profitbricks",
new_version,
BUILD_START,
BUILD_END,
- )
+ )
figlet('CIDB OK')
except Exception as error: