]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
git_buildpackage: make env and command properties, usable by debian_build
authorMathias Klette <mathias.klette@profitbricks.com>
Wed, 5 Jun 2013 17:28:17 +0000 (19:28 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Wed, 5 Jun 2013 17:28:17 +0000 (19:28 +0200)
lib/git_buildpackage.py

index e03e48e3eb24901b9fe1000649a2a432e46d4d5a..b84faeb716665ec57743aff0d4b9e53f6bc30824 100644 (file)
@@ -12,8 +12,17 @@ BIN_GIT_BUILDPACKAGE = '/usr/bin/git-buildpackage'
 BIN_SUDO = '/usr/bin/sudo'
 
 class GitBuildPackage(object):
-    def __init__(self, upstream_branch=None,
-            debian_branch=None, dist=None, arch=None, pb_suite=None, git_commit_id=None):
+    def __init__(self, 
+            upstream_branch=None,
+            debian_branch=None, 
+            dist=None,
+            arch=None, 
+            pb_suite=None,
+            git_commit_id=None
+            ):
+        '''
+        TODO
+        '''
         self.upstream_branch = upstream_branch
         self.debian_branch = debian_branch
         self.dist = dist
@@ -21,8 +30,23 @@ class GitBuildPackage(object):
         self.pb_suite = pb_suite
         self.git_commit_id = git_commit_id
 
-    def build(self):
-        cmd = [
+    @property
+    def env(self):
+        '''
+        TODO
+        '''
+        result = os.environ
+        result['DIST'] = self.dist
+        result['PB_SUITE'] = self.pb_suite
+        result['GIT_COMMIT_ID'] = self.git_commit_id
+        return result
+
+    @property
+    def command(self):
+        '''
+        TODO
+        '''
+        result = [
                 BIN_SUDO,
                 BIN_GIT_BUILDPACKAGE,
                 '--git-upstream-branch=%s' %(self.upstream_branch),
@@ -30,6 +54,12 @@ class GitBuildPackage(object):
                 '--git-ignore-new',
                 '--debbuildopts', '-b'    # don't build source packages... see directly below
         ]
+        return result
+
+    def build(self):
+        '''
+        TODO
+        '''
         # if we would build orig.tar.gz we would need to be able to access 
         # them later, which we probably could achieve with using pristine-tar 
         # and storing that in the git repo - but this has the downside that 
@@ -40,33 +70,28 @@ class GitBuildPackage(object):
         # So in summary, it would be expensive and buys as nothing, as we 
         # can always generate the source from said git repos...
 
-        env = os.environ
-        env['DIST'] = self.dist
-        env['PB_SUITE'] = self.pb_suite
-        env['GIT_COMMIT_ID'] = self.git_commit_id
-
         logger.debug(
                 'Trying to call "%s" with environment export %s'
                 %(
-                    ' '.join(cmd),
+                    ' '.join(self.command),
                     ' '.join(
                         map(
                             lambda x: '%s="%s"' %(x[0], x[1]),
-                            env.iteritems()
+                            self.env.iteritems()
                         )
                     )
                 )
         )
 
         cmdobj = subprocess.Popen(
-                cmd,
+                self.command,
                 shell=False,
                 close_fds=True,
                 #stdout=subprocess.PIPE,
                 #stderr=subprocess.PIPE,
                 stdout=sys.stdout,
                 stderr=sys.stderr,
-                env=env,
+                env=self.env,
                 cwd=os.getcwd(),
         )
 
@@ -74,17 +99,8 @@ class GitBuildPackage(object):
         if ret:
             logger.error(
                     '"%s" returned non-zero. exitcode was: %s'
-                    %(' '.join(cmd), ret)
+                    %(' '.join(self.command), 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 ret