New option for creating a git-meta file
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 1 Apr 2014 12:14:13 +0000 (15:14 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 2 Apr 2014 12:00:01 +0000 (15:00 +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: Iad3321acc1f80d280dd4c1e21f9681331fa882d1
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
obs_service_gbs/command.py
packaging/obs-service-gbs.spec
tests/test_obs_service_gbs.py

index 07f16f9..3598263 100644 (file)
@@ -33,6 +33,7 @@ import gbp.log as gbplog
 import gbp_repocache
 from gbp_repocache import CachedRepo, CachedRepoError
 from obs_service_gbp_utils import GbpServiceError, fork_call, sanitize_uid_gid
+from obs_service_gbp_utils import write_treeish_meta
 
 
 # Setup logging
@@ -145,6 +146,9 @@ def parse_args(argv):
                         choices=['yes', 'no'])
     parser.add_argument('--config', action='append',
                         help='Config file to use, can be given multiple times')
+    parser.add_argument('--git-meta', metavar='FILENAME',
+                        help='Create a json-formatted file FILENAME containing'
+                             'metadata about the exported revision')
     args = parser.parse_args(argv)
     if not args.config:
         args.config = default_configs
@@ -185,6 +189,13 @@ def main(argv=None):
         # Export sources with GBS
         gbs_export(repo, args, config)
 
+        # Write git-meta
+        if args.git_meta:
+            try:
+                write_treeish_meta(repo.repo, args.revision, args.outdir,
+                                   args.git_meta)
+            except GbpServiceError as err:
+                raise ServiceError(str(err), 1)
     except ServiceError as err:
         LOGGER.error(err[0])
         ret = err[1]
index d7c100b..31d9eda 100644 (file)
@@ -16,7 +16,7 @@ Source:         %{name}-%{version}.tar.bz2
 Requires:       gbs-export
 Requires:       git-buildpackage-common
 Requires:       gbp-repocache
-Requires:       obs-service-git-buildpackage-utils
+Requires:       obs-service-git-buildpackage-utils > 0.5
 BuildRequires:  python
 BuildRequires:  python-setuptools
 %if 0%{?do_unittests}
index 26a31d5..b61de16 100644 (file)
@@ -19,6 +19,7 @@
 """Tests for the GBS source service"""
 
 import grp
+import json
 import os
 import shutil
 import stat
@@ -191,6 +192,18 @@ class TestGbsService(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 the user/group settings"""
         # Changing to current user/group should succeed