logger.info('deleted %s' %(GIT_TARGET_WORKSPACE))
return True
+
+
def exit_ok():
send_email(SMTP_BUILD_SUCCESS)
sys.exit(0)
os.path.join('origin', GIT_DEBIAN_BRANCH)
)
+ cleanup_files = ('.gbp.conf', 'debian/gbp.conf', '.git/gbp.conf')
+ result = git_helper.git_cleanup_branch(cleanup_files)
+ result = git_helper.git_commit(
+ "Cleanup branch for correct builds.",
+ cleanup_files
+ )
+
pb_version_path = os.path.join('debian', 'pb_version')
if not os.path.exists(pb_version_path):
# -*- coding: utf-8 -*-
import os
+import shutil
import git
import logging
import subprocess
return True
return False
+def git_cleanup_branch(paths):
+ """
+ Delete files in current checkout of branch. Pass in an iterable list
+ of paths to delete.
+
+ This is sometimes necessary to ensure our build chain is working as
+ expected.
+
+ I.e. git-buildpackage tries to find it's configuration in also from
+ the branch being used. That way our central configuration is ignored
+ and builds fail.
+ """
+ result = dict()
+ for path in paths:
+ try:
+ if not os.path.exists(path):
+ logger.info(
+ 'Cleanup of %s impossible: Not existing'
+ %(path)
+ )
+ continue
+
+ if os.path.isdir(path):
+ cmd=shutil.rmtree
+ elif os.path.isfile(path):
+ cmd=os.unlink
+ else:
+ raise Exception(
+ 'Cleanup of %s impossible: Unknown file type'
+ %(path)
+ )
+ continue
+
+ logger.debug(
+ 'Trying to remove %s'
+ %(path)
+ )
+ cmd(path)
+ except Exception, error:
+ result.setdefault(path, error)
+ else:
+ result.setdefault(path, True)
+ return result
+
+
+def git_commit(message, paths=("-a",)):
+ """
+ Create a new commit with a given message.
+
+ You can also pass an interable object with the files to be commited. If
+ ommited, option "-a" is used.
+ """
+ cmd = [
+ GIT,
+ 'commit',
+ '-m "%s"' %(message),
+ '%s' %(' '.join(paths))
+ ]
+ cmdobj = subprocess.Popen(
+ cmd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ shell=False,
+ env={'':''},
+ cwd='/',
+ close_fds=True
+ )
+
+ logger.info('commit changes for %s' %(' '.join(paths)))
+ logger.debug(
+ 'calling "%s" for commit' %(' '.join(cmd))
+ )
+ ret = cmdobj.wait()
+ if ret:
+ error_str = cmdobj.stderr.read()
+ if not error_str:
+ error_str = cmdobj.stdout.read()
+ if not error_str:
+ error_str = 'No Error Msg found'
+ logger.error(
+ '%s returned with %s. Output was: %s'
+ %(' '.join(cmd), ret, error_str)
+ )
+ return False
+ logger.debug('changes for %s commited' %(' '.join(paths)))
+ return True
+
# vim: autoindent smartindent tabstop=4 expandtab shiftwidth=4 softtabstop=4 nu enc=utf-8 cinwords=if,elif,else,for,while,try,except,finally,def,class