Skip to content

Commit

Permalink
Improve comps group support
Browse files Browse the repository at this point in the history
New file dnfdragora/compsicons.py, similar to groupicons.py, but for
comps.

New tool tools/gen-comps-category-list.sh: Generates a map from category
name to ID for dnfdragora/compsicons.py, as a workaround for
manatools/dnfdaemon#9.

dnfdragora/ui.py (mainGui._getAllGroupIDList): Remember the UI names for
                                               each ID in an
                                               id_to_name_map.
                 (mainGui._fillGroupTree): Handle comps separately, use
                                           compsicons.py to get the
                                           icons (manatools#2) and use the
                                           id_to_name_map to get the UI
                                           name (manatools#3).

Fixes manatools#2.
Fixes manatools#3.

The only remaining issue is that the UI names are not translated, which
I filed as manatools/dnfdaemon#10 because Yumex-DNF is also affected (and
thus it is clearly dnfdaemon's fault).
  • Loading branch information
kkofler committed Nov 16, 2016
1 parent bb6edcf commit 7e7d903
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 49 deletions.
48 changes: 48 additions & 0 deletions dnfdragora/compsicons.py
Original file line number Diff line number Diff line change
@@ -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
136 changes: 87 additions & 49 deletions dnfdragora/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -438,19 +439,21 @@ 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
'''
gid = g_id
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) :
'''
Expand All @@ -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 = []
Expand Down
4 changes: 4 additions & 0 deletions tools/gen-comps-category-list.sh
Original file line number Diff line number Diff line change
@@ -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!<group>.*</group>!!g' -e 's!<environment>.*</environment>!!g' | tr '#' '\n' | grep '<_name>\|<id>' | tr '\n' '#' | sed -e 's!<id>\([^<]*\)</id># *<_name>\([^<]*\)</_name>!"\2": "\1",!g' | tr '#' '\n' | sed -e 's/^ */ /g'

0 comments on commit 7e7d903

Please sign in to comment.