Implemented --out commandline option. Fixes #200.
authorZhang Qiang <qiang.z.zhang@intel.com>
Fri, 3 Aug 2012 06:35:34 +0000 (14:35 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Fri, 3 Aug 2012 06:39:34 +0000 (14:39 +0800)
--out specifies existing directory for the RPMs. gbs copies
result RPMs to it when build is finished successfully.
As build is run with root privileges we can't move RPMs because of
possible access restrictions, so we're copying them.

gitbuildsys/cmd_build.py
tools/gbs

index 7a8572879201b9991763a93f086709abf508f9c7..66488de4500b09bd5633fe548c59e4f4287b6d50 100644 (file)
@@ -24,6 +24,8 @@ import re
 import subprocess
 import tempfile
 import urllib2
+import glob
+import shutil
 from urlparse import urlsplit, urlunsplit
 
 import msger
@@ -245,6 +247,12 @@ def do(opts, args):
         raise errors.Usage('--commit can\'t be specified together with '\
                            '--include-all')
 
+    if opts.out:
+        if not os.path.exists(opts.out):
+            msger.error('Output directory %s doesn\'t exist' % opts.out)
+        if not os.path.isdir(opts.out):
+            msger.error('%s is not a directory' % opts.out)
+
     try:
         repo = RpmGitRepository(workdir)
     except GitRepositoryError, err:
@@ -404,9 +412,16 @@ def do(opts, args):
         if subprocess.call(cmd):
             msger.error('rpmbuild fails')
         else:
+            out_dir = os.path.join(build_root, 'home/abuild/rpmbuild/RPMS/')
+            if opts.out:
+                for fpath in glob.glob(out_dir + '/*/*.rpm'):
+                    shutil.copy(fpath, opts.out)
+                msger.info('RPMs have been copied from %s to %s' \
+                           % (out_dir, opts.out))
+                out_dir = os.path.abspath(opts.out)
             msger.info('The buildroot was: %s' % build_root)
-            msger.info('Binaries RPM packages can be found here:\n     %s/%s' % \
-                       (build_root, 'home/abuild/rpmbuild/RPMS/'))
+            msger.info('Binaries RPM packages can be found here:'\
+                       '\n     %s' % out_dir)
             msger.info('Done')
     except KeyboardInterrupt:
         msger.info('keyboard interrupt, killing build ...')
index 3b1c9f537f5ff6e2d51285245883299e60e8dc95..8199f5336482bf152aed82cef7cc8a2b7f2c7fdd 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -222,6 +222,10 @@ class Gbs(cmdln.Cmdln):
                   dest='include_all',
                   help='Uncommitted changes and untracked files would be '\
                        'included while generating tar ball')
+    @cmdln.option('--out',
+                  default=None,
+                  dest='out',
+                  help='Output directory for RPMs')
     @cmdln.option('--debuginfo',
                   action='store_true',
                   default=False,