]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
add buildpackage
authorRobin Wittler <robin.wittler@profitbricks.com>
Wed, 3 Aug 2011 13:18:57 +0000 (15:18 +0200)
committerRobin Wittler <robin.wittler@profitbricks.com>
Wed, 3 Aug 2011 13:18:57 +0000 (15:18 +0200)
lib/git_buildpackage.py [new file with mode: 0644]
testgit_build.py

diff --git a/lib/git_buildpackage.py b/lib/git_buildpackage.py
new file mode 100644 (file)
index 0000000..8e8fc85
--- /dev/null
@@ -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
index 9122589fab6a5217a3f1f2297520bfd46156a649..8a4767d3a261591bff2ab05b6a37fc024045a82a 100755 (executable)
@@ -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,