From 924b8fb1283e8c661ccebf2b909bbeff932bbf7b Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Mon, 4 Aug 2008 10:41:54 -0400 Subject: Break a few functions out of yuminstall.py into their own file. This is required because keeping them in yuminstall.py means that system-config-kickstart, which imports GroupSelector, ends up pulling in all of yuminstall. And we can't do that as non-root because we end up trying to import the pyblock stuff as well. --- compssort.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ iw/GroupSelector.py | 16 ++++++------ textw/grpselect_text.py | 6 ++--- yuminstall.py | 47 +-------------------------------- 4 files changed, 81 insertions(+), 57 deletions(-) create mode 100644 compssort.py diff --git a/compssort.py b/compssort.py new file mode 100644 index 000000000..3ad97959f --- /dev/null +++ b/compssort.py @@ -0,0 +1,69 @@ +# +# compssort.py +# +# Copyright (C) 2005, 2006, 2007 Red Hat, Inc. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os + +import gettext +_ = lambda x: gettext.ldgettext("anaconda", x) + +def _getDefaultLangs(): + languages = [] + for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): + val = os.environ.get(envar) + if val: + languages = val.split(':') + break + if 'C' not in languages: + languages.append('C') + + # now normalize and expand the languages + nelangs = [] + for lang in languages: + for nelang in gettext._expand_lang(lang): + if nelang not in nelangs: + nelangs.append(nelang) + return nelangs + +# kind of lame caching of translations so we don't always have +# to do all the looping +strs = {} +def xmltrans(base, thedict): + if strs.has_key(base): + return strs[base] + + langs = _getDefaultLangs() + for l in langs: + if thedict.has_key(l): + strs[base] = thedict[l] + return strs[base] + strs[base] = base + return base + +def ui_comps_sort(one, two): + if one.display_order > two.display_order: + return 1 + elif one.display_order < two.display_order: + return -1 + elif xmltrans(one.name, one.translated_name) > \ + xmltrans(two.name, two.translated_name): + return 1 + elif xmltrans(one.name, one.translated_name) < \ + xmltrans(two.name, two.translated_name): + return -1 + return 0 diff --git a/iw/GroupSelector.py b/iw/GroupSelector.py index d12ba8bae..ad3867a3b 100644 --- a/iw/GroupSelector.py +++ b/iw/GroupSelector.py @@ -31,7 +31,7 @@ try: except ImportError: # yum 2.9.x mdErrors = yum.Errors from yum.constants import * -import yuminstall +from compssort import * I18N_DOMAIN="anaconda" @@ -163,7 +163,7 @@ class OptionalPackageSelector: if parent: self.window.set_transient_for(parent) self.window.set_title(_("Packages in %s") % - yuminstall.xmltrans(group.name, group.translated_name)) + xmltrans(group.name, group.translated_name)) self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.window.set_size_request(600, 400) self._createStore() @@ -372,11 +372,11 @@ class GroupSelector: def _populateGroups(self, groups, defaultpix = None): grps = map(lambda x: self.ayum.comps.return_group(x), filter(lambda x: self.ayum.comps.has_group(x), groups)) - grps.sort(yuminstall.ui_comps_sort) + grps.sort(ui_comps_sort) for grp in grps: if not _groupHasPackages(grp, self.ayum): continue - s = "%s" % yuminstall.xmltrans(grp.name, grp.translated_name) + s = "%s" % xmltrans(grp.name, grp.translated_name) fn = "/usr/share/pixmaps/comps/%s.png" % grp.groupid if os.access(fn, os.R_OK): @@ -416,9 +416,9 @@ class GroupSelector: return if grp.description: - txt = yuminstall.xmltrans(grp.description, grp.translated_description) + txt = xmltrans(grp.description, grp.translated_description) else: - txt = yuminstall.xmltrans(grp.name, grp.translated_name) + txt = xmltrans(grp.name, grp.translated_name) inst = 0 cnt = 0 @@ -472,11 +472,11 @@ class GroupSelector: def populateCategories(self): self.catstore.clear() cats = self.ayum.comps.categories - cats.sort(yuminstall.ui_comps_sort) + cats.sort(ui_comps_sort) for cat in cats: if not _catHasGroupWithPackages(cat, self.ayum): continue - s = "%s" % yuminstall.xmltrans(cat.name, cat.translated_name) + s = "%s" % xmltrans(cat.name, cat.translated_name) self.catstore.append(None, [s, cat]) # select the first category diff --git a/textw/grpselect_text.py b/textw/grpselect_text.py index fd33892c6..f74b54c23 100644 --- a/textw/grpselect_text.py +++ b/textw/grpselect_text.py @@ -22,7 +22,7 @@ import yum.Errors from snack import * from constants_text import * -import yuminstall +from compssort import * from constants import * import gettext @@ -75,10 +75,10 @@ class GroupSelectionWindow: # FIXME: this is very yum backend specific... groups = filter(lambda x: x.user_visible, anaconda.backend.ayum.comps.groups) - groups.sort(yuminstall.ui_comps_sort) + groups.sort(ui_comps_sort) ct = CheckboxTree(height = 6, scroll = (len(groups) > 6)) for grp in groups: - ct.append(yuminstall.xmltrans(grp.name, grp.translated_name), + ct.append(xmltrans(grp.name, grp.translated_name), grp, grp.selected) g.add(ct, 0, 2, (0, 0, 0, 1)) diff --git a/yuminstall.py b/yuminstall.py index e7a2e46d0..2741b7cbc 100644 --- a/yuminstall.py +++ b/yuminstall.py @@ -45,6 +45,7 @@ from product import * from sortedtransaction import SplitMediaTransactionData from constants import * from image import * +from compssort import * import packages import gettext @@ -84,52 +85,6 @@ def size_string (size): else: return _("%s Bytes") %(number_format(size),) -def _getDefaultLangs(): - languages = [] - for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): - val = os.environ.get(envar) - if val: - languages = val.split(':') - break - if 'C' not in languages: - languages.append('C') - - # now normalize and expand the languages - nelangs = [] - for lang in languages: - for nelang in gettext._expand_lang(lang): - if nelang not in nelangs: - nelangs.append(nelang) - return nelangs - -# kind of lame caching of translations so we don't always have -# to do all the looping -strs = {} -def xmltrans(base, thedict): - if strs.has_key(base): - return strs[base] - - langs = _getDefaultLangs() - for l in langs: - if thedict.has_key(l): - strs[base] = thedict[l] - return strs[base] - strs[base] = base - return base - -def ui_comps_sort(one, two): - if one.display_order > two.display_order: - return 1 - elif one.display_order < two.display_order: - return -1 - elif xmltrans(one.name, one.translated_name) > \ - xmltrans(two.name, two.translated_name): - return 1 - elif xmltrans(one.name, one.translated_name) < \ - xmltrans(two.name, two.translated_name): - return -1 - return 0 - class AnacondaCallback: def __init__(self, ayum, anaconda, instLog, modeText): -- cgit