From: "Mike Frysinger" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
Date: Wed, 8 Mar 2017 00:16:46 +0000 (UTC) [thread overview]
Message-ID: <1488931524.52fd99ac5d2a5d37767e2ab3fdbaa23ce24badd8.vapier@gentoo> (raw)
commit: 52fd99ac5d2a5d37767e2ab3fdbaa23ce24badd8
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 8 00:05:24 2017 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Mar 8 00:05:24 2017 +0000
URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=52fd99ac
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.
src/ekeyword/ekeyword.py | 10 +++++++--
src/ekeyword/ekeyword_unittest.py | 47 ++++++++++++++++++++++++++++-----------
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):
next reply other threads:[~2017-03-08 0:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 0:16 Mike Frysinger [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-03-08 0:16 [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/ Mike Frysinger
2017-02-18 5:24 Mike Frysinger
2017-02-16 7:25 Mike Frysinger
2017-02-16 7:25 Mike Frysinger
2016-01-27 23:35 Mike Frysinger
2016-01-27 23:35 Mike Frysinger
2015-04-04 21:26 Mike Frysinger
2015-04-04 21:26 Mike Frysinger
2015-04-04 21:26 Mike Frysinger
2014-11-18 18:24 Mike Gilbert
2014-11-13 22:51 Mike Frysinger
2014-01-27 23:14 Mike Frysinger
2014-01-25 22:00 Mike Frysinger
2014-01-25 22:00 Mike Frysinger
2014-01-25 22:00 Mike Frysinger
2014-01-20 16:29 Mike Frysinger
2014-01-20 6:17 Mike Frysinger
2012-04-23 3:02 Christian Ruppert
2012-04-23 3:02 Christian Ruppert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1488931524.52fd99ac5d2a5d37767e2ab3fdbaa23ce24badd8.vapier@gentoo \
--to=vapier@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox