Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
Date: Sat, 25 Jan 2014 22:01:02
Message-Id: 1390687207.0482abe75ed71c5d0b6bb55f0d98bf9388861c08.vapier@gentoo
1 commit: 0482abe75ed71c5d0b6bb55f0d98bf9388861c08
2 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jan 25 22:00:07 2014 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Sat Jan 25 22:00:07 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=0482abe7
7
8 ekeyword: fix python3 compat issues
9
10 Get the unittests passing w/python-3.3.
11
12 ---
13 src/ekeyword/ekeyword.py | 36 ++++++++++++++----------------------
14 1 file changed, 14 insertions(+), 22 deletions(-)
15
16 diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
17 index d8e0ed1..3fa74c1 100755
18 --- a/src/ekeyword/ekeyword.py
19 +++ b/src/ekeyword/ekeyword.py
20 @@ -41,6 +41,7 @@ from __future__ import print_function
21 import argparse
22 import collections
23 import difflib
24 +import io
25 import os
26 import re
27 import sys
28 @@ -77,30 +78,21 @@ def sort_keywords(arches):
29 arches.remove(g)
30 keywords.append(g)
31
32 - def arch_cmp(a1, a2):
33 + def arch_key(keyword):
34 # Sort independent of leading marker (~ or -).
35 - a1 = keyword_to_arch(a1)
36 - a2 = keyword_to_arch(a2)
37 + arch = keyword_to_arch(keyword)
38
39 # A keyword may have a "-" in it. We split on that and sort
40 # by the two resulting items. The part after the hyphen is
41 # the primary key.
42 - if '-' in a1:
43 - arch1, plat1 = a1.split('-', 1)
44 + if '-' in arch:
45 + arch, plat = arch.split('-', 1)
46 else:
47 - arch1, plat1 = a1, ''
48 - if '-' in a2:
49 - arch2, plat2 = a2.split('-', 1)
50 - else:
51 - arch2, plat2 = a2, ''
52 + arch, plat = arch, ''
53
54 - ret = cmp(plat1, plat2)
55 - if ret:
56 - return ret
57 - else:
58 - return cmp(arch1, arch2)
59 + return (plat, arch)
60
61 - keywords += sorted(arches, cmp=arch_cmp)
62 + keywords += sorted(arches, key=arch_key)
63
64 return keywords
65
66 @@ -133,8 +125,8 @@ def diff_keywords(old_keywords, new_keywords, format='color-inline'):
67
68 return output
69
70 - sold = ' '.join(old_keywords)
71 - snew = ' '.join(new_keywords)
72 + sold = str(' '.join(old_keywords))
73 + snew = str(' '.join(new_keywords))
74 s = difflib.SequenceMatcher(str.isspace, sold, snew, autojunk=False)
75 return show_diff(s)
76
77 @@ -263,12 +255,12 @@ def process_content(ebuild, data, ops, arch_status=None, verbose=0,
78 def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0,
79 dry_run=False, format='color-inline'):
80 """Process |ops| for |ebuild|"""
81 - with open(ebuild, 'rb') as f:
82 + with io.open(ebuild, encoding='utf8') as f:
83 updated, content = process_content(
84 ebuild, f, ops, arch_status=arch_status,
85 verbose=verbose, quiet=quiet, format=format)
86 if updated and not dry_run:
87 - with open(ebuild, 'wb') as f:
88 + with io.open(ebuild, 'w', encoding='utf8') as f:
89 f.writelines(content)
90
91
92 @@ -396,9 +388,9 @@ def get_parser():
93 formatter_class=argparse.RawDescriptionHelpFormatter)
94 parser.add_argument('-n', '--dry-run', default=False, action='store_true',
95 help='Show what would be changed, but do not commit')
96 - parser.add_argument('-v', '--verbose', action='count',
97 + parser.add_argument('-v', '--verbose', action='count', default=0,
98 help='Be verbose while processing things')
99 - parser.add_argument('-q', '--quiet', action='count',
100 + parser.add_argument('-q', '--quiet', action='count', default=0,
101 help='Be quiet while processing things (only show errors)')
102 parser.add_argument('--format', default='auto',
103 choices=('auto', 'color-inline', 'inline', 'short-multi', 'long-multi'),