waf Provide release signing capability in 'waf dist'
authorAndrew Bartlett <abartlet@samba.org>
Fri, 28 May 2010 10:24:47 +0000 (20:24 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 28 May 2010 11:59:08 +0000 (21:59 +1000)
This helps ensure the release is signed correctly - the .tar file, not
the .tar.gz must be signed, and it's easy to forget this.

Andrew Bartlett

buildtools/wafsamba/samba_dist.py
buildtools/wafsamba/wscript

index 30e82620afdae83aa7a6f1db4bc29b8796150fab..05c5aaaeb6995f6ed3d7742559a7b21fbfb6b2e1 100644 (file)
@@ -1,7 +1,7 @@
 # customised version of 'waf dist' for Samba tools
 # uses git ls-files to get file lists
 
-import Utils, os, sys, tarfile, stat, Scripting, Logs
+import Utils, os, sys, tarfile, gzip, stat, Scripting, Logs, Options
 from samba_utils import *
 
 dist_dirs = None
@@ -86,9 +86,14 @@ def dist(appname='',version=''):
         sys.exit(1)
 
     dist_base = '%s-%s' % (appname, version)
-    dist_name = '%s.tar.gz' % (dist_base)
 
-    tar = tarfile.open(dist_name, 'w:gz')
+    if Options.options.SIGN_RELEASE:
+        dist_name = '%s.tar' % (dist_base)
+        tar = tarfile.open(dist_name, 'w')
+    else:
+        dist_name = '%s.tar.gz' % (dist_base)
+        tar = tarfile.open(dist_name, 'w:gz')
+
     blacklist = dist_blacklist.split()
 
     for dir in dist_dirs.split():
@@ -126,7 +131,30 @@ def dist(appname='',version=''):
 
     tar.close()
 
-    Logs.info('Created %s' % dist_name)
+    if Options.options.SIGN_RELEASE:
+        try:
+            os.unlink(dist_name + '.asc')
+        except OSError:
+            pass
+
+        cmd = "gpg --detach-sign --armor " + dist_name
+        os.system(cmd)
+        uncompressed_tar = open(dist_name, 'rb')
+        compressed_tar = gzip.open(dist_name + '.gz', 'wb')
+        while 1:
+            buffer = uncompressed_tar.read(1048576)
+            if buffer:
+                compressed_tar.write(buffer)
+            else:
+                break
+        uncompressed_tar.close()
+        compressed_tar.close()
+        os.unlink(dist_name)
+        Logs.info('Created %s.gz %s.asc' % (dist_name, dist_name))
+        dist_name = dist_name + '.gz'
+    else:
+        Logs.info('Created %s' % dist_name)
+
     return dist_name
 
 
index 7bb2baa0380a6201980a6e09e8c53993cfe01f84..bad65cac245e2a92f3bcb623c5e821a7e94bb65d 100644 (file)
@@ -130,6 +130,14 @@ def set_options(opt):
                   help=SUPPRESS_HELP,
                   action='store_true', dest='AUTOCONF_DISABLE_DEPENDENCY_TRACKING', default=False)
 
+    gr = opt.option_group('dist options')
+    gr.add_option('--sign-release',
+                   help='sign the release tarball created by waf dist',
+                   action='store_true', dest='SIGN_RELEASE')
+    gr.add_option('--tag',
+                   help='tag release in git at the same time',
+                   type='string', action='store', dest='TAG_RELEASE')
+
 
 @wafsamba.runonce
 def configure(conf):