From e39f146fba4e8a7964dbd97d8152f94891124811 Mon Sep 17 00:00:00 2001 From: Robin Wittler Date: Wed, 3 Aug 2011 15:18:57 +0200 Subject: [PATCH] add buildpackage --- lib/git_buildpackage.py | 60 +++++++++++++++++++++++++++++++++++++++++ testgit_build.py | 5 +++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 lib/git_buildpackage.py diff --git a/lib/git_buildpackage.py b/lib/git_buildpackage.py new file mode 100644 index 0000000..8e8fc85 --- /dev/null +++ b/lib/git_buildpackage.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import logging +import subprocess +logger = logging.getLogger(__file__) + + +BIN_GIT_BUILDPACKAGE = '/usr/bin/git-buildpackage' +BIN_SUDO = '/usr/bin/sudo' + +# sudo DIST=squeeze git-buildpackage --git-upstream-branch=master +# --git-debian-branch=debian --git-tag +class GitBuildPackage(object): + def __init__(self, upstream_branch=None, + debian_branch=None, dist=None, arch=None): + self.upstream_branch = upstream_branch + self.debian_branch = debian_branch + self.dist = dist + self.arch = arch + + + def build(self): + cmd = [ + BIN_SUDO, + GIT_BUILDPACKAGE, + '--git-upstream-branch=%s' %(self.upstream_branch), + '--git-debian-branch=%s' %(self.debian_branch) + ] + + env = os.environ + env['DIST'] = self.dist + + cmd_obj = subprocess.Popen( + cmd, + shell=False, + close_fds=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, + cwd=os.getcwd(), + ) + + 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 + return cmdobj.stdout.read() or 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 diff --git a/testgit_build.py b/testgit_build.py index 9122589..8a4767d 100755 --- a/testgit_build.py +++ b/testgit_build.py @@ -46,8 +46,11 @@ GIT_TARGET_WORKSPACE = os.path.join( '%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 = 'debian' + GIT_DEBIAN_BRANCH = GIT_UPSTREAM_BRANCH GIT_TARGET_DIR = os.path.join( GIT_TARGET_WORKSPACE, -- 2.39.5