public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2012-04-23  3:02 Christian Ruppert
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Ruppert @ 2012-04-23  3:02 UTC (permalink / raw
  To: gentoo-commits

commit:     430f15ddbd8405d7e82a332cbd9c242405923800
Author:     Christian Ruppert <idl0r <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 23 02:24:09 2012 +0000
Commit:     Christian Ruppert <idl0r <AT> gentoo <DOT> org>
CommitDate: Mon Apr 23 02:24:09 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=430f15dd

More cleanup

---
 src/ekeyword/ekeyword |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/ekeyword/ekeyword b/src/ekeyword/ekeyword
index 0c68773..5f94fc6 100755
--- a/src/ekeyword/ekeyword
+++ b/src/ekeyword/ekeyword
@@ -112,7 +112,6 @@ for my $f (@ARGV) {
 
 	open(my $fh_in, "<", $f) or die "Can't read $f: $!\n";
 	open(my $fh_out, ">", "${f}.new") or die "Can't create ${f}.new: ${!}\n";
-	select($fh_out);
 
 	my $count = 0;
 	while(<$fh_in>) {
@@ -121,10 +120,10 @@ for my $f (@ARGV) {
 	seek($fh_in, 0, 0);
 
 	while (<$fh_in>) {
-		if (/^\s*KEYWORDS=/) {
+		if (m/^\s*KEYWORDS=/) {
 
 			# extract the quoted section from KEYWORDS
-			while (not /^\s*KEYWORDS=["'].*?["']/) {
+			while (not m/^\s*KEYWORDS=["'].*?["']/) {
 				chomp;
 				my $next = <$fh_in>;
 				$_ = join " ", $_, $next;
@@ -134,7 +133,7 @@ for my $f (@ARGV) {
 			if($count > 1 && length($quoted) eq 0) {
 				# Skip empty KEYWORDS variables in case they occur more than
 				# once, bug 321475.
-				print $_;
+				print $fh_out $_;
 				next;
 			}
 
@@ -218,15 +217,15 @@ for my $f (@ARGV) {
 			# re-insert quoted to KEYWORDS
 			s/(["']).*?["']/$1$quoted$1/;
 
-			print $_ or die "Can't write $f.new: $!\n";
+			print $fh_out $_ or die "Can't write $f.new: $!\n";
 		} else {
-			print, next;
+			print $fh_out $_;
+			next;
 		}
 	}
 
 	close($fh_in);
 	close($fh_out);
-	select STDOUT;
 
 	system("diff -U 0 ${f} ${f}.new");
 	rename("$f.new", "$f") or die "Can't rename: $!\n";



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2012-04-23  3:02 Christian Ruppert
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Ruppert @ 2012-04-23  3:02 UTC (permalink / raw
  To: gentoo-commits

commit:     7d28b4f65d8c6964b9493eb46815522d6d72df8e
Author:     Christian Ruppert <idl0r <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 23 02:47:23 2012 +0000
Commit:     Christian Ruppert <idl0r <AT> gentoo <DOT> org>
CommitDate: Mon Apr 23 02:47:23 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=7d28b4f6

More cleanup

---
 src/ekeyword/ekeyword |   31 ++++++++++++++++---------------
 1 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/ekeyword/ekeyword b/src/ekeyword/ekeyword
index 5f94fc6..d680e26 100755
--- a/src/ekeyword/ekeyword
+++ b/src/ekeyword/ekeyword
@@ -93,6 +93,7 @@ get_architectures();
 get_architectures_status();
 
 my $files = 0;
+my $line;
 for my $f (@ARGV) {
 	if ($f =~ m/$kw_re/o) {
 		my $arch = $2;
@@ -104,7 +105,7 @@ for my $f (@ARGV) {
 			}
 		}
 
-		push @kw, $f;
+		push(@kw, $f);
 		next;
 	}
 
@@ -114,26 +115,26 @@ for my $f (@ARGV) {
 	open(my $fh_out, ">", "${f}.new") or die "Can't create ${f}.new: ${!}\n";
 
 	my $count = 0;
-	while(<$fh_in>) {
-		$count++ if m/^\s*KEYWORDS=/;
+	while($line = <$fh_in>) {
+		$count++ if $line =~ m/^\s*KEYWORDS=/;
 	}
 	seek($fh_in, 0, 0);
 
-	while (<$fh_in>) {
-		if (m/^\s*KEYWORDS=/) {
+	while ($line = <$fh_in>) {
+		if ($line =~ m/^\s*KEYWORDS=/) {
 
 			# extract the quoted section from KEYWORDS
-			while (not m/^\s*KEYWORDS=["'].*?["']/) {
-				chomp;
+			while ($line !~ m/^\s*KEYWORDS=["'](?:.+)?["']/) {
+				chomp($line);
 				my $next = <$fh_in>;
-				$_ = join " ", $_, $next;
+				$line = join(" ", $line, $next);
 			}
-			(my $quoted = $_) =~ s/^.*?["'](.*?)["'].*/$1/s;
+			(my $quoted = $line) =~ s/^.*?["'](.*?)["'].*/$1/s;
 
 			if($count > 1 && length($quoted) eq 0) {
 				# Skip empty KEYWORDS variables in case they occur more than
 				# once, bug 321475.
-				print $fh_out $_;
+				print $fh_out $line;
 				next;
 			}
 
@@ -145,7 +146,7 @@ for my $f (@ARGV) {
 
 				# handle -* and ^*
 				if (defined $star) {
-					$leader = substr $star,0,1;
+					$leader = substr($star, 0, 1);
 					$arch = 'STAR';
 				}
 
@@ -212,14 +213,14 @@ for my $f (@ARGV) {
 				$sa =~ s/([a-z0-9]+)-([a-z0-9]*)/$2-$1/g;
 				$sb =~ s/([a-z0-9]+)-([a-z0-9]*)/$2-$1/g;
 				$sa cmp $sb;
-			} split " ", $quoted;
+			} split(/\s+/, $quoted);
 
 			# re-insert quoted to KEYWORDS
-			s/(["']).*?["']/$1$quoted$1/;
+			$line =~ s/(["']).*?["']/$1$quoted$1/;
 
-			print $fh_out $_ or die "Can't write $f.new: $!\n";
+			print $fh_out $line or die "Can't write $f.new: $!\n";
 		} else {
-			print $fh_out $_;
+			print $fh_out $line;
 			next;
 		}
 	}



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-01-20  6:17 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2014-01-20  6:17 UTC (permalink / raw
  To: gentoo-commits

commit:     14522d53c0088a0087376366f2b09c32704e791d
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 20 06:15:33 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Jan 20 06:15:33 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=14522d53

ekeyword: make sure ~all does not expand into entire arch list

---
 src/ekeyword/ekeyword.py          | 2 +-
 src/ekeyword/ekeyword_unittest.py | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 37a25ee..b53daef 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -146,7 +146,7 @@ def process_keywords(keywords, ops, arch_status=None):
 				# Process all possible keywords.  We use the arch_status as a
 				# master list.  If it lacks some keywords, then we might miss
 				# somethings here, but not much we can do.
-				arches = set(arch_status.keys()) | old_arches
+				arches = old_arches
 		else:
 			arches = (oarch,)
 

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 9ccde0e..a1d8d85 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -169,6 +169,9 @@ class TestProcessKeywords(unittest.TestCase):
 			'arm': 'stable',
 			'arm64': 'exp',
 			'm68k': 'dev',
+			'mips': 'dev',
+			's390': 'dev',
+			'sh': 'dev',
 		}
 		self._test('alpha arm arm64 m68k mips arm-linux', ops,
 		           '~alpha ~arm ~arm64 ~m68k ~mips ~arm-linux', arch_status)


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-01-20 16:29 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2014-01-20 16:29 UTC (permalink / raw
  To: gentoo-commits

commit:     b7014219ba7425daa9fafda82fafcc129f8628ce
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 20 16:24:53 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Jan 20 16:24:53 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=b7014219

ekeyword: fix keyword sorting between platforms

We need to sort first upon the platform (part after the '-') before we
look at the arch at all.

Reported-by: Ulrich Mueller <ulm <AT> gentoo.org>

---
 src/ekeyword/ekeyword             |  1 +
 src/ekeyword/ekeyword.py          | 24 ++++++++++++++++--------
 src/ekeyword/ekeyword_unittest.py |  9 ++++++++-
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/ekeyword/ekeyword b/src/ekeyword/ekeyword
new file mode 120000
index 0000000..8374306
--- /dev/null
+++ b/src/ekeyword/ekeyword
@@ -0,0 +1 @@
+ekeyword.py
\ No newline at end of file

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index b53daef..66cf48a 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -78,15 +78,23 @@ def sort_keywords(arches):
 		a1 = keyword_to_arch(a1)
 		a2 = keyword_to_arch(a2)
 
-		# If a keyword has a "-" in it, then it always comes after ones
-		# that do not.  We want things like alpha/mips/sparc showing up
-		# before amd64-fbsd and amd64-linux.
-		if '-' in a1 and not '-' in a2:
-			return 1
-		elif '-' not in a1 and '-' in a2:
-			return -1
+		# A keyword may have a "-" in it.  We split on that and sort
+		# by the two resulting items.  The part after the hyphen is
+		# the primary key.
+		if '-' in a1:
+			arch1, plat1 = a1.split('-', 1)
 		else:
-			return cmp(a1, a2)
+			arch1, plat1 = a1, ''
+		if '-' in a2:
+			arch2, plat2 = a2.split('-', 1)
+		else:
+			arch2, plat2 = a2, ''
+
+		ret = cmp(plat1, plat2)
+		if ret:
+			return ret
+		else:
+			return cmp(arch1, arch2)
 
 	keywords += sorted(arches, cmp=arch_cmp)
 

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index a1d8d85..5096c71 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -31,14 +31,21 @@ class TestSortKeywords(unittest.TestCase):
 		self._test('arm -* x86', '-* arm x86')
 		self._test('hppa ~* amd64', '~* amd64 hppa')
 
-	def testNonLinux(self):
+	def testMixedPlatform(self):
+		"""Verify core arches get sorted before all w/suffix"""
 		self._test('arm-linux alpha amd64-fbsd hppa',
 		           'alpha hppa amd64-fbsd arm-linux')
 
 	def testPrefixes(self):
+		"""Verify -/~ and such get ignored for sorting"""
 		self._test('-hppa arm ~alpha -* ~arm-linux',
 		           '-* ~alpha arm -hppa ~arm-linux')
 
+	def testPlatform(self):
+		"""Verify we sort based on platform first"""
+		self._test('x86-linux ppc-macos x86-fbsd amd64-linux amd64-fbsd',
+		           'amd64-fbsd x86-fbsd amd64-linux x86-linux ppc-macos')
+
 
 class TestDiffKeywords(unittest.TestCase):
 	"""Tests for diff_keywords"""


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-01-25 22:00 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2014-01-25 22:00 UTC (permalink / raw
  To: gentoo-commits

commit:     a8d9d1e301afbdd794d3a95f0ef61e78ca39edcf
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 20 20:05:18 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Jan 20 20:05:18 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=a8d9d1e3

ekeyword: make quiet/verbose flags a bit more flexible

This allows for multiple levels of verbose/quiet.

---
 src/ekeyword/ekeyword.py          | 16 ++++++++--------
 src/ekeyword/ekeyword_unittest.py |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 66cf48a..7a6c630 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -190,15 +190,15 @@ def process_keywords(keywords, ops, arch_status=None):
 	return new_keywords
 
 
-def process_content(ebuild, data, ops, arch_status=None, verbose=False,
-                    quiet=False, format='color-inline'):
+def process_content(ebuild, data, ops, arch_status=None, verbose=0,
+                    quiet=0, format='color-inline'):
 	"""Process |ops| for |data|"""
 	# Set up the user display style based on verbose/quiet settings.
-	if verbose:
+	if verbose > 1:
 		disp_name = ebuild
 		def logit(msg):
 			print('%s: %s' % (disp_name, msg))
-	elif quiet:
+	elif quiet > 1:
 		def logit(msg):
 			pass
 	else:
@@ -225,7 +225,7 @@ def process_content(ebuild, data, ops, arch_status=None, verbose=False,
 			old_keywords, ops, arch_status=arch_status)
 
 		# Finally let's present the results to the user.
-		if new_keywords != old_keywords:
+		if (new_keywords != old_keywords) or verbose:
 			# Only do the diff work if something actually changed.
 			updated = True
 			old_keywords = sort_keywords(old_keywords)
@@ -256,7 +256,7 @@ def process_content(ebuild, data, ops, arch_status=None, verbose=False,
 	return updated, content
 
 
-def process_ebuild(ebuild, ops, arch_status=None, verbose=False, quiet=False,
+def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
                    dry_run=False, format='color-inline'):
 	"""Process |ops| for |ebuild|"""
 	with open(ebuild, 'rb') as f:
@@ -369,9 +369,9 @@ def get_parser():
 		formatter_class=argparse.RawDescriptionHelpFormatter)
 	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', default=False, action='store_true',
+	parser.add_argument('-v', '--verbose', action='count',
 		help='Be verbose while processing things')
-	parser.add_argument('-q', '--quiet', default=False, action='store_true',
+	parser.add_argument('-q', '--quiet', action='count',
 		help='Be quiet while processing things (only show errors)')
 	parser.add_argument('--format', default='auto',
 		choices=('auto', 'color-inline', 'inline', 'short-multi', 'long-multi'),

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 5096c71..00c295f 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -245,7 +245,7 @@ class TestProcessContent(unittest.TestCase):
 		self.assertFalse(updated)
 		self.assertEqual(ret, [' KEYWORDS=\n'])
 
-	def _testSmoke(self, format='color-inline', verbose=False, quiet=False):
+	def _testSmoke(self, format='color-inline', verbose=0, quiet=0):
 		ops = (
 			ekeyword.Op(None, 'arm', None),
 			ekeyword.Op('~', 'sparc', None),
@@ -256,11 +256,11 @@ class TestProcessContent(unittest.TestCase):
 
 	def testSmokeQuiet(self):
 		"""Smoke test for quiet mode"""
-		self._testSmoke(quiet=True)
+		self._testSmoke(quiet=10)
 
 	def testSmokeVerbose(self):
 		"""Smoke test for verbose mode"""
-		self._testSmoke(verbose=True)
+		self._testSmoke(verbose=10)
 
 	def testSmokeFormatColor(self):
 		"""Smoke test for color-inline format"""


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-01-25 22:00 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2014-01-25 22:00 UTC (permalink / raw
  To: gentoo-commits

commit:     080519f882c622f4fbd44858801b39aaad4e88ad
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 20 20:06:15 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Jan 20 20:06:15 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=080519f8

ekeyword: skip known paths rather than fail

There are commonly files in an ebuild dir that we don't care about.
Issue a warning, but otherwise skip them without aborting.  This let's
you do things like:
	ekeyword x86 some-package/*

Which is nice when you know there's only one or two ebuilds in there.

---
 src/ekeyword/ekeyword.py | 37 ++++++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 7a6c630..d8e0ed1 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -54,6 +54,10 @@ VERSION = '1.0 awesome'
 Op = collections.namedtuple('Op', ('op', 'arch', 'ref_arch'))
 
 
+def warning(msg):
+	print('warning: %s' % msg, file=sys.stderr)
+
+
 def keyword_to_arch(keyword):
 	"""Given a keyword, strip it down to its arch value
 
@@ -309,8 +313,8 @@ def load_profile_data(portdir=None, repo='gentoo'):
 	if arch_status:
 		arch_status['all'] = None
 	else:
-		print('warning: could not read profile files: %s' % arch_list, file=sys.stderr)
-		print('warning: will not be able to verify args are correct', file=sys.stderr)
+		warning('could not read profile files: %s' % arch_list)
+		warning('will not be able to verify args are correct')
 
 	return arch_status
 
@@ -334,7 +338,30 @@ def arg_to_op(arg):
 	return Op(op, arch, refarch)
 
 
-def args_to_work(args, arch_status=None, repo='gentoo'):
+def ignorable_arg(arg, quiet=0):
+	"""Whether it's ok to ignore this argument"""
+	if os.path.isdir(arg):
+		if not quiet:
+			warning('ignoring directory %s' % arg)
+		return True
+
+	WHITELIST = (
+		'Manifest',
+		'metadata.xml',
+	)
+	base = os.path.basename(arg)
+	if (base.startswith('ChangeLog') or
+	    base in WHITELIST or
+	    base.startswith('.') or
+	    base.endswith('~')):
+		if not quiet:
+			warning('ignoring file: %s' % arg)
+		return True
+
+	return False
+
+
+def args_to_work(args, arch_status=None, repo='gentoo', quiet=0):
 	"""Process |args| into a list of work itmes (ebuild/arches to update)"""
 	work = []
 	todo_arches = []
@@ -353,7 +380,7 @@ def args_to_work(args, arch_status=None, repo='gentoo'):
 			op = arg_to_op(arg)
 			if not arch_status or op.arch in arch_status:
 				todo_arches.append(op)
-			else:
+			elif not ignorable_arg(arg, quiet=quiet):
 				raise ValueError('unknown arch/argument: %s' % arg)
 
 	if todo_arches:
@@ -425,7 +452,7 @@ def main(argv):
 
 	arch_status = load_profile_data()
 	try:
-		work = args_to_work(work_args, arch_status=arch_status)
+		work = args_to_work(work_args, arch_status=arch_status, quiet=opts.quiet)
 	except ValueError as e:
 		parser.error(e)
 


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-01-25 22:00 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2014-01-25 22:00 UTC (permalink / raw
  To: gentoo-commits

commit:     0482abe75ed71c5d0b6bb55f0d98bf9388861c08
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 25 22:00:07 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Jan 25 22:00:07 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=0482abe7

ekeyword: fix python3 compat issues

Get the unittests passing w/python-3.3.

---
 src/ekeyword/ekeyword.py | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index d8e0ed1..3fa74c1 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -41,6 +41,7 @@ from __future__ import print_function
 import argparse
 import collections
 import difflib
+import io
 import os
 import re
 import sys
@@ -77,30 +78,21 @@ def sort_keywords(arches):
 			arches.remove(g)
 			keywords.append(g)
 
-	def arch_cmp(a1, a2):
+	def arch_key(keyword):
 		# Sort independent of leading marker (~ or -).
-		a1 = keyword_to_arch(a1)
-		a2 = keyword_to_arch(a2)
+		arch = keyword_to_arch(keyword)
 
 		# A keyword may have a "-" in it.  We split on that and sort
 		# by the two resulting items.  The part after the hyphen is
 		# the primary key.
-		if '-' in a1:
-			arch1, plat1 = a1.split('-', 1)
+		if '-' in arch:
+			arch, plat = arch.split('-', 1)
 		else:
-			arch1, plat1 = a1, ''
-		if '-' in a2:
-			arch2, plat2 = a2.split('-', 1)
-		else:
-			arch2, plat2 = a2, ''
+			arch, plat = arch, ''
 
-		ret = cmp(plat1, plat2)
-		if ret:
-			return ret
-		else:
-			return cmp(arch1, arch2)
+		return (plat, arch)
 
-	keywords += sorted(arches, cmp=arch_cmp)
+	keywords += sorted(arches, key=arch_key)
 
 	return keywords
 
@@ -133,8 +125,8 @@ def diff_keywords(old_keywords, new_keywords, format='color-inline'):
 
 		return output
 
-	sold = ' '.join(old_keywords)
-	snew = ' '.join(new_keywords)
+	sold = str(' '.join(old_keywords))
+	snew = str(' '.join(new_keywords))
 	s = difflib.SequenceMatcher(str.isspace, sold, snew, autojunk=False)
 	return show_diff(s)
 
@@ -263,12 +255,12 @@ 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, format='color-inline'):
 	"""Process |ops| for |ebuild|"""
-	with open(ebuild, 'rb') as f:
+	with io.open(ebuild, encoding='utf8') as f:
 		updated, content = process_content(
 			ebuild, f, ops, arch_status=arch_status,
 			verbose=verbose, quiet=quiet, format=format)
 		if updated and not dry_run:
-			with open(ebuild, 'wb') as f:
+			with io.open(ebuild, 'w', encoding='utf8') as f:
 				f.writelines(content)
 
 
@@ -396,9 +388,9 @@ def get_parser():
 		formatter_class=argparse.RawDescriptionHelpFormatter)
 	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',
+	parser.add_argument('-v', '--verbose', action='count', default=0,
 		help='Be verbose while processing things')
-	parser.add_argument('-q', '--quiet', action='count',
+	parser.add_argument('-q', '--quiet', action='count', default=0,
 		help='Be quiet while processing things (only show errors)')
 	parser.add_argument('--format', default='auto',
 		choices=('auto', 'color-inline', 'inline', 'short-multi', 'long-multi'),


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-01-27 23:14 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2014-01-27 23:14 UTC (permalink / raw
  To: gentoo-commits

commit:     465c0532f88df7bf3af08e84172ea5a908105fc1
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 27 23:13:43 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Jan 27 23:13:43 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=465c0532

ekeyword: ignore "*" when processing "all"

Reported-by: Jeroen Roovers <jer <AT> gentoo.org>

---
 src/ekeyword/ekeyword.py          | 3 +++
 src/ekeyword/ekeyword_unittest.py | 9 ++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 3fa74c1..080e04f 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -151,6 +151,9 @@ def process_keywords(keywords, ops, arch_status=None):
 				# master list.  If it lacks some keywords, then we might miss
 				# somethings here, but not much we can do.
 				arches = old_arches
+			# We ignore the glob arch as we never want to tweak it.
+			if '*' in arches:
+				arches.remove('*')
 		else:
 			arches = (oarch,)
 

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 00c295f..b491db0 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -176,12 +176,11 @@ class TestProcessKeywords(unittest.TestCase):
 			'arm': 'stable',
 			'arm64': 'exp',
 			'm68k': 'dev',
-			'mips': 'dev',
 			's390': 'dev',
 			'sh': 'dev',
 		}
-		self._test('alpha arm arm64 m68k mips arm-linux', ops,
-		           '~alpha ~arm ~arm64 ~m68k ~mips ~arm-linux', arch_status)
+		self._test('-* ~* * alpha arm arm64 m68k arm-linux', ops,
+		           '-* ~* * ~alpha ~arm ~arm64 ~m68k ~arm-linux', arch_status)
 
 	def testAllMultiUnstableStable(self):
 		ops = (
@@ -194,8 +193,8 @@ class TestProcessKeywords(unittest.TestCase):
 			'arm64': 'exp',
 			'm68k': 'dev',
 		}
-		self._test('alpha arm arm64 m68k', ops,
-		           '~alpha arm ~arm64 ~m68k', arch_status)
+		self._test('-* ~* * alpha arm arm64 m68k', ops,
+		           '-* ~* * ~alpha arm ~arm64 ~m68k', arch_status)
 
 
 class TestProcessContent(unittest.TestCase):


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-11-13 22:51 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2014-11-13 22:51 UTC (permalink / raw
  To: gentoo-commits

commit:     a9e7d0e7211b5f7816667e0ab9bb2c17653c890e
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Nov 13 22:51:01 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Nov 13 22:51:01 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=a9e7d0e7

ekeyword: fill out documentation and tweak API

Basically clean things up for people using ekeyword as a module.

---
 src/ekeyword/ekeyword.py | 73 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 63 insertions(+), 10 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 080e04f..a35d58d 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -18,22 +18,22 @@ The ^ leader instructs ekeyword to remove the specified arch.
 Examples:
 
   # Mark all existing arches in the ebuild as stable.
-  $ ekeyword all foo-1.ebuild
+  $ %(prog)s all foo-1.ebuild
 
   # Mark arm as stable and x86 as unstable.
-  $ ekeyword arm ~x86 foo-1.ebuild
+  $ %(prog)s arm ~x86 foo-1.ebuild
 
   # Mark hppa as unsupported (explicitly adds -hppa).
-  $ ekeyword -hppa foo-1.ebuild
+  $ %(prog)s -hppa foo-1.ebuild
 
   # Delete alpha keywords from all ebuilds.
-  $ ekeyword ^alpha *.ebuild
+  $ %(prog)s ^alpha *.ebuild
 
   # Mark sparc as stable for foo-1 and m68k as unstable for foo-2.
-  $ ekeyword sparc foo-1.ebuild ~m68k foo-2.ebuild
+  $ %(prog)s sparc foo-1.ebuild ~m68k foo-2.ebuild
 
   # Mark s390 as the same state as amd64.
-  $ ekeyword s390=amd64 foo-1.ebuild
+  $ %(prog)s s390=amd64 foo-1.ebuild
 """
 
 from __future__ import print_function
@@ -52,10 +52,20 @@ from portage.output import colorize, nocolor
 
 VERSION = '1.0 awesome'
 
+# Operation object that describes how to perform a change.
+# Args:
+#  op: The operation to perform when |ref_arch| is not set:
+#      None: Mark |arch| stable
+#      '-': Mark |arch| as not applicable (e.g. -foo)
+#      '~': Mark |arch| as unstable (e.g. ~foo)
+#      '^': Delete |arch| so it isn't listed at all
+#  arch: The required arch to update
+#  ref_arch: Set |arch| status to this arch (ignoring |op|)
 Op = collections.namedtuple('Op', ('op', 'arch', 'ref_arch'))
 
 
 def warning(msg):
+	"""Write |msg| as a warning to stderr"""
 	print('warning: %s' % msg, file=sys.stderr)
 
 
@@ -69,7 +79,17 @@ def keyword_to_arch(keyword):
 
 
 def sort_keywords(arches):
-	"""Sort |arches| list in the order developers expect"""
+	"""Sort |arches| list in the order developers expect
+
+	This is vaguely defined because it is kind of vaguely defined once you get
+	past the basic (Linux-only) keywords.
+
+	Args:
+	  arches: An iterable of ARCH values.
+
+	Returns:
+	  A sorted list of |arches|
+	"""
 	keywords = []
 
 	# Globs always come first.
@@ -98,7 +118,16 @@ def sort_keywords(arches):
 
 
 def diff_keywords(old_keywords, new_keywords, format='color-inline'):
-	"""Show pretty diff between list of keywords"""
+	"""Show pretty diff between list of keywords
+
+	Args:
+	  old_keywords: The old set of KEYWORDS
+	  new_keywords: The new set of KEYWORDS
+	  format: The diff style
+
+	Returns:
+	  A string containing the diff output ready to shown to the user
+	"""
 	def show_diff(s):
 		output = ''
 
@@ -257,7 +286,21 @@ 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, format='color-inline'):
-	"""Process |ops| for |ebuild|"""
+	"""Process |ops| for |ebuild|
+
+	Args:
+	  ebuild: The ebuild file to operate on & update in place
+	  ops: An iterable of operations (Op objects) to perform on |ebuild|
+	  arch_status: A dict mapping default arches to their stability; see the
+	               load_profile_data function for more details
+	  verbose: Be verbose; show various status messages
+	  quiet: Be quiet; only show errors
+	  dry_run: Do not make any changes to |ebuild|; show what would be done
+	  format: The diff style
+
+    Returns:
+      Whether any updates were processed
+	"""
 	with io.open(ebuild, encoding='utf8') as f:
 		updated, content = process_content(
 			ebuild, f, ops, arch_status=arch_status,
@@ -265,10 +308,20 @@ 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)
+        return updated
 
 
 def load_profile_data(portdir=None, repo='gentoo'):
-	"""Load the list of known arches from the tree"""
+	"""Load the list of known arches from the tree
+
+	Args:
+	  portdir: The repository to load all data from (and ignore |repo|)
+	  repo: Look up this repository by name to locate profile data
+
+	Returns:
+	  A dict mapping the keyword to its preferred state:
+	  {'x86': 'stable', 'mips': 'dev', ...}
+	"""
 	if portdir is None:
 		portdir = portage.db['/']['vartree'].settings.repositories[repo].location
 


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2014-11-18 18:24 Mike Gilbert
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Gilbert @ 2014-11-18 18:24 UTC (permalink / raw
  To: gentoo-commits

commit:     8054e7f40cd07cac63dc67488aa22871fb29b7c6
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Tue Nov 18 18:21:50 2014 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Tue Nov 18 18:21:50 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=8054e7f4

ekeyword: Fix inconsistent use of tabs for indentation.

---
 src/ekeyword/ekeyword.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index a35d58d..cac6298 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -308,7 +308,7 @@ 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)
-        return updated
+	return updated
 
 
 def load_profile_data(portdir=None, repo='gentoo'):


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2015-04-04 21:26 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2015-04-04 21:26 UTC (permalink / raw
  To: gentoo-commits

commit:     53883043dd23eecf033756bff14d50fa994e4525
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Apr  4 21:21:31 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Apr  4 21:21:31 2015 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=53883043

ekeyword: change "format" to "style" to avoid pylint warning

Python provides a builtin "format" we don't want to clobber.

 src/ekeyword/ekeyword.py          | 32 ++++++++++++++++----------------
 src/ekeyword/ekeyword_unittest.py | 36 ++++++++++++++++++------------------
 2 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index cac6298..bc3b2cf 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -117,13 +117,13 @@ def sort_keywords(arches):
 	return keywords
 
 
-def diff_keywords(old_keywords, new_keywords, format='color-inline'):
+def diff_keywords(old_keywords, new_keywords, style='color-inline'):
 	"""Show pretty diff between list of keywords
 
 	Args:
 	  old_keywords: The old set of KEYWORDS
 	  new_keywords: The new set of KEYWORDS
-	  format: The diff style
+	  style: The diff style
 
 	Returns:
 	  A string containing the diff output ready to shown to the user
@@ -138,7 +138,7 @@ def diff_keywords(old_keywords, new_keywords, format='color-inline'):
 
 			if tag in ('delete', 'replace'):
 				o = s.a[i0:i1]
-				if format == 'color-inline':
+				if style == 'color-inline':
 					o = colorize('bg_darkred', o)
 				else:
 					o = '-{%s}' % o
@@ -146,7 +146,7 @@ def diff_keywords(old_keywords, new_keywords, format='color-inline'):
 
 			if tag in ('insert', 'replace'):
 				o = s.b[j0:j1]
-				if format == 'color-inline':
+				if style == 'color-inline':
 					o = colorize('bg_darkgreen', o)
 				else:
 					o = '+{%s}' % o
@@ -219,7 +219,7 @@ def process_keywords(keywords, ops, arch_status=None):
 
 
 def process_content(ebuild, data, ops, arch_status=None, verbose=0,
-                    quiet=0, format='color-inline'):
+                    quiet=0, style='color-inline'):
 	"""Process |ops| for |data|"""
 	# Set up the user display style based on verbose/quiet settings.
 	if verbose > 1:
@@ -260,10 +260,10 @@ def process_content(ebuild, data, ops, arch_status=None, verbose=0,
 			new_keywords = sort_keywords(new_keywords)
 			line = '%s"%s"%s\n' % (m.group(1), ' '.join(new_keywords),
 			                       m.group(5))
-			if format in ('color-inline', 'inline'):
-				logit(diff_keywords(old_keywords, new_keywords, format=format))
+			if style in ('color-inline', 'inline'):
+				logit(diff_keywords(old_keywords, new_keywords, style=style))
 			else:
-				if format == 'long-multi':
+				if style == 'long-multi':
 					logit(' '.join(['%*s' % (len(keyword_to_arch(x)) + 1, x)
 					                for x in old_keywords]))
 					logit(' '.join(['%*s' % (len(keyword_to_arch(x)) + 1, x)
@@ -285,7 +285,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, format='color-inline'):
+                   dry_run=False, style='color-inline'):
 	"""Process |ops| for |ebuild|
 
 	Args:
@@ -296,7 +296,7 @@ def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
 	  verbose: Be verbose; show various status messages
 	  quiet: Be quiet; only show errors
 	  dry_run: Do not make any changes to |ebuild|; show what would be done
-	  format: The diff style
+	  style: The diff style
 
     Returns:
       Whether any updates were processed
@@ -304,7 +304,7 @@ def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
 	with io.open(ebuild, encoding='utf8') as f:
 		updated, content = process_content(
 			ebuild, f, ops, arch_status=arch_status,
-			verbose=verbose, quiet=quiet, format=format)
+			verbose=verbose, quiet=quiet, style=style)
 		if updated and not dry_run:
 			with io.open(ebuild, 'w', encoding='utf8') as f:
 				f.writelines(content)
@@ -448,7 +448,7 @@ def get_parser():
 		help='Be verbose while processing things')
 	parser.add_argument('-q', '--quiet', action='count', default=0,
 		help='Be quiet while processing things (only show errors)')
-	parser.add_argument('--format', default='auto',
+	parser.add_argument('--format', default='auto', dest='style',
 		choices=('auto', 'color-inline', 'inline', 'short-multi', 'long-multi'),
 		help='Selet output format for showing differences')
 	parser.add_argument('-V', '--version', default=False, action='store_true',
@@ -491,12 +491,12 @@ def main(argv):
 	if not work_args:
 		parser.error('need arches/ebuilds to process')
 
-	if opts.format == 'auto':
+	if opts.style == 'auto':
 		if not portage.db['/']['vartree'].settings.get('NOCOLOR', 'false').lower() in ('no', 'false'):
 			nocolor()
-			opts.format = 'short'
+			opts.style = 'short'
 		else:
-			opts.format = 'color-inline'
+			opts.style = 'color-inline'
 
 	arch_status = load_profile_data()
 	try:
@@ -507,7 +507,7 @@ 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, format=opts.format)
+		               dry_run=opts.dry_run, style=opts.style)
 
 	return os.EX_OK
 

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index b491db0..5141159 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -75,19 +75,19 @@ class TestDiffKeywords(unittest.TestCase):
 		ret = ekeyword.diff_keywords(['~a'], ['-a'])
 		self.assertNotEqual(ret, '')
 
-	def _testSmokeFormat(self, format):
+	def _testSmokeStyle(self, style):
 		return ekeyword.diff_keywords(
 			['~a', 'b', '-abcde'],
-			['a', '-b', '-abxde'], format=format)
+			['a', '-b', '-abxde'], style=style)
 
-	def testSmokeFormatColor(self):
-		"""Run a full smoke test for color-inline format"""
-		ret = self._testSmokeFormat('color-inline')
+	def testSmokeStyleColor(self):
+		"""Run a full smoke test for color-inline style"""
+		ret = self._testSmokeStyle('color-inline')
 		self.assertNotEqual(ret, '')
 
-	def testSmokeFormatNoColor(self):
-		"""Run a full smoke test for non-color-inline format"""
-		self._testSmokeFormat('nocolor')
+	def testSmokeStyleNoColor(self):
+		"""Run a full smoke test for non-color-inline style"""
+		self._testSmokeStyle('nocolor')
 
 
 class TestProcessKeywords(unittest.TestCase):
@@ -244,14 +244,14 @@ class TestProcessContent(unittest.TestCase):
 		self.assertFalse(updated)
 		self.assertEqual(ret, [' KEYWORDS=\n'])
 
-	def _testSmoke(self, format='color-inline', verbose=0, quiet=0):
+	def _testSmoke(self, style='color-inline', verbose=0, quiet=0):
 		ops = (
 			ekeyword.Op(None, 'arm', None),
 			ekeyword.Op('~', 'sparc', None),
 		)
 		ekeyword.process_content(
 			'asdf', ['KEYWORDS="arm"'], ops, verbose=verbose,
-			quiet=quiet, format=format)
+			quiet=quiet, style=style)
 
 	def testSmokeQuiet(self):
 		"""Smoke test for quiet mode"""
@@ -261,20 +261,20 @@ class TestProcessContent(unittest.TestCase):
 		"""Smoke test for verbose mode"""
 		self._testSmoke(verbose=10)
 
-	def testSmokeFormatColor(self):
-		"""Smoke test for color-inline format"""
+	def testSmokeStyleColor(self):
+		"""Smoke test for color-inline style"""
 		self._testSmoke('color-inline')
 
-	def testSmokeFormatInline(self):
-		"""Smoke test for inline format"""
+	def testSmokeStyleInline(self):
+		"""Smoke test for inline style"""
 		self._testSmoke('inline')
 
-	def testSmokeFormatShortMulti(self):
-		"""Smoke test for short-multi format"""
+	def testSmokeStyleShortMulti(self):
+		"""Smoke test for short-multi style"""
 		self._testSmoke('short-multi')
 
-	def testSmokeFormatLongMulti(self):
-		"""Smoke test for long-multi format"""
+	def testSmokeStyleLongMulti(self):
+		"""Smoke test for long-multi style"""
 		self._testSmoke('long-multi')
 
 


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2015-04-04 21:26 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2015-04-04 21:26 UTC (permalink / raw
  To: gentoo-commits

commit:     56cf23ea1bd90f9f850691dbf2052cd58aa99a98
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Apr  4 21:23:44 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Apr  4 21:23:44 2015 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=56cf23ea

ekeyword: fix crash when passing "" as the arch

 src/ekeyword/ekeyword.py          | 2 +-
 src/ekeyword/ekeyword_unittest.py | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index b0035da..7a0cc7d 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -478,7 +478,7 @@ def main(argv):
 			if arg in ('--format',):
 				if argv:
 					parse_args.append(argv.pop(0))
-		elif arg[0] == '-' and len(arg) == 2:
+		elif len(arg) == 2 and arg[0] == '-':
 			parse_args.append(arg)
 		else:
 			work_args.append(arg)

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 5141159..134dd80 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -372,6 +372,10 @@ class TestMain(unittest.TestCase):
 		ekeyword.main(['arm', '--dry-run', os.path.join(TESTDIR, 'process-1.ebuild')])
 		ekeyword.main(['--version', '--dry-run'])
 
+	def testEmptyString(self):
+		self.assertRaises(SystemExit, ekeyword.main,
+		                  ['', os.path.join(TESTDIR, 'process-1.ebuild')])
+
 
 if __name__ == '__main__':
 	unittest.main()


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2015-04-04 21:26 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2015-04-04 21:26 UTC (permalink / raw
  To: gentoo-commits

commit:     083b5fd4a51c54dc7154c03bcdb9ce4b665e5491
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Apr  4 21:21:55 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Apr  4 21:21:55 2015 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=083b5fd4

ekeyword: fix unused variable warnings

 src/ekeyword/ekeyword.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index bc3b2cf..b0035da 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -227,7 +227,7 @@ def process_content(ebuild, data, ops, arch_status=None, verbose=0,
 		def logit(msg):
 			print('%s: %s' % (disp_name, msg))
 	elif quiet > 1:
-		def logit(msg):
+		def logit(_msg):
 			pass
 	else:
 		# Chop the full path and the .ebuild suffix.
@@ -349,7 +349,7 @@ def load_profile_data(portdir=None, repo='gentoo'):
 			for line in f:
 				line = line.split('#', 1)[0].split()
 				if line:
-					arch, profile, status = line
+					arch, _profile, status = line
 					arch_status.setdefault(arch, status)
 					curr_status = profile_status[arch_status[arch]]
 					new_status = profile_status[status]
@@ -409,7 +409,7 @@ def ignorable_arg(arg, quiet=0):
 	return False
 
 
-def args_to_work(args, arch_status=None, repo='gentoo', quiet=0):
+def args_to_work(args, arch_status=None, _repo='gentoo', quiet=0):
 	"""Process |args| into a list of work itmes (ebuild/arches to update)"""
 	work = []
 	todo_arches = []


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2016-01-27 23:35 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2016-01-27 23:35 UTC (permalink / raw
  To: gentoo-commits

commit:     00e918798ece8a6fdf38ba2e5edad1c5b328c183
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 27 23:32:27 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Jan 27 23:32:27 2016 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=00e91879

ekeyword: allow passing arch_status={} to disable profile logic

 src/ekeyword/ekeyword.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 7a0cc7d..64f4eb0 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -168,7 +168,7 @@ def process_keywords(keywords, ops, arch_status=None):
 	for op, oarch, refarch in ops:
 		# Figure out which keywords we need to modify.
 		if oarch == 'all':
-			if not arch_status:
+			if arch_status is None:
 				raise ValueError('unable to process "all" w/out profiles.desc')
 			old_arches = set([keyword_to_arch(a) for a in new_keywords])
 			if op is None:


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2016-01-27 23:35 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2016-01-27 23:35 UTC (permalink / raw
  To: gentoo-commits

commit:     1b33e0ae109e11b1ee696ea6c6919bb86ecbc66f
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 27 23:32:57 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Jan 27 23:32:57 2016 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=1b33e0ae

ekeyword: fix "all" keyword handling w/-keywords

When an ebuild has a keyword like '-sparc', we don't want the magic
"all" or "~all" keywords to change it to 'sparc' or '~sparc'.

 src/ekeyword/ekeyword.py          | 8 ++++++++
 src/ekeyword/ekeyword_unittest.py | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 64f4eb0..e4a8197 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -180,9 +180,17 @@ def process_keywords(keywords, ops, arch_status=None):
 				# master list.  If it lacks some keywords, then we might miss
 				# somethings here, but not much we can do.
 				arches = old_arches
+
 			# We ignore the glob arch as we never want to tweak it.
 			if '*' in arches:
 				arches.remove('*')
+
+			# For keywords that are explicitly disabled, do not update.  When
+			# people use `ekeyword ~all ...` or `ekeyword all ...`, they rarely
+			# (if ever) want to change a '-sparc' to 'sparc' or '-sparc' to
+			# '~sparc'.  We force people to explicitly do `ekeyword sparc ...`
+			# in these cases.
+			arches = [x for x in arches if '-' + x not in new_keywords]
 		else:
 			arches = (oarch,)
 

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 134dd80..473113b 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -196,6 +196,14 @@ class TestProcessKeywords(unittest.TestCase):
 		self._test('-* ~* * alpha arm arm64 m68k', ops,
 		           '-* ~* * ~alpha arm ~arm64 ~m68k', arch_status)
 
+	def testAllDisabled(self):
+		"""Make sure ~all does not change -arch to ~arch"""
+		ops = (
+			ekeyword.Op('~', 'all', None),
+		)
+		self._test('alpha -sparc ~x86', ops,
+		           '~alpha -sparc ~x86', {})
+
 
 class TestProcessContent(unittest.TestCase):
 	"""Tests for process_content"""


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2017-02-16  7:25 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2017-02-16  7:25 UTC (permalink / raw
  To: gentoo-commits

commit:     aa32986eecd93ed87cbdb347c3ee4f943f397510
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 16 07:24:35 2017 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Feb 16 07:24:35 2017 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=aa32986e

ekeyword: add a linter helper

 src/ekeyword/.pylintrc            | 37 +++++++++++++++++++++++++++++
 src/ekeyword/ekeyword.py          | 15 ++++++++----
 src/ekeyword/ekeyword_unittest.py |  2 ++
 src/ekeyword/pylint               | 49 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+), 4 deletions(-)

diff --git a/src/ekeyword/.pylintrc b/src/ekeyword/.pylintrc
new file mode 100644
index 0000000..6a040d8
--- /dev/null
+++ b/src/ekeyword/.pylintrc
@@ -0,0 +1,37 @@
+[MESSAGES CONTROL]
+# Disable the message, report, category or checker with the given id(s). You
+# can either give multiple identifier separated by comma (,) or put this option
+# multiple times (only on the command line, not in the configuration file where
+# it should appear only once).
+disable=
+	missing-docstring,
+	too-many-lines,
+	too-many-branches,
+	too-many-statements,
+	too-few-public-methods,
+	too-many-instance-attributes,
+	too-many-public-methods,
+	too-many-locals,
+	too-many-arguments,
+	locally-enabled,
+	locally-disabled,
+	fixme,
+	bad-whitespace,
+	bad-continuation,
+	invalid-name,
+
+[REPORTS]
+reports=no
+
+[FORMAT]
+max-line-length=80
+indent-string='\t'
+
+[SIMILARITIES]
+min-similarity-lines=20
+
+[VARIABLES]
+dummy-variables-rgx=_
+
+[DESIGN]
+max-parents=10

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index a36dcd3..56e284b 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -179,7 +179,7 @@ def process_keywords(keywords, ops, arch_status=None):
 				# Process all possible keywords.  We use the arch_status as a
 				# master list.  If it lacks some keywords, then we might miss
 				# somethings here, but not much we can do.
-				arches = old_arches
+				arches = list(old_arches)
 
 			# We ignore the glob arch as we never want to tweak it.
 			if '*' in arches:
@@ -192,7 +192,7 @@ def process_keywords(keywords, ops, arch_status=None):
 			# in these cases.
 			arches = [x for x in arches if '-' + x not in new_keywords]
 		else:
-			arches = (oarch,)
+			arches = [oarch]
 
 		if refarch:
 			# Figure out the state for this arch based on the reference arch.
@@ -319,6 +319,13 @@ def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
 	return updated
 
 
+def portage_settings():
+	"""Return the portage settings we care about."""
+	# Portage creates the db member on the fly which confuses the linter.
+	# pylint: disable=no-member
+	return portage.db['/']['vartree'].settings
+
+
 def load_profile_data(portdir=None, repo='gentoo'):
 	"""Load the list of known arches from the tree
 
@@ -331,7 +338,7 @@ def load_profile_data(portdir=None, repo='gentoo'):
 	  {'x86': 'stable', 'mips': 'dev', ...}
 	"""
 	if portdir is None:
-		portdir = portage.db['/']['vartree'].settings.repositories[repo].location
+		portdir = portage_settings().repositories[repo].location
 
 	arch_status = {}
 
@@ -497,7 +504,7 @@ def main(argv):
 		parser.error('need arches/ebuilds to process')
 
 	if opts.style == 'auto':
-		if not portage.db['/']['vartree'].settings.get('NOCOLOR', 'false').lower() in ('no', 'false'):
+		if not portage_settings().get('NOCOLOR', 'false').lower() in ('no', 'false'):
 			nocolor()
 			opts.style = 'short'
 		else:

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 7b9017e..be84cc1 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -3,6 +3,8 @@
 # Distributed under the terms of the GNU General Public License v2
 # Written by Mike Frysinger <vapier@gentoo.org>
 
+# pylint: disable=no-self-use
+
 """Unittests for ekeyword"""
 
 import os

diff --git a/src/ekeyword/pylint b/src/ekeyword/pylint
new file mode 100755
index 0000000..3a9a368
--- /dev/null
+++ b/src/ekeyword/pylint
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+"""Run pylint with the right settings."""
+
+from __future__ import print_function
+
+import os
+import sys
+
+
+def find_all_modules(source_root):
+	"""Locate all python modules in the tree for scanning"""
+	ret = []
+
+	for root, _dirs, files in os.walk(source_root, topdown=False):
+		# Add all of the .py modules in the tree.
+		ret += [os.path.join(root, x) for x in files if x.endswith('.py')]
+
+	# Add the main scripts that don't end in .py.
+	ret += [os.path.join(source_root, x) for x in ('pylint',)]
+
+	return ret
+
+
+def main(argv):
+	"""The main entry point"""
+	source_root = os.path.dirname(os.path.realpath(__file__))
+
+	if not argv:
+		argv = find_all_modules(source_root)
+
+	pympath = source_root
+	pythonpath = os.environ.get('PYTHONPATH')
+	if pythonpath is None:
+		pythonpath = pympath
+	else:
+		pythonpath = pympath + ':' + pythonpath
+	os.environ['PYTHONPATH'] = pythonpath
+
+	pylintrc = os.path.join(source_root, '.pylintrc')
+	cmd = ['pylint', '--rcfile', pylintrc]
+	os.execvp(cmd[0], cmd + argv)
+
+
+if __name__ == '__main__':
+	sys.exit(main(sys.argv[1:]))


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2017-02-16  7:25 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2017-02-16  7:25 UTC (permalink / raw
  To: gentoo-commits

commit:     c688fa044b7b5e8e72ae6e9cc7f54fc35e1ff0c1
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 16 07:12:52 2017 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Feb 16 07:12:52 2017 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=c688fa04

ekeyword: change --version to use builtin version action

Minor clean up here.

 src/ekeyword/ekeyword.py          |  5 +----
 src/ekeyword/ekeyword_unittest.py | 11 ++++++++---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index e4a8197..a36dcd3 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -459,7 +459,7 @@ def get_parser():
 	parser.add_argument('--format', default='auto', dest='style',
 		choices=('auto', 'color-inline', 'inline', 'short-multi', 'long-multi'),
 		help='Selet output format for showing differences')
-	parser.add_argument('-V', '--version', default=False, action='store_true',
+	parser.add_argument('-V', '--version', action='version', version=VERSION,
 		help='Show version information')
 	return parser
 
@@ -493,9 +493,6 @@ def main(argv):
 
 	parser = get_parser()
 	opts = parser.parse_args(parse_args)
-	if opts.version:
-		print('version: %s' % VERSION)
-		return os.EX_OK
 	if not work_args:
 		parser.error('need arches/ebuilds to process')
 

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index 473113b..7b9017e 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -378,11 +378,16 @@ class TestMain(unittest.TestCase):
 
 	def testSmoke(self):
 		ekeyword.main(['arm', '--dry-run', os.path.join(TESTDIR, 'process-1.ebuild')])
-		ekeyword.main(['--version', '--dry-run'])
+
+	def testVersion(self):
+		with self.assertRaises(SystemExit) as e:
+			ekeyword.main(['--version', '--dry-run'])
+		self.assertEqual(e.exception.code, os.EX_OK)
 
 	def testEmptyString(self):
-		self.assertRaises(SystemExit, ekeyword.main,
-		                  ['', os.path.join(TESTDIR, 'process-1.ebuild')])
+		with self.assertRaises(SystemExit) as e:
+			ekeyword.main(['', os.path.join(TESTDIR, 'process-1.ebuild')])
+		self.assertNotEqual(e.exception.code, os.EX_OK)
 
 
 if __name__ == '__main__':


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2017-02-18  5:24 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2017-02-18  5:24 UTC (permalink / raw
  To: gentoo-commits

commit:     76b7677ea2f95e11f5332dbcb71c97578d18deac
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 18 05:24:47 2017 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Feb 18 05:24:47 2017 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=76b7677e

ekeyword: enable bad-whitespace check

 src/ekeyword/.pylintrc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/ekeyword/.pylintrc b/src/ekeyword/.pylintrc
index 6a040d8..cd5b31e 100644
--- a/src/ekeyword/.pylintrc
+++ b/src/ekeyword/.pylintrc
@@ -16,7 +16,6 @@ disable=
 	locally-enabled,
 	locally-disabled,
 	fixme,
-	bad-whitespace,
 	bad-continuation,
 	invalid-name,
 


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2017-03-08  0:16 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2017-03-08  0:16 UTC (permalink / raw
  To: gentoo-commits

commit:     4759a27d5fd878b59201fb48233e066eccf03be2
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Mar  8 00:04:15 2017 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Mar  8 00:04:15 2017 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=4759a27d

ekeyword: misc source touchups

No functional changes here!

 src/ekeyword/ekeyword.py          | 8 ++++++--
 src/ekeyword/ekeyword_unittest.py | 7 +++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index 56e284b..6d09001 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -99,6 +99,10 @@ def sort_keywords(arches):
 			keywords.append(g)
 
 	def arch_key(keyword):
+		"""Callback for python sorting functions
+
+		Used to turn a Gentoo keyword into a sortable form.
+		"""
 		# Sort independent of leading marker (~ or -).
 		arch = keyword_to_arch(keyword)
 
@@ -306,8 +310,8 @@ def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
 	  dry_run: Do not make any changes to |ebuild|; show what would be done
 	  style: The diff style
 
-    Returns:
-      Whether any updates were processed
+	Returns:
+	  Whether any updates were processed
 	"""
 	with io.open(ebuild, encoding='utf8') as f:
 		updated, content = process_content(

diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index be84cc1..3465dfb 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -7,6 +7,8 @@
 
 """Unittests for ekeyword"""
 
+from __future__ import print_function
+
 import os
 import tempfile
 import unittest
@@ -21,14 +23,17 @@ class TestSortKeywords(unittest.TestCase):
 	"""Tests for sort_keywords"""
 
 	def _test(self, input_data, exp_data):
+		"""Sort |input_data| and make sure it matches |exp_data|"""
 		output_data = ekeyword.sort_keywords(input_data.split())
 		self.assertEqual(exp_data.split(), output_data)
 
 	def testNull(self):
+		"""Verify whitespace is collapsed"""
 		self._test('', '')
 		self._test('   		 ', '')
 
 	def testGlob(self):
+		"""Verify globs get sorted before all others"""
 		self._test('* arm', '* arm')
 		self._test('arm -* x86', '-* arm x86')
 		self._test('hppa ~* amd64', '~* amd64 hppa')
@@ -356,6 +361,7 @@ class TestLoadProfileData(unittest.TestCase):
 
 
 class TestArgToOps(unittest.TestCase):
+	"""Tests for arg_to_op()"""
 
 	def _test(self, arg, op):
 		self.assertEqual(ekeyword.arg_to_op(arg), ekeyword.Op(*op))
@@ -377,6 +383,7 @@ class TestArgToOps(unittest.TestCase):
 
 
 class TestMain(unittest.TestCase):
+	"""Tests for the main entry point"""
 
 	def testSmoke(self):
 		ekeyword.main(['arm', '--dry-run', os.path.join(TESTDIR, 'process-1.ebuild')])


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
@ 2017-03-08  0:16 Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2017-03-08  0:16 UTC (permalink / raw
  To: gentoo-commits

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):


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-03-08  0:16 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-27 23:35 [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/ Mike Frysinger
  -- strict thread matches above, loose matches on Subject: below --
2017-03-08  0:16 Mike Frysinger
2017-03-08  0:16 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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox