('%s-build%s' %(BUILD_ID, BUILD_NUMBER))
)
-if GIT_UPSTREAM_BRANCH == 'NONE':
- raise Exception('You must give a GIT_UPSTREAM_BRANCH')
-
-if GIT_DEBIAN_BRANCH == 'NONE':
- GIT_DEBIAN_BRANCH = GIT_UPSTREAM_BRANCH
+#if GIT_UPSTREAM_BRANCH == 'NONE':
+# raise Exception('You must give a GIT_UPSTREAM_BRANCH')
+#
+#if GIT_DEBIAN_BRANCH == 'NONE':
+# GIT_DEBIAN_BRANCH = GIT_UPSTREAM_BRANCH
GIT_TARGET_DIR = os.path.join(
GIT_TARGET_WORKSPACE,
def send_email(result):
smtp = smtplib.SMTP(SMTP_SERVER)
+ if result == SMTP_BUILD_ERROR:
+ SMTP_TEXT += '\nThe filesystem path is: %s' %(GIT_TARGET_WORKSPACE)
msg = (
'From: %s\n' %(SMTP_FROM) +
'To: %s\n' %(GIT_COMMITTER_EMAIL) +
cmd_obj = subprocess.Popen(
cmd,
shell=False,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
+ stdout=sys.stdout,
+ stderr=sys.stderr,
close_fds=True,
cwd=os.path.dirname(DPUT_CF)
)
ret = cmd_obj.wait()
if ret:
- errormsg = cmd_obj.stderr.read()
- if not errormsg:
- errormsg = cmd_obj.stdout.read()
- if not errormsg:
- errormsg = None
message = (
- '"%s" returned non-zero (returned with: %s). Error Msg was: %s'
- %(cmd, ret, errormsg)
+ '"%s" returned non-zero (returned with: %s).'
+ %(' '.join(cmd), ret)
)
logger.debug(message)
raise Exception(message)
- output = cmd_obj.stdout.read() or None
message = (
- '"%s" returned zero. Output was: %s'
- %(cmd, output)
+ '"%s" returned zero.' %(' '.join(cmd))
)
logger.debug(message)
return True
def remove_git_target_workspace():
+ if not os.path.exists(GIT_TRAGET_WORKSPACE):
+ return True
+
try:
cmd = [BIN_SUDO, BIN_RM, '-rf', GIT_TARGET_WORKSPACE]
cmdobj = subprocess.Popen(
shell=False,
cwd='/',
close_fds=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
+ stdout=sys.stdout,
+ stderr=sys.stderr,
env={'':''}
)
logger.debug(
'Trying to call "%s" to delete "%s"'
- %(cmd, GIT_TARGET_WORKSPACE)
+ %(' '.join(cmd), GIT_TARGET_WORKSPACE)
)
ret = cmdobj.wait()
if ret:
- stderr_msg = cmdobj.stderr.read()
- stdout_msg = cmdobj.stdout.read()
_str = (
- 'Cmd "%s" returned non-zero (exitcode: %s). '
- %(cmd, ret) +
- 'Output was: stdout="%s", stderr="%s"'
- %(stdout_msg, stderr_msg)
+ 'Cmd "%s" returned non-zero (exitcode: %s).'
+ %(' '.join(cmd), ret)
)
logger.debug(_str)
raise Exception(_str)
raise
else:
logger.info('deleted %s' %(GIT_TARGET_WORKSPACE))
- return cmdobj
+ return True
def exit_ok():
- remove_git_target_workspace()
send_email(SMTP_BUILD_SUCCESS)
sys.exit(0)
def exit_error():
+ sys.exitfunc = lambda: None
send_email(SMTP_BUILD_ERROR)
sys.exit(1)
logger.info('git clone was not successfull')
exit_error()
- #atexit.register(remove_git_target_workspace)
+ atexit.register(remove_git_target_workspace)
os.chdir(GIT_TARGET_DIR)
- if GIT_UPSTREAM_BRANCH != GIT_DEBIAN_BRANCH:
+ if not GIT_DEBIAN_BRANCH:
+ if GIT_UPSTREAM_BRANCH:
+ GIT_DEBIAN_BRANCH = GIT_UPSTREAM_BRANCH
+ logging.debug(
+ 'setting GIT_DEBIAN_BRANCH to %s',
+ GIT_UPSTREAM_BRANCH
+ )
+ else:
+ logger.error('Could not determine GIT_DEBIAN_BRANCH')
+ exit_error()
+ elif not GIT_UPSTREAM_BRANCH:
+ if GIT_DEBIAN_BRANCH:
+ GIT_UPSTREAM_BRANCH = GIT_DEBIAN_BRANCH
+ logging.debug(
+ 'setting GIT_UPSTREAM_BRANCH to %s',
+ GIT_UPSTREAM_BRANCH
+ )
+ else:
+ logger.error('Could not determine GIT_UPSTREAM_BRANCH')
+ exit_error()
+
+ repo = git.repo.Repo()
+
+ if GIT_DEBIAN_BRANCH != 'master':
git_helper.git_new_branch_from(
GIT_DEBIAN_BRANCH,
os.path.join('origin', GIT_DEBIAN_BRANCH)
)
- repo = git.repo.Repo()
- # hacked by holger
- cmd = ['/usr/bin/git', 'checkout', GIT_UPSTREAM_BRANCH]
- subprocess.check_call(cmd)
-
- 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()
+ pb_version = fh.readline().rstrip()
fh.close()
fh = open('debian/control')
for line in fh:
if line.startswith('Source:'):
pkg_name = line.split(':')[-1].lstrip().rstrip()
+ break
fh.close()
if options.distribution in ('unstable', 'experimental'):
if ret:
raise Exception('git log was not successfull')
- #git_log_output = map(
- # lambda x: x.rstrip(),
- # git_log.stdout.readlines()
- #)
+ else:
+ logger.info('git log was successfull')
cmd = [
'/usr/bin/dch',
'--',
'%s' %(''.join(git_log.stdout.read()))
]
- # '%s' %(git_log_output)
- logger.debug('Trying to call: %s' %(cmd))
+ logger.debug('Trying to call: %s' %(' '.join(cmd)))
dch = subprocess.Popen(
cmd,
shell=False,
close_fds=True,
stdin=git_log.stdout,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
+ stdout=sys.stdout,
+ stderr=sys.stderr,
cwd=os.getcwd()
)
ret = dch.wait()
if ret:
raise Exception(
- 'git dch was not successfull ' +
- 'Error msg was: %s' %(dch.stderr.read())
+ '"%s" returned with exitcode: %s' %(' '.join(cmd), ret)
)
logger.info('debian/changelog written')
- # we need to commit here else git-buildpackage will use the existing debian/changelog...
+ # we need to commit here else git-buildpackage will use the existing debian/changelog...
+ # TODO: Later we should investigate why the "--ignore-new" trick
+ # did not work!
cmd = ['/usr/bin/git', 'add', '-A']
subprocess.check_call(cmd)
cmd = ['/usr/bin/git', 'commit', '-a', '-m', 'add changelog']
cmd,
shell=False,
close_fds=True,
- stdout=sys.stdout,
+ stdout=subprocess.PIPE,
stderr=sys.stderr,
cwd='./'
)
ret = parse_changelog.wait()
if ret:
raise Exception(
- '%s was not successfull, return code was %s ' % (' '.join(cmd), ret)
+ '%s was not successfull, return code was %s ' % (' '.join(cmd), ret)
)
exit_error()
shell=False,
close_fds=True,
stdin=parse_changelog.stdout,
- stdout=sys.stdout,
+ stdout=subprocess.PIPE,
stderr=sys.stderr,
cwd=os.getcwd()
)
ret = grep_dctrl.wait()
if ret:
raise Exception(
- '%s was not successfull, return code was %s ' % (' '.join(cmd), ret)
+ '%s was not successfull, return code was %s ' % (' '.join(cmd), ret)
)
exit_error()
-
- version = grep_dctrl.stdout.read()
- version = version.strip()
- logger.info('version is %s' % (version))
-
- #stdout_msg = parse_changelog.stdout.read()
- #logger.info(stdout_msg)
+ version = grep_dctrl.stdout.readline()
+ version = version.strip()
+ logger.info('Packet version is %s' % (version))
if not GIT_COMMITTER_EMAIL:
for commit in repo.commits():
logger.info('starting git-buildpackage')
ret = gbp.build()
logger.debug(
- 'This is the output of git-buildpackage: \n%s'
+ 'This is the returncode of git-buildpackage: \n%s'
%(ret)
)
if not ret:
pass
exit_error()
else:
- create_dput_cfg()
- changes_file = os.path.join(GIT_TARGET_WORKSPACE, 'build-area/result/', '%s_%s_amd64.changes' % (pkg_name, version))
- dput_package_upload(changes_file)
-
- fh = open(changes_file, 'r')
- logger.info('%s' % (fh.read()))
- fh.close()
-
- #logger.debug(os.listdir('./'))
- #logger.debug(os.listdir('../'))
-
- exit_ok()
-
-#class GitBuildPackage(object):
-# def __init__(self, upstream_branch=None,
-# debian_branch=None, dist=None, arch=None)
-#
-# ftp = FTP(
-# 'alexandria.profitbricks.localdomain',
-# 'debian-uploader',
-# 'vae6tooZe1ec'
-# )
-#
-# logger.info('Log in on %s successfull' %(ftp.host))
-#
-# ftp.cwd('experimental')
-# 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()
-# exit_ok()
+ try:
+ create_dput_cfg()
+ changes_file = os.path.join(GIT_TARGET_WORKSPACE, 'build-area/result/', '%s_%s_amd64.changes' % (pkg_name, version))
+ dput_package_upload(changes_file)
+
+ fh = open(changes_file, 'r')
+ logger.info('%s' % (fh.read()))
+ fh.close()
+ exit_ok()
+ except Exception, error:
+ logger.exception(error)
+ exit_error()