]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
add distribution feature
authorRobin Wittler <robin.wittler@profitbricks.com>
Tue, 9 Aug 2011 15:31:27 +0000 (17:31 +0200)
committerRobin Wittler <robin.wittler@profitbricks.com>
Tue, 9 Aug 2011 15:31:27 +0000 (17:31 +0200)
build.py
lib/git_buildpackage.py

index 22d678b0c3945720113f7426585be0bc1c3001cd..2434b0559b899c68f9eda4996decb0ecbe50adfb 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -11,6 +11,8 @@ import atexit
 import shutil
 import logging
 import smtplib
+import optparse
+import datetime
 import platform
 import subprocess
 from glob import glob
@@ -215,6 +217,19 @@ def exit_error():
     send_email(SMTP_BUILD_ERROR)
     sys.exit(1)
 
+def getopts():
+    usage = '%prog [options]'
+    parser = optparse.OptionParser(usage=usage, version='%prog 0.1')
+    parser.add_option(
+            '--distribution',
+            dest='distribution',
+            choices = ['stable', 'testing', 'unstable', 'experimental'],
+            default='unstable',
+            help='The pkg distribution. Default: %default'
+    )
+
+    return parser.parse_args()
+
 if __name__ == '__main__':
     logger.debug(
             'Initialised with Enviroment: %s'
@@ -228,6 +243,7 @@ if __name__ == '__main__':
             )
     )
     logging.getLogger('lib.git_helper').setLevel(logging.DEBUG)
+    options, args = getopts()
     if git_helper.git_clone_remote_repository(GIT_REPO_PATH, GIT_TARGET_DIR):
         logger.info('git clone was successfull')
     else:
@@ -248,6 +264,73 @@ if __name__ == '__main__':
     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()
+        fh.close()
+
+    if options.distribution in ('unstable', 'experimental'):
+        daily_date = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
+        version = '%s-%s' %(pb_version, daily_date)
+        os.unlink('debian/changelog')
+        fh = open('debian/control')
+        for line in fh:
+            if line.startswith('Source:'):
+                pkg_name = line.split(':')[-1].lstrip().rstrip()
+        fh.close()
+
+        cmd = ['/usr/bin/git', 'log']
+        git_log = subprocess.Popen(
+                cmd,
+                shell=False,
+                close_fds=True,
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                cwd='./'
+        )
+
+        ret = git_log.wait()
+
+        if ret:
+            raise Exception('git log was not successfull')
+#        git_log_output = map(
+#                lambda x: x.rstrip(),
+#                cmd_obj.stdout.readlines()
+#        )
+
+
+        cmd = [
+                '/usr/bin/dch',
+                '--create',
+                '--package',
+                pkg_name,
+                '--newversion',
+                '%s' %(version),
+                '--distribution',
+                '%s' %(options.distribution),
+                '--',
+                '%s' %(git_log.stdout.read())
+        ]
+
+        dch = subprocess.Popen(
+                cmd,
+                shell=True,
+                close_fds=True,
+                stdin=git_log.stdout,
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                cwd='./'
+        )
+        ret = dch.wait()
+
+        if ret:
+            raise Exception('git dch was not successfull')
+        logger.info('debian/changelog written')
+
     if not GIT_COMMITTER_EMAIL:
         for commit in repo.commits():
             if commit.id == GIT_NEW_ID:
index e02a6bf62ae270de8479d9deafa4405d2ac7f3ad..5a8fc3a4dd625f762c984c7ec4296e4721940c7c 100644 (file)
@@ -26,7 +26,8 @@ class GitBuildPackage(object):
                 BIN_SUDO,
                 BIN_GIT_BUILDPACKAGE,
                 '--git-upstream-branch=%s' %(self.upstream_branch),
-                '--git-debian-branch=%s' %(self.debian_branch)
+                '--git-debian-branch=%s' %(self.debian_branch),
+                '--git-ignore-new'
         ]
 
         env = os.environ