Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/ekeyword/
Date: Fri, 24 Apr 2020 08:06:15
Message-Id: 1587714984.459cfba47d2522553d076ebaabf656ce8f29cf11.mgorny@gentoo
1 commit: 459cfba47d2522553d076ebaabf656ce8f29cf11
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri Apr 24 07:55:49 2020 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Fri Apr 24 07:56:24 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=459cfba4
7
8 ekeyword: Use now-common load_profile_data() from eshowkw
9
10 This also fixes 'all' to process all architectures using stable keywords
11 and not just these having stable profiles.
12
13 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
14
15 pym/gentoolkit/ekeyword/ekeyword.py | 62 ++--------------------------
16 pym/gentoolkit/ekeyword/ekeyword_unittest.py | 36 ----------------
17 2 files changed, 3 insertions(+), 95 deletions(-)
18
19 diff --git a/pym/gentoolkit/ekeyword/ekeyword.py b/pym/gentoolkit/ekeyword/ekeyword.py
20 index cf2a15e..a86a9c2 100755
21 --- a/pym/gentoolkit/ekeyword/ekeyword.py
22 +++ b/pym/gentoolkit/ekeyword/ekeyword.py
23 @@ -47,6 +47,8 @@ import re
24 import subprocess
25 import sys
26
27 +from gentoolkit.profile import load_profile_data
28 +
29 import portage
30 from portage.output import colorize, nocolor
31
32 @@ -179,7 +181,7 @@ def process_keywords(keywords, ops, arch_status=None):
33 if op is None:
34 # Process just stable keywords.
35 arches = [k for k, v in arch_status.items()
36 - if v == 'stable' and k in old_arches]
37 + if v[1] == 'arch' and k in old_arches]
38 else:
39 # Process all possible keywords. We use the arch_status as a
40 # master list. If it lacks some keywords, then we might miss
41 @@ -346,64 +348,6 @@ def portage_settings():
42 return portage.db[portage.root]['vartree'].settings
43
44
45 -def load_profile_data(portdir=None, repo=None):
46 - """Load the list of known arches from the tree
47 -
48 - Args:
49 - portdir: The repository to load all data from (and ignore |repo|)
50 - repo: Look up this repository by name to locate profile data
51 -
52 - Returns:
53 - A dict mapping the keyword to its preferred state:
54 - {'x86': 'stable', 'mips': 'dev', ...}
55 - """
56 - if repo is None:
57 - repo = portage_settings().repositories.mainRepo().name
58 - if portdir is None:
59 - portdir = portage_settings().repositories[repo].location
60 -
61 - arch_status = {}
62 -
63 - try:
64 - arch_list = os.path.join(portdir, 'profiles', 'arch.list')
65 - with open(arch_list) as f:
66 - for line in f:
67 - line = line.split('#', 1)[0].strip()
68 - if line:
69 - arch_status[line] = None
70 - except IOError:
71 - pass
72 -
73 - try:
74 - profile_status = {
75 - 'stable': 0,
76 - 'dev': 1,
77 - 'exp': 2,
78 - None: 3,
79 - }
80 - profiles_list = os.path.join(portdir, 'profiles', 'profiles.desc')
81 - with open(profiles_list) as f:
82 - for line in f:
83 - line = line.split('#', 1)[0].split()
84 - if line:
85 - arch, _profile, status = line
86 - arch_status.setdefault(arch, status)
87 - curr_status = profile_status[arch_status[arch]]
88 - new_status = profile_status[status]
89 - if new_status < curr_status:
90 - arch_status[arch] = status
91 - except IOError:
92 - pass
93 -
94 - if arch_status:
95 - arch_status['all'] = None
96 - else:
97 - warning('could not read profile files: %s' % arch_list)
98 - warning('will not be able to verify args are correct')
99 -
100 - return arch_status
101 -
102 -
103 def arg_to_op(arg):
104 """Convert a command line |arg| to an Op"""
105 arch_prefixes = ('-', '~', '^')
106
107 diff --git a/pym/gentoolkit/ekeyword/ekeyword_unittest.py b/pym/gentoolkit/ekeyword/ekeyword_unittest.py
108 index 5e66afe..7446914 100755
109 --- a/pym/gentoolkit/ekeyword/ekeyword_unittest.py
110 +++ b/pym/gentoolkit/ekeyword/ekeyword_unittest.py
111 @@ -343,42 +343,6 @@ class TestProcessEbuild(unittest.TestCase):
112 self.assertEqual(m.call_count, 0)
113
114
115 -class TestLoadProfileData(unittest.TestCase):
116 - """Tests for load_profile_data"""
117 -
118 - def _test(self, subdir):
119 - portdir = os.path.join(TESTDIR, 'profiles', subdir)
120 - return ekeyword.load_profile_data(portdir=portdir)
121 -
122 - def testLoadBoth(self):
123 - """Test loading both arch.list and profiles.desc"""
124 - ret = self._test('both')
125 - self.assertIn('arm', ret)
126 - self.assertEqual(ret['arm'], 'stable')
127 - self.assertIn('arm64', ret)
128 - self.assertEqual(ret['arm64'], 'exp')
129 -
130 - def testLoadArchOnly(self):
131 - """Test loading only arch.list"""
132 - ret = self._test('arch-only')
133 - self.assertIn('arm', ret)
134 - self.assertEqual(ret['arm'], None)
135 - self.assertIn('x86-solaris', ret)
136 -
137 - def testLoadProfilesOnly(self):
138 - """Test loading only profiles.desc"""
139 - ret = self._test('profiles-only')
140 - self.assertIn('arm', ret)
141 - self.assertEqual(ret['arm'], 'stable')
142 - self.assertIn('arm64', ret)
143 - self.assertEqual(ret['arm64'], 'exp')
144 -
145 - def testLoadNone(self):
146 - """Test running when neither files exists"""
147 - ret = self._test('none')
148 - self.assertEqual(ret, {})
149 -
150 -
151 class TestArgToOps(unittest.TestCase):
152 """Tests for arg_to_op()"""