summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2017-03-07 16:05:24 -0800
committerMike Frysinger <vapier@gentoo.org>2017-03-07 16:05:24 -0800
commit52fd99ac5d2a5d37767e2ab3fdbaa23ce24badd8 (patch)
treead0895b1709ff7b3138b42d226ac9c3cb93253f5
parentekeyword: misc source touchups (diff)
downloadgentoolkit-52fd99ac5d2a5d37767e2ab3fdbaa23ce24badd8.tar.gz
gentoolkit-52fd99ac5d2a5d37767e2ab3fdbaa23ce24badd8.tar.bz2
gentoolkit-52fd99ac5d2a5d37767e2ab3fdbaa23ce24badd8.zip
ekeyword: add support for regenerating manifests
Since many ebuilds live in overlays with manifest checking turned on, add a flag to easily regen the manifest files after we modify them.
-rwxr-xr-xsrc/ekeyword/ekeyword.py10
-rwxr-xr-xsrc/ekeyword/ekeyword_unittest.py47
2 files changed, 42 insertions, 15 deletions
diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 6d09001..31225b0 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -44,6 +44,7 @@ import difflib
import io
import os
import re
+import subprocess
import sys
import portage
@@ -297,7 +298,7 @@ def process_content(ebuild, data, ops, arch_status=None, verbose=0,
def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
- dry_run=False, style='color-inline'):
+ dry_run=False, style='color-inline', manifest=False):
"""Process |ops| for |ebuild|
Args:
@@ -320,6 +321,8 @@ def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
if updated and not dry_run:
with io.open(ebuild, 'w', encoding='utf8') as f:
f.writelines(content)
+ if manifest:
+ subprocess.check_call(['ebuild', ebuild, 'manifest'])
return updated
@@ -461,6 +464,8 @@ def get_parser():
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
+ parser.add_argument('-m', '--manifest', default=False, action='store_true',
+ help='Run `ebuild manifest` on the ebuild after modifying it')
parser.add_argument('-n', '--dry-run', default=False, action='store_true',
help='Show what would be changed, but do not commit')
parser.add_argument('-v', '--verbose', action='count', default=0,
@@ -523,7 +528,8 @@ def main(argv):
for ebuild, ops in work:
process_ebuild(ebuild, ops, arch_status=arch_status,
verbose=opts.verbose, quiet=opts.quiet,
- dry_run=opts.dry_run, style=opts.style)
+ dry_run=opts.dry_run, style=opts.style,
+ manifest=opts.manifest)
return os.EX_OK
diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 3465dfb..de40e7a 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -10,9 +10,12 @@
from __future__ import print_function
import os
+import subprocess
import tempfile
import unittest
+import mock
+
import ekeyword
@@ -299,29 +302,47 @@ class TestProcessEbuild(unittest.TestCase):
This is fairly light as most code is in process_content.
"""
- def _test(self, dry_run):
- ops = (
- ekeyword.Op(None, 'arm', None),
- ekeyword.Op('~', 'sparc', None),
- )
+ def _process_ebuild(self, *args, **kwargs):
+ """Set up a writable copy of an ebuild for process_ebuild()"""
with tempfile.NamedTemporaryFile() as tmp:
with open(tmp.name, 'wb') as fw:
with open(os.path.join(TESTDIR, 'process-1.ebuild'), 'rb') as f:
orig_content = f.read()
fw.write(orig_content)
- ekeyword.process_ebuild(tmp.name, ops, dry_run=dry_run)
+ ekeyword.process_ebuild(tmp.name, *args, **kwargs)
with open(tmp.name, 'rb') as f:
- new_content = f.read()
- if dry_run:
- self.assertEqual(orig_content, new_content)
- else:
- self.assertNotEqual(orig_content, new_content)
+ return (orig_content, f.read())
+
+ def _testSmoke(self, dry_run):
+ ops = (
+ ekeyword.Op(None, 'arm', None),
+ ekeyword.Op('~', 'sparc', None),
+ )
+ orig_content, new_content = self._process_ebuild(ops, dry_run=dry_run)
+ if dry_run:
+ self.assertEqual(orig_content, new_content)
+ else:
+ self.assertNotEqual(orig_content, new_content)
def testSmokeNotDry(self):
- self._test(False)
+ self._testSmoke(False)
def testSmokeDry(self):
- self._test(True)
+ self._testSmoke(True)
+
+ def testManifestUpdated(self):
+ """Verify `ebuild ... manifest` runs on updated files"""
+ with mock.patch.object(subprocess, 'check_call') as m:
+ self._process_ebuild((ekeyword.Op('~', 'arm', None),),
+ manifest=True)
+ m.assert_called_once_with(['ebuild', mock.ANY, 'manifest'])
+
+ def testManifestNotUpdated(self):
+ """Verify we don't run `ebuild ... manifest` on unmodified files"""
+ with mock.patch.object(subprocess, 'check_call') as m:
+ self._process_ebuild((ekeyword.Op(None, 'arm', None),),
+ manifest=True)
+ self.assertEqual(m.call_count, 0)
class TestLoadProfileData(unittest.TestCase):