diff --git a/dnfdragora/compsicons.py b/dnfdragora/compsicons.py new file mode 100644 index 00000000..4305c6fd --- /dev/null +++ b/dnfdragora/compsicons.py @@ -0,0 +1,48 @@ +from gettext import gettext as _ +import os.path + +class CompsIcons: + ''' + This class manages the access to group name and icons + ''' + def __init__(self, icon_path=None): + + if icon_path: + self.icon_path = icon_path if icon_path.endswith("/") else icon_path + "/" + else: + self.icon_path = "/usr/share/pixmaps/comps/" + + self.default_icon = self.icon_path + "uncategorized.png" + + # workaround for https://github.com/timlau/dnf-daemon/issues/9 + # generated using tools/gen-comps-category-list.sh + self.name_to_id_map = { + "KDE Desktop": "kde-desktop-environment", + "Xfce Desktop": "xfce-desktop-environment", + "Applications": "apps", + "LXDE Desktop": "lxde-desktop-environment", + "LXQt Desktop": "lxqt-desktop-environment", + "Cinnamon Desktop": "cinnamon-desktop-environment", + "MATE Desktop": "mate-desktop-environment", + "Hawaii Desktop": "hawaii-desktop-environment", + "Sugar Desktop Environment": "sugar-desktop-environment", + "GNOME Desktop": "gnome-desktop-environment", + "Development": "development", + "Servers": "servers", + "Base System": "base-system", + "Content": "content", + } + + def icon(self, group_path): + group_names = group_path.split("/") + for group_name in reversed(group_names): + if group_name in self.name_to_id_map: + group_id = self.name_to_id_map[group_name] + else: + group_id = group_name + + icon_name = self.icon_path + group_id + ".png" + if os.path.exists(icon_name): + return icon_name + + return self.default_icon diff --git a/dnfdragora/ui.py b/dnfdragora/ui.py index 27b434fe..b9338727 100644 --- a/dnfdragora/ui.py +++ b/dnfdragora/ui.py @@ -17,6 +17,7 @@ import yui import dnfdragora.basedragora +import dnfdragora.compsicons as compsicons import dnfdragora.groupicons as groupicons import dnfdragora.progress_ui as progress_ui from dnfdragora import const @@ -438,7 +439,7 @@ def _groupNameFromItem(self, group, treeItem) : return None - def _getAllGroupIDList(self, groups, new_groups, g_id=None) : + def _getAllGroupIDList(self, groups, new_groups, id_to_name_map, g_id=None) : ''' return a list of group ID as pathnames ''' @@ -446,11 +447,13 @@ def _getAllGroupIDList(self, groups, new_groups, g_id=None) : for gl in groups: if (isinstance(gl, list)): if (type(gl[0]) is str) : + if not gl[0] in id_to_name_map: + id_to_name_map[gl[0]] = gl[1] new_groups.append(gid + "/" + gl[0] if (gid) else gl[0]) if not gid : gid = gl[0] else : - self._getAllGroupIDList(gl, new_groups, gid) + self._getAllGroupIDList(gl, new_groups, id_to_name_map, gid) def _fillGroupTree(self) : ''' @@ -466,68 +469,103 @@ def _fillGroupTree(self) : # get group comps rpm_groups = self.backend.get_groups() if rpm_groups : + # using comps groups = [] - self._getAllGroupIDList(rpm_groups, groups) + id_to_name_map = {} + self._getAllGroupIDList(rpm_groups, groups, id_to_name_map) rpm_groups = groups - else: - #don't have comps try tags - rpm_groups = self.backend.get_groups_from_packages() - print ("End found %d groups" %len(rpm_groups)) - - rpm_groups = sorted(rpm_groups) - icon_path = self.options['icon_path'] if 'icon_path' in self.options.keys() else None - gIcons = groupicons.GroupIcons(icon_path) - groups = gIcons.groups() - - for g in rpm_groups: - #X/Y/Z/... - currG = groups - currT = self.groupList - subGroups = g.split("/") - currItem = None - parentItem = None - groupName = None - - for sg in subGroups: - if groupName: - groupName += "/%s"%(sg) - else: - groupName = sg - icon = gIcons.icon(groupName) + rpm_groups = sorted(rpm_groups) + icon_path = self.options['comps_icon_path'] if 'comps_icon_path' in self.options.keys() else '/usr/share/pixmaps/comps/' + gIcons = compsicons.CompsIcons(icon_path) + + for g in rpm_groups: + #X/Y/Z/... + currT = self.groupList + subGroups = g.split("/") + currItem = None + parentItem = None + groupName = None + + for sg in subGroups: + if groupName: + groupName += "/%s"%(sg) + else: + groupName = sg + icon = gIcons.icon(groupName) - if sg in currG: - currG = currG[sg] - if currG["title"] in currT : - currT = currT[currG["title"]] - parentItem = currT["item"] - else : - # create the item - item = None - if parentItem: - item = yui.YTreeItem(parentItem, currG["title"], icon) - else : - item = yui.YTreeItem(currG["title"], icon) - item.this.own(False) - currT[currG["title"]] = { "item" : item, "name" : groupName } - currT = currT[currG["title"]] - parentItem = item - else: - # group is not in our group definition, but it's into the repository - # we just use it if sg in currT : currT = currT[sg] parentItem = currT["item"] else : item = None if parentItem: - item = yui.YTreeItem(parentItem, sg, icon) + item = yui.YTreeItem(parentItem, id_to_name_map[sg], icon) else : - item = yui.YTreeItem(sg, icon) + item = yui.YTreeItem(id_to_name_map[sg], icon) item.this.own(False) currT[sg] = { "item" : item, "name": groupName } currT = currT[sg] parentItem = item + else: + #don't have comps try tags + rpm_groups = self.backend.get_groups_from_packages() + + rpm_groups = sorted(rpm_groups) + icon_path = self.options['icon_path'] if 'icon_path' in self.options.keys() else None + gIcons = groupicons.GroupIcons(icon_path) + groups = gIcons.groups() + + for g in rpm_groups: + #X/Y/Z/... + currG = groups + currT = self.groupList + subGroups = g.split("/") + currItem = None + parentItem = None + groupName = None + + for sg in subGroups: + if groupName: + groupName += "/%s"%(sg) + else: + groupName = sg + icon = gIcons.icon(groupName) + + if sg in currG: + currG = currG[sg] + if currG["title"] in currT : + currT = currT[currG["title"]] + parentItem = currT["item"] + else : + # create the item + item = None + if parentItem: + item = yui.YTreeItem(parentItem, currG["title"], icon) + else : + item = yui.YTreeItem(currG["title"], icon) + item.this.own(False) + currT[currG["title"]] = { "item" : item, "name" : groupName } + currT = currT[currG["title"]] + parentItem = item + else: + # group is not in our group definition, but it's into the repository + # we just use it + if sg in currT : + currT = currT[sg] + parentItem = currT["item"] + else : + item = None + if parentItem: + item = yui.YTreeItem(parentItem, sg, icon) + else : + item = yui.YTreeItem(sg, icon) + item.this.own(False) + currT[sg] = { "item" : item, "name": groupName } + currT = currT[sg] + parentItem = item + + print ("End found %d groups" %len(rpm_groups)) keylist = sorted(self.groupList.keys()) v = [] diff --git a/tools/gen-comps-category-list.sh b/tools/gen-comps-category-list.sh new file mode 100755 index 00000000..10c8f334 --- /dev/null +++ b/tools/gen-comps-category-list.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Generate the map from category name to ID for dnfdragora/compsicons.py +# Workaround for https://github.com/timlau/dnf-daemon/issues/9 +wget https://pagure.io/fedora-comps/raw/master/f/comps-f26.xml.in -q -O - | tr '\n' '#' | sed -e 's!.*!!g' -e 's!.*!!g' | tr '#' '\n' | grep '<_name>\|' | tr '\n' '#' | sed -e 's!\([^<]*\)# *<_name>\([^<]*\)!"\2": "\1",!g' | tr '#' '\n' | sed -e 's/^ */ /g'