From e6764abc191888adf4b31c9d865958c5acba5e88 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 1 Apr 2014 14:51:58 +0300 Subject: [PATCH] New option for creating a git-meta file 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 --- obs_service_gbp/command.py | 16 +++++++++++++++- tests/test_obs_service_gbp.py | 13 +++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/obs_service_gbp/command.py b/obs_service_gbp/command.py index 895811d..c474ef2 100644 --- a/obs_service_gbp/command.py +++ b/obs_service_gbp/command.py @@ -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 diff --git a/tests/test_obs_service_gbp.py b/tests/test_obs_service_gbp.py index 76ee6be..66cfb30 100644 --- a/tests/test_obs_service_gbp.py +++ b/tests/test_obs_service_gbp.py @@ -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 -- 2.7.4