From 72cf760ee66142b22196a82ee4c96f130be0ed4e Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Mar 01 2017 09:33:58 +0000 Subject: Fix rpm command to get changelog from SPEC Commands.rpmdefines was not added to rpm command to get changelog from SPEC. This causes SPEC cannot be parsed correctly if it contains SourceN or PatchN. Like other methods in Commands class that runs rpm, Commands.rpmdefines should be always added to the rpm command. Resolves: rhbz#1412224 Signed-off-by: Chenxiong Qi --- diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0becd3a..823b18c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ ChangeLog ========= +NEXT +---- + +- Fix rpm command to get changelog from SPEC - rhbz#1412224 (cqi) + v1.49 (2017-02-22) ------------------ diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index d2abdea..7ded7f1 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1981,8 +1981,10 @@ class Commands(object): """Write the latest spec changelog entry to a clog file""" spec_file = os.path.join(self.path, self.spec) - cmd = ['rpm', '-q', '--qf', '%{CHANGELOGTEXT}\n', '--specfile', spec_file] - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd = ['rpm'] + self.rpmdefines + ['-q', '--qf', '"%{CHANGELOGTEXT}\n"', + '--specfile', '"%s"' % spec_file] + proc = subprocess.Popen(' '.join(cmd), shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() if proc.returncode > 0: raise rpkgError(stderr.strip()) diff --git a/tests/test_cli.py b/tests/test_cli.py index cb6dc6c..29b1e2e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -72,6 +72,7 @@ class TestClog(CliTestCase): def setUp(self): super(TestClog, self).setUp() + self.checkout_branch(git.Repo(self.cloned_repo_path), 'eng-rhel-6') def cli_clog(self): """Run clog command""" @@ -86,8 +87,7 @@ class TestClog(CliTestCase): clog_file = os.path.join(self.cloned_repo_path, 'clog') self.assertTrue(os.path.exists(clog_file)) - with open(clog_file, 'r') as f: - clog = f.read().strip() + clog = self.read_file(clog_file).strip() self.assertEqual('Initial version', clog) def test_raw_clog(self): @@ -98,15 +98,25 @@ class TestClog(CliTestCase): clog_file = os.path.join(self.cloned_repo_path, 'clog') self.assertTrue(os.path.exists(clog_file)) - with open(clog_file, 'r') as f: - clog = f.read().strip() + clog = self.read_file(clog_file).strip() self.assertEqual('- Initial version', clog) + def test_reference_source_files_in_spec_should_not_break_clog(self): + """SPEC containing Source0 or Patch0 should not break clog + + This case is reported in bug 1412224 + """ + spec_file = os.path.join(self.cloned_repo_path, self.spec_file) + spec = self.read_file(spec_file) + self.write_file(spec_file, spec.replace('#Source0:', 'Source0: extrafile.txt')) + self.test_raw_clog() + class TestCommit(CliTestCase): def setUp(self): super(TestCommit, self).setUp() + self.checkout_branch(git.Repo(self.cloned_repo_path), 'eng-rhel-6') self.make_changes() def get_last_commit_message(self): diff --git a/tests/test_commands.py b/tests/test_commands.py index 9765d6d..aae6921 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -306,7 +306,7 @@ class ClogTest(CommandTestCase): def setUp(self): super(ClogTest, self).setUp() - with open(os.path.join(self.repo_path, self.spec_file), 'w') as specfile: + with open(os.path.join(self.cloned_repo_path, self.spec_file), 'w') as specfile: specfile.write(''' Summary: package demo Name: pkgtool @@ -325,12 +325,14 @@ $what_is_this - initial ''') - self.cmd = self.make_commands(self.repo_path) + self.clog_file = os.path.join(self.cloned_repo_path, 'clog') + self.cmd = self.make_commands() + self.checkout_branch(self.cmd.repo, 'eng-rhel-6') def test_clog(self): self.cmd.clog() - with open(os.path.join(self.repo_path, 'clog'), 'r') as clog: + with open(self.clog_file, 'r') as clog: clog_lines = clog.readlines() expected_lines = ['add %changelog section\n', @@ -340,7 +342,7 @@ $what_is_this def test_raw_clog(self): self.cmd.clog(raw=True) - with open(os.path.join(self.repo_path, 'clog'), 'r') as clog: + with open(self.clog_file, 'r') as clog: clog_lines = clog.readlines() expected_lines = ['- add %changelog section\n', diff --git a/tests/utils.py b/tests/utils.py index d02fd57..7688d49 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -27,6 +27,8 @@ Name: docpkg Version: 1.2 Release: 2%{dist} License: GPL +#Source0: +#Patch0: Group: Applications/Productivity BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) %description