New option for creating a git-meta file
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 1 Apr 2014 11:51:58 +0000 (14:51 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 1 Apr 2014 12:15:14 +0000 (15:15 +0300)
Add a new 'git-meta' option for writing metadata about the exported
treeish into a text file in json format. The argument for the option is
the filename to write into.

NOTE! Be careful with the filename: the service fails if the filename
already exists in the exported files.

Change-Id: I7e7c1ce6559ac7ef27ea5fda1619c280cdcc76f0
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
obs_service_gbp/command.py
tests/test_obs_service_gbp.py

index 895811d..c474ef2 100644 (file)
@@ -30,6 +30,7 @@ from gbp.scripts.buildpackage_rpm import main as gbp_rpm
 
 from obs_service_gbp import LOGGER, gbplog
 from obs_service_gbp_utils import GbpServiceError, fork_call, sanitize_uid_gid
+from obs_service_gbp_utils import write_treeish_meta
 from gbp_repocache import CachedRepo, CachedRepoError
 import gbp_repocache
 
@@ -170,6 +171,9 @@ def parse_args(argv):
                                                'spec file')
     parser.add_argument('--config', default=default_configs, action='append',
                         help='Config file to use, can be given multiple times')
+    parser.add_argument('--git-meta', metavar='FILENAME',
+                        help='Write data about the exported revision into '
+                             'FILENAME in json format')
     args = parser.parse_args(argv)
     args.outdir = os.path.abspath(args.outdir)
     return args
@@ -196,4 +200,14 @@ def main(argv=None):
         return 1
 
     # Run GBP
-    return gbp_export(repo, args, config)
+    ret = gbp_export(repo, args, config)
+
+    # Write git meta file
+    if not ret and args.git_meta:
+        try:
+            write_treeish_meta(repo.repo, args.revision, args.outdir,
+                               args.git_meta)
+        except GbpServiceError as err:
+            LOGGER.error(err)
+            ret = 1
+    return ret
index 76ee6be..66cfb30 100644 (file)
@@ -19,6 +19,7 @@
 """Tests for the git-buildpackage OBS source service"""
 
 import grp
+import json
 import os
 import stat
 from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611
@@ -130,6 +131,18 @@ class TestService(UnitTestsBase):
         ok_(not os.path.exists(default_cache), os.listdir('.'))
         ok_(os.path.exists('my-repo-cache'), os.listdir('.'))
 
+    def test_options_git_meta(self):
+        """Test the --git-meta option"""
+        eq_(service(['--url', self.orig_repo.path, '--git-meta=_git_meta']), 0)
+
+        # Check that the file was created and is json parseable
+        with open('_git_meta') as meta_fp:
+            json.load(meta_fp)
+
+        # Test failure
+        eq_(service(['--url', self.orig_repo.path,
+                     '--git-meta=test-package.spec']), 1)
+
     def test_user_group_config(self):
         """Test setting the user and group under which gbp is run"""
         # Changing to current user/group should succeed