Fix user profile display

Without this patch, issuing 'bindep --profiles' would fail
on groups that aren't a 2-tuple, because we assume
always two elements and unpack these two [1].

This is a problem, because in the case of loci [2], it prevents
a user from predicting the list of packages to be installed
on the system in a read only fashion.

Additionally, the current --profile function is showing
platform details under "Configuration profiles" AND
"Platform Profiles", as platforms are not filtered by the
profiles() function.

This patch solves the two linked problems by:
- ensuring the lists of profiles are flattened
- ensure the profiles are following the _partition function.

[1]: cec3a7576b/bindep/depends.py (L276)
[2]: 8982c3ae71/bindep.txt (L13)

Change-Id: Ied4ac178e20daf35f105e2acae0a2b3e11219a56
This commit is contained in:
Jean-Philippe Evrard 2018-07-23 17:46:29 +02:00
parent cec3a7576b
commit 94dd535faa
2 changed files with 13 additions and 2 deletions

View File

@ -273,8 +273,14 @@ class Depends(object):
def profiles(self):
profiles = set()
for rule in self._rules:
for _, selector in rule[1]:
profiles.add(selector)
# Partition rules, but keep only the user ones
_, user_profiles = self._partition(rule)
for profile in user_profiles:
# Flatten a series of AND conditionals in a user rule
if isinstance(profile, list):
profiles.update([rule[1] for rule in profile])
elif isinstance(profile, tuple):
profiles.add(profile[1])
return sorted(profiles)
def codenamebits(self, distro_id, codename):

View File

@ -67,6 +67,11 @@ class TestDepends(TestCase):
depends = Depends("")
self.assertEqual([], depends.profiles())
def test_3tuple(self):
depends = Depends(u"erlang [(infra rabbitmq hipe)]\n")
self.assertEqual(sorted([u'infra', u'rabbitmq', u'hipe']),
depends.profiles())
def test_platform_profiles_succeeds(self):
with DistroFixture('Ubuntu'):
depends = Depends("")