|
|
7a536a |
From 3c758a4ea670fab1f4b55fa878ebf2b2ff4b678b Mon Sep 17 00:00:00 2001
|
|
|
7a536a |
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
|
|
|
7a536a |
Date: Tue, 28 Apr 2020 09:08:05 +0200
|
|
|
7a536a |
Subject: [PATCH] Handle empty comps group name (RhBug:1826198)
|
|
|
7a536a |
|
|
|
7a536a |
Don't crash on empty comps group/environment name. In outputs, use the
|
|
|
7a536a |
"<name-unset>" placeholder instead of the name.
|
|
|
7a536a |
|
|
|
7a536a |
https://bugzilla.redhat.com/show_bug.cgi?id=1826198
|
|
|
7a536a |
---
|
|
|
7a536a |
dnf/cli/commands/group.py | 4 ++--
|
|
|
7a536a |
dnf/cli/output.py | 16 ++++++++++------
|
|
|
7a536a |
dnf/comps.py | 11 ++++++++++-
|
|
|
7a536a |
dnf/db/group.py | 12 ++++++++----
|
|
|
7a536a |
tests/repos/main_comps.xml | 7 +++++++
|
|
|
7a536a |
tests/support.py | 2 +-
|
|
|
7a536a |
tests/test_comps.py | 6 +++---
|
|
|
7a536a |
tests/test_groups.py | 9 +++++++++
|
|
|
7a536a |
8 files changed, 50 insertions(+), 17 deletions(-)
|
|
|
7a536a |
|
|
|
7a536a |
diff --git a/dnf/cli/commands/group.py b/dnf/cli/commands/group.py
|
|
|
7a536a |
index f535a50980..4ffd3b89c8 100644
|
|
|
7a536a |
--- a/dnf/cli/commands/group.py
|
|
|
7a536a |
+++ b/dnf/cli/commands/group.py
|
|
|
7a536a |
@@ -177,7 +177,7 @@ def _list(self, userlist):
|
|
|
7a536a |
def _out_grp(sect, group):
|
|
|
7a536a |
if not done:
|
|
|
7a536a |
print(sect)
|
|
|
7a536a |
- msg = ' %s' % group.ui_name
|
|
|
7a536a |
+ msg = ' %s' % (group.ui_name if group.ui_name is not None else _("<name-unset>"))
|
|
|
7a536a |
if print_ids:
|
|
|
7a536a |
msg += ' (%s)' % group.id
|
|
|
7a536a |
if group.lang_only:
|
|
|
7a536a |
@@ -188,7 +188,7 @@ def _out_env(sect, envs):
|
|
|
7a536a |
if envs:
|
|
|
7a536a |
print(sect)
|
|
|
7a536a |
for e in envs:
|
|
|
7a536a |
- msg = ' %s' % e.ui_name
|
|
|
7a536a |
+ msg = ' %s' % (e.ui_name if e.ui_name is not None else _("<name-unset>"))
|
|
|
7a536a |
if print_ids:
|
|
|
7a536a |
msg += ' (%s)' % e.id
|
|
|
7a536a |
print(msg)
|
|
|
7a536a |
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
|
|
|
7a536a |
index 67eab80b19..2585a5c773 100644
|
|
|
7a536a |
--- a/dnf/cli/output.py
|
|
|
7a536a |
+++ b/dnf/cli/output.py
|
|
|
7a536a |
@@ -1221,47 +1221,51 @@ def _add_line(lines, data, a_wid, po, obsoletes=[]):
|
|
|
7a536a |
lines.append((name, "", "", "", "", "", ""))
|
|
|
7a536a |
pkglist_lines.append((action, lines))
|
|
|
7a536a |
if self.base._history:
|
|
|
7a536a |
+ def format_line(group):
|
|
|
7a536a |
+ name = group.getName()
|
|
|
7a536a |
+ return (name if name else _("<name-unset>"), "", "", "", "", "", "")
|
|
|
7a536a |
+
|
|
|
7a536a |
install_env_group = self.base._history.env._installed
|
|
|
7a536a |
if install_env_group:
|
|
|
7a536a |
action = _("Installing Environment Groups")
|
|
|
7a536a |
lines = []
|
|
|
7a536a |
for group in install_env_group.values():
|
|
|
7a536a |
- lines.append((group.getName(), "", "", "", "", "", ""))
|
|
|
7a536a |
+ lines.append(format_line(group))
|
|
|
7a536a |
pkglist_lines.append((action, lines))
|
|
|
7a536a |
upgrade_env_group = self.base._history.env._upgraded
|
|
|
7a536a |
if upgrade_env_group:
|
|
|
7a536a |
action = _("Upgrading Environment Groups")
|
|
|
7a536a |
lines = []
|
|
|
7a536a |
for group in upgrade_env_group.values():
|
|
|
7a536a |
- lines.append((group.getName(), "", "", "", "", "", ""))
|
|
|
7a536a |
+ lines.append(format_line(group))
|
|
|
7a536a |
pkglist_lines.append((action, lines))
|
|
|
7a536a |
remove_env_group = self.base._history.env._removed
|
|
|
7a536a |
if remove_env_group:
|
|
|
7a536a |
action = _("Removing Environment Groups")
|
|
|
7a536a |
lines = []
|
|
|
7a536a |
for group in remove_env_group.values():
|
|
|
7a536a |
- lines.append((group.getName(), "", "", "", "", "", ""))
|
|
|
7a536a |
+ lines.append(format_line(group))
|
|
|
7a536a |
pkglist_lines.append((action, lines))
|
|
|
7a536a |
install_group = self.base._history.group._installed
|
|
|
7a536a |
if install_group:
|
|
|
7a536a |
action = _("Installing Groups")
|
|
|
7a536a |
lines = []
|
|
|
7a536a |
for group in install_group.values():
|
|
|
7a536a |
- lines.append((group.getName(), "", "", "", "", "", ""))
|
|
|
7a536a |
+ lines.append(format_line(group))
|
|
|
7a536a |
pkglist_lines.append((action, lines))
|
|
|
7a536a |
upgrade_group = self.base._history.group._upgraded
|
|
|
7a536a |
if upgrade_group:
|
|
|
7a536a |
action = _("Upgrading Groups")
|
|
|
7a536a |
lines = []
|
|
|
7a536a |
for group in upgrade_group.values():
|
|
|
7a536a |
- lines.append((group.getName(), "", "", "", "", "", ""))
|
|
|
7a536a |
+ lines.append(format_line(group))
|
|
|
7a536a |
pkglist_lines.append((action, lines))
|
|
|
7a536a |
remove_group = self.base._history.group._removed
|
|
|
7a536a |
if remove_group:
|
|
|
7a536a |
action = _("Removing Groups")
|
|
|
7a536a |
lines = []
|
|
|
7a536a |
for group in remove_group.values():
|
|
|
7a536a |
- lines.append((group.getName(), "", "", "", "", "", ""))
|
|
|
7a536a |
+ lines.append(format_line(group))
|
|
|
7a536a |
pkglist_lines.append((action, lines))
|
|
|
7a536a |
# show skipped conflicting packages
|
|
|
7a536a |
if not self.conf.best and self.base._goal.actions & forward_actions:
|
|
|
7a536a |
diff --git a/dnf/comps.py b/dnf/comps.py
|
|
|
7a536a |
index 316d647087..4ca15b1e07 100644
|
|
|
7a536a |
--- a/dnf/comps.py
|
|
|
7a536a |
+++ b/dnf/comps.py
|
|
|
7a536a |
@@ -75,7 +75,16 @@ def _by_pattern(pattern, case_sensitive, sqn):
|
|
|
7a536a |
else:
|
|
|
7a536a |
match = re.compile(fnmatch.translate(pattern), flags=re.I).match
|
|
|
7a536a |
|
|
|
7a536a |
- return {g for g in sqn if match(g.name) or match(g.id) or match(g.ui_name)}
|
|
|
7a536a |
+ ret = set()
|
|
|
7a536a |
+ for g in sqn:
|
|
|
7a536a |
+ if match(g.id):
|
|
|
7a536a |
+ ret.add(g)
|
|
|
7a536a |
+ elif g.name is not None and match(g.name):
|
|
|
7a536a |
+ ret.add(g)
|
|
|
7a536a |
+ elif g.ui_name is not None and match(g.ui_name):
|
|
|
7a536a |
+ ret.add(g)
|
|
|
7a536a |
+
|
|
|
7a536a |
+ return ret
|
|
|
7a536a |
|
|
|
7a536a |
|
|
|
7a536a |
def _fn_display_order(group):
|
|
|
7a536a |
diff --git a/dnf/db/group.py b/dnf/db/group.py
|
|
|
7a536a |
index e3a087760b..5d7e18d1a8 100644
|
|
|
7a536a |
--- a/dnf/db/group.py
|
|
|
7a536a |
+++ b/dnf/db/group.py
|
|
|
7a536a |
@@ -78,8 +78,10 @@ def _get_obj_id(self, obj):
|
|
|
7a536a |
def new(self, obj_id, name, translated_name, pkg_types):
|
|
|
7a536a |
swdb_group = self.history.swdb.createCompsGroupItem()
|
|
|
7a536a |
swdb_group.setGroupId(obj_id)
|
|
|
7a536a |
- swdb_group.setName(name)
|
|
|
7a536a |
- swdb_group.setTranslatedName(translated_name)
|
|
|
7a536a |
+ if name is not None:
|
|
|
7a536a |
+ swdb_group.setName(name)
|
|
|
7a536a |
+ if translated_name is not None:
|
|
|
7a536a |
+ swdb_group.setTranslatedName(translated_name)
|
|
|
7a536a |
swdb_group.setPackageTypes(pkg_types)
|
|
|
7a536a |
return swdb_group
|
|
|
7a536a |
|
|
|
7a536a |
@@ -136,8 +138,10 @@ def _get_obj_id(self, obj):
|
|
|
7a536a |
def new(self, obj_id, name, translated_name, pkg_types):
|
|
|
7a536a |
swdb_env = self.history.swdb.createCompsEnvironmentItem()
|
|
|
7a536a |
swdb_env.setEnvironmentId(obj_id)
|
|
|
7a536a |
- swdb_env.setName(name)
|
|
|
7a536a |
- swdb_env.setTranslatedName(translated_name)
|
|
|
7a536a |
+ if name is not None:
|
|
|
7a536a |
+ swdb_env.setName(name)
|
|
|
7a536a |
+ if translated_name is not None:
|
|
|
7a536a |
+ swdb_env.setTranslatedName(translated_name)
|
|
|
7a536a |
swdb_env.setPackageTypes(pkg_types)
|
|
|
7a536a |
return swdb_env
|
|
|
7a536a |
|
|
|
7a536a |
diff --git a/tests/repos/main_comps.xml b/tests/repos/main_comps.xml
|
|
|
7a536a |
index 9e694d13a5..584bb25b3a 100644
|
|
|
7a536a |
--- a/tests/repos/main_comps.xml
|
|
|
7a536a |
+++ b/tests/repos/main_comps.xml
|
|
|
7a536a |
@@ -49,6 +49,13 @@
|
|
|
7a536a |
<packagereq type="optional">brokendeps</packagereq>
|
|
|
7a536a |
</packagelist>
|
|
|
7a536a |
</group>
|
|
|
7a536a |
+ <group>
|
|
|
7a536a |
+ <id>missing-name-group</id>
|
|
|
7a536a |
+ <name></name>
|
|
|
7a536a |
+ <packagelist>
|
|
|
7a536a |
+ <packagereq type="mandatory">meaning-of-life</packagereq>
|
|
|
7a536a |
+ </packagelist>
|
|
|
7a536a |
+ </group>
|
|
|
7a536a |
<category>
|
|
|
7a536a |
<id>base-system</id>
|
|
|
7a536a |
<display_order>99</display_order>
|
|
|
7a536a |
diff --git a/tests/support.py b/tests/support.py
|
|
|
7a536a |
index e549ba5b95..a7d6a8542c 100644
|
|
|
7a536a |
--- a/tests/support.py
|
|
|
7a536a |
+++ b/tests/support.py
|
|
|
7a536a |
@@ -94,7 +94,7 @@ def mock_open(mock=None, data=None):
|
|
|
7a536a |
MAIN_NSOLVABLES = 9
|
|
|
7a536a |
UPDATES_NSOLVABLES = 4
|
|
|
7a536a |
AVAILABLE_NSOLVABLES = MAIN_NSOLVABLES + UPDATES_NSOLVABLES
|
|
|
7a536a |
-TOTAL_GROUPS = 4
|
|
|
7a536a |
+TOTAL_GROUPS = 5
|
|
|
7a536a |
TOTAL_NSOLVABLES = SYSTEM_NSOLVABLES + AVAILABLE_NSOLVABLES
|
|
|
7a536a |
|
|
|
7a536a |
|
|
|
7a536a |
diff --git a/tests/test_comps.py b/tests/test_comps.py
|
|
|
7a536a |
index 30d468e3af..763218587f 100644
|
|
|
7a536a |
--- a/tests/test_comps.py
|
|
|
7a536a |
+++ b/tests/test_comps.py
|
|
|
7a536a |
@@ -107,7 +107,7 @@ def test_group_packages(self):
|
|
|
7a536a |
def test_iteration(self):
|
|
|
7a536a |
comps = self.comps
|
|
|
7a536a |
self.assertEqual([g.name for g in comps.groups_iter()],
|
|
|
7a536a |
- ['Base', 'Solid Ground', "Pepper's", "Broken Group"])
|
|
|
7a536a |
+ ['Base', 'Solid Ground', "Pepper's", "Broken Group", None])
|
|
|
7a536a |
self.assertEqual([c.name for c in comps.categories_iter()],
|
|
|
7a536a |
['Base System'])
|
|
|
7a536a |
g = dnf.util.first(comps.groups_iter())
|
|
|
7a536a |
@@ -115,7 +115,7 @@ def test_iteration(self):
|
|
|
7a536a |
|
|
|
7a536a |
def test_group_display_order(self):
|
|
|
7a536a |
self.assertEqual([g.name for g in self.comps.groups],
|
|
|
7a536a |
- ["Pepper's", 'Base', 'Solid Ground', 'Broken Group'])
|
|
|
7a536a |
+ ["Pepper's", 'Base', 'Solid Ground', 'Broken Group', None])
|
|
|
7a536a |
|
|
|
7a536a |
def test_packages(self):
|
|
|
7a536a |
comps = self.comps
|
|
|
7a536a |
@@ -127,7 +127,7 @@ def test_packages(self):
|
|
|
7a536a |
|
|
|
7a536a |
def test_size(self):
|
|
|
7a536a |
comps = self.comps
|
|
|
7a536a |
- self.assertLength(comps, 6)
|
|
|
7a536a |
+ self.assertLength(comps, 7)
|
|
|
7a536a |
self.assertLength(comps.groups, tests.support.TOTAL_GROUPS)
|
|
|
7a536a |
self.assertLength(comps.categories, 1)
|
|
|
7a536a |
self.assertLength(comps.environments, 1)
|
|
|
7a536a |
diff --git a/tests/test_groups.py b/tests/test_groups.py
|
|
|
7a536a |
index fe388f96c0..8972da687e 100644
|
|
|
7a536a |
--- a/tests/test_groups.py
|
|
|
7a536a |
+++ b/tests/test_groups.py
|
|
|
7a536a |
@@ -295,6 +295,15 @@ def test_group_install_broken_optional_nonstrict(self):
|
|
|
7a536a |
self.assertLength(inst, 1)
|
|
|
7a536a |
self.assertEmpty(removed)
|
|
|
7a536a |
|
|
|
7a536a |
+ def test_group_install_missing_name(self):
|
|
|
7a536a |
+ comps_group = self.base.comps.group_by_pattern('missing-name-group')
|
|
|
7a536a |
+
|
|
|
7a536a |
+ cnt = self.base.group_install(comps_group.id, ('mandatory', 'default', 'optional'),
|
|
|
7a536a |
+ strict=False)
|
|
|
7a536a |
+ self._swdb_commit()
|
|
|
7a536a |
+ self.base.resolve()
|
|
|
7a536a |
+ self.assertEqual(cnt, 1)
|
|
|
7a536a |
+
|
|
|
7a536a |
|
|
|
7a536a |
class EnvironmentInstallTest(tests.support.ResultTestCase):
|
|
|
7a536a |
"""Set up a test where sugar is considered not installed."""
|